arduino - NodeMcu 串行通信 Tx 和 Rx

标签 arduino embedded nodemcu

我是 NodeMcu 的初学者。我带来了一个 Adraxx ENDEV019 ESP8266 NodeMcu WiFi 开发板。我正在尝试使用 arduino Ide 进行编程。我尝试了一些基本的例子。下面是我正在为董事会尝试的代码。我使用 Serial1 端口进行调试通信。我连接:

  • 从板的发送到串行适配器的接收
  • 从板的接收到串行适配器的发送

我尝试了不同的波特率。我使用外部电源为 NodeMcu 供电,但我在串行监视器中看不到正确的输出。

如果我使用串行端口而不是串行1并使用USB电缆连接到计算机,则相同的代码可以正常工作。

#define LED D0 
#define DBG_OUTPUT_PORT Serial1

// the setup function runs once when you press reset or power the board
void setup() {
  DBG_OUTPUT_PORT.begin(9600);
  DBG_OUTPUT_PORT.print("\n");
  DBG_OUTPUT_PORT.setDebugOutput(true);
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(LED, OUTPUT);  

}

// the loop function runs over and over again forev`er
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED, HIGH);// turn the LED off.(Note that LOW is the voltage level but actually 
  delay(2000);                       // wait for a second
  DBG_OUTPUT_PORT.print("Connected! IP address: \n");

  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW

  digitalWrite(LED, LOW); // turn the LED on.

}

enter image description here enter image description here

我犯了什么错误?

最佳答案

来自(https://arduino-esp8266.readthedocs.io/en/latest/reference.html#serial):

Serial uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX). Serial may be remapped to GPIO15 (TX) and GPIO13 (RX) by calling Serial.swap() after Serial.begin. Calling swap again maps UART0 back to GPIO1 and GPIO3.

Serial1 uses UART1, TX pin is GPIO2. UART1 can not be used to receive data because normally it’s RX pin is occupied for flash chip connection.


您连接的引脚排列看起来像 GPIO1(TX) 和 GPIO3(RX)。 GPIO2为D4引脚。

(引脚图来自: https://github.com/nodemcu/nodemcu-devkit-v1.0 )

关于arduino - NodeMcu 串行通信 Tx 和 Rx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55084188/

相关文章:

C - IF(char[] == "ZYX") 不工作

embedded - 入门级嵌入式系统项目?

c++ - 没有大量 getter/mutator 的优雅的面向对象的成员访问

lua - Lua脚本在执行前是否加载到内存中?

file - 写入文件nodemcu lua

ssl - 使用 NodeMCU 获取 HTTPS (SSL) 请求

php - 为什么 client.available() 返回 0? (阿杜伊诺)

php - 将二进制命令从 PHP 发送到 Arduino 驱动的热敏打印机

c++ - 如何使类的函数成为默认值

PHP exec 没有按预期运行我的脚本