我想通过UART将数据从我的ESP8266设备发送到Arduino Uno板.
ESP8266已使用NodeMCU固件刷新(该版本具有以下时间戳:nodemcu-master-8-modules-2017-05-30-19-21-49-integer).仅使用以下模块构建固件:file,gpio,net,node,tmr,uart,websocket,wifi. ESP8266板本身就是Adafruit Huzzah板.
ESP板通过笔记本电脑USB的串行电缆供电.我使用的电缆是this one,它为我的电路板供电5V,我知道我的Mac上的USB可以提供所需的500mA电流.
Arduino也通过我电脑上的其他USB端口供电.
ESP板和Arduino连接如下:
ESP8266
TX RX GND
| | |
| | |
10 11 |
RX TX GND
Arduino
Adafruit Huzzah董事会声称:
The TX pin is the output from the module and is 3.3V logic. The RX pin
is the input into the module and is 5V compliant (there is a level
shifter on this pin)
因此,不需要在这两者之间转换水平.
我在ESP8266板上运行的代码,如init.lua:
uart.setup(0,115200,8,0,1)
tmr.alarm(0, 5000, 0, function()
uart.write(0, "A", 19)
end)
我在Arduino上运行的代码是:
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
MeetAndroid meetAndroid;
SoftwareSerial sSerial(rxPin, txPin);
uint8_t lastByte;
uint8_t serialBuffer[64];
int count = 0;
int onboardLed = 13;
void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(115200);
sSerial.begin(115200);
pinMode(onboardLed, OUTPUT);
digitalWrite(onboardLed, HIGH);
}
void loop() {
while (sSerial.available() > 0) {
serialBuffer[count] = sSerial.read();
count++;
}
for (int i = 0; i < count; i++) {
Serial.println(serialBuffer[i]);
}
}
一旦我重置ESP板,我在Arduino的串行监视器上看到的是垃圾:
⸮⸮⸮⸮⸮⸮Z,⸮}⸮߿⸮ߏ⸮\⸮⸮LYLYLYLYL⸮L⸮L⸮L⸮L⸮L (((((⸮$⸮$⸮$⸮$⸮$⸮$⸮4⸮0⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@ ((((⸮$:⸮&i(⸮⸮
在短暂的延迟之后,它开始在这条初始线之后逐行打印出垃圾.我很清楚,在某个地方,有一个不匹配.
我已经找到了关于这个问题的先前问题,但是我能找到的唯一一个与我使用最接近的问题就是one ought to read the docs,这对我来说并不是很有帮助.
有谁知道这里有什么不妥吗?
最佳答案 您必须设置适当的波特率.您可以在串行监视器的右下角设置波特率.
我更喜欢使用9600的标准调试波特率.