Esp8266向Arduino软串口通信,Arduino收到乱码的问题!
简要:本文说明Esp8266向Arduino软串口通信,Arduino收到乱码的问题!
最近小编在做一个用arduino UNO和esp8266开发板的项目,在过程中遇到了一个问题:esp8266如何和arduino通信?为什么arduino收到的都是乱码?现在网上有很多解决arduino读取esp8266的串口信息,今天小编就来为大家解决这个问题。
例子:Esp8266串口通信输出“1”,Arduino收到什么信息?
代码:
Arduino Uno:
#include <SoftwareSerial.h>
SoftwareSerial arduinoSerial = SoftwareSerial(0,1);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
arduinoSerial.begin(9600);
arduinoSerial.flush();
}
void loop() {
// put your main code here, to run repeatedly:
char a;
a=arduinoSerial.read();
Serial.println(a);
}
ESP8266:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.write("1");
}
这是就有人问了,我收到的都是乱码啊。。。。?我收到的不是我想要的啊?
此时esp8266输出的情况是这样的!
这里我们使用的是安信可串口调试助手。
而Arduino收到的消息是这样的!
这时我们如何解决这个问题呢?此时我是这么接的线!
测试时,我的两个模块都是使用USB转TTL供电的,当我们把esp8266用电池供电就解决了这个问题了,在这里我是将arduino上的3v3接到了esp8266的3v管脚上,arduino为esp8266供电。
上图片!Arduino串口通信收到的数据👆👆👆
现在就正常了!
如果有错误,还请各位大佬批评指正!
愿大家在单片机的学习之路一路顺风ヾ(◍°∇°◍)ノ゙