我是 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.
}
我犯了什么错误?
最佳答案
来自(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引脚。
关于arduino - NodeMcu 串行通信 Tx 和 Rx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55084188/