Software serial reading wrong values

Hi there,

I’m trying to use the software serial library in my arduino Uno to read packets from a ESP8266. I set a constant word packet to test the comms and see if it is working, but it shows a very erratic behavior. Every time a packet is read, the values are different. My arduino code only reads the software serial port and prints it back to the monitor. Code:

#include <SoftwareSerial.h>
SoftwareSerial esp8266(2,3); //TX, RX
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
esp8266.begin(115200);
}
String old_msg="";
String data;
void loop() {
//Check to see if anything is available in the serial receive buffer
while (Serial.available()) {
Serial.write(Serial.read());
}

Also i am using an ESP8266 wifi module thing that is powered from the arduinos 5V

SoftwareSerial esp8266(2,3); //TX, RX

You may have wired things correctly, but the order of pins in the SoftwareSerial constructor is Rx, Tx

So RX is 2 and TX is 3 let me change and see

That code never accesses your esp8266 connection. It only accesses Serial.

Yea i saw that but it dosnt matter i have tried lots of codes before that

The code you post most certainly DOES matter if you expect others to look at it and help solve problems.

So i have changed the code to this:
#include <SoftwareSerial.h>
SoftwareSerial esp8266(2,3); //TX, RX
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
esp8266.begin(115200);
}
String old_msg="";
String data;
void loop() {
//Check to see if anything is available in the serial receive buffer
while (esp8266.available()) {
Serial.write(esp8266.read());
}
}
And i have connected esp8266 RX to pin 3 and TX to pin 2 and it still shows messed up data from the char it is reciving from the esp.

And the code running on your esp8266? Configured for 115200 baud as well? I would change that to 9600 baud for softwareSerial...

1 Like

Wow after letting it run for 2 minutes i see that the data is perfect, thanks a lot for your help!!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.