Go Down

Topic: ESP8266 Softwareserial suddenly broken (Read 1 time) previous topic - next topic


hey guys!

i got a Mega2560 Uart connected towards a NodeMCU-ESP8266
The NodeMCU is connected to my WiFi and UDP.broadcasts the Data which he got serial the Mega2560
Somehow i cant use the Nodemcu hardware serial so i tried softserial.

This works. but sometimes the softserial reciever ist doing strange things for some seconds (arround 200-400 UDP packages).

Left: the Mega2560 serial output
Middle: SoftSerial from my Node which will be broadcasted over WiFi
Right: another Node also connected to Wifi which recieves the Data from the UDP.Broadcast

Here everything is fine for a long time:

Here its broken:

Code: [Select]

#define     LED0        2         // WIFI Module LED
#define     analogPin   A0
#include    <ESP8266WiFi.h>
#include    <WiFiUDP.h>
#include    <Wire.h>
#include    <SoftwareSerial.h>

char           inData[65];    // USART DATA BUFFER...
boolean        started = false;     
boolean        ended = false;
boolean        USART_completed = false; 

SoftwareSerial SoftSerial(13, 12); // (RX,TX)  // (D7, D6)

int index2;
int status = WL_IDLE_STATUS;
const char* ssid = "BBT";  //  your network SSID (name)
const char* pass = "pennyisafreeloader";   // your network password
byte packetBuffer[512]; //buffer to hold incoming and outgoing packets
unsigned int localPort = 2390;    // local port to listen for UDP packets
IPAddress ipMulti (192,168,178,255);  // ipMulti (;
WiFiUDP Udp;  // A UDP instance to let us send and receive packets over UDP

void setup()
 // pinMode(D7, INPUT);   // RX0
  pinMode(LED0, OUTPUT);          // WIFI OnBoard LED Light
  pinMode(analogPin, INPUT);      // ADC PIN
  SoftSerial.begin(115200);       // softwareserial

Code: [Select]

void loop()

  Serial_to_WiFi();            // Here we send the USART Data over WiFiUDP
// Recieve_WiFi_response();    // If a WIFI device sends us UDP data we can react in this function on
  WiFi_setup();               // Here we check if we are still connected to the WiFi server

void Read_SoftSerial_Data(){
   while (SoftSerial.available()>0) {     
    char inChar = SoftSerial.read();
    if(inChar == '<'){
        started = true;
        index2 = 0;
        inData[index2] = inChar;
        inData[index2] = '\0';
    else if(inChar == '>'){
        ended = true;
        inData[index2] = inChar;
        inData[index2] = '\0';
    else if(started){
        inData[index2] = inChar;
        inData[index2] = '\0';
    if(started && ended) {
        started = false;     
        ended = false;
        USART_completed = true; 

anybody got a clue why it suddnly gets broken ? is it maybe because its Softserial and it crashes into other timing or interrupt stuff ?
I would like to use the hardware UART but it does not work :-(

transmissionrate: every 7ms i send out the string <0A255_233_132>

Another point to mention is that when I choose another UART frequency the data gets more and more broken.



sometimes the softserial reciever ist doing strange things
Code: [Select]

SoftwareSerial SoftSerial(13, 12); // (RX,TX)  // (D7, D6)

void setup(){
  SoftSerial.begin(115200);       // softwareserial

maybe because its Softserial and it crashes into other timing or interrupt stuff ?
This is probably correct but the fact that you get anything at all at the other times is a surprise, and it is possible that you don't. You just think you do. After all, it is not even clear where or if the software serial is connected, and it is even possible that it isn't. It might pay to start over, using a proper hardware serial port as originally, and sensibly, intended. You have four of them on a Mega, and using software serial instead rather makes you look like you don't know what you are doing, so it's not the sort of thing to show your mother or your mates.  Running software serial at 115200 is a pretty certain kiss of death, hence my comment, and 38400 is about the most you can expect.  Running at 115200 on hardware serial is fine and, if your other hardware is up to it, is not necessarily the upper limit.


Does anybody have a clue how i can get the Hardware serial running in the NodeMCU V3 ESP8266 ??

hi nick ty for your reply!
I know what you mean, i think its just "luck" that it works sometimes.
I am not sure how fast Softserial can be handled by the ESP, I got to mention that it runs on 80MHz...
so it should be able to run a much faster Soft.Serial than the conventional Arduinos with 16MHz...

The Mega is doing Hardwareserial! The ESP is doing softSerial, and the Code is from the ESP.

Look at this pic:

and here is a Video from it:

Youtube Video from m project


I'm afraid I can't comment on how well the ESP handles software serial. It is probably such a dumb idea you might find it hard to get proper information because nobody would want to admit that they know. Using it on any arduino is never a good idea and the same probably applies to an ESP, although maybe to a slightly lesser degree.

As things are, the ESP8266 is properly equipped with kosher hardware serial, and it therefore seems just silly not to use it.  I understand some ESP boards come with TWO hardware serial ports. I'm sure there is a message in there somewhere.....


I can try the I2C .. but I will also need a UART running on ESP :(
dont know how i can use the Hardware UART cause its wired towards the USB programming interface


Feb 13, 2017, 12:03 pm Last Edit: Feb 13, 2017, 12:09 pm by BuffaloChill
...just to mention ....

An ESP8266 port of SoftwareSerial library done by Peter Lerup (@plerup) supports baud rate up to 115200 and multiples SoftwareSerial instances. See https://github.com/plerup/espsoftwareserial if you want to suggest an improvement or open an issue related to SoftwareSerial.
Same functionality as the corresponding AVR library but several instances can be active at the same time. Speed up to 115200 baud is supported. The constructor also has an optional input buffer size.

Please note that due to the fact that the ESP always have other activities ongoing, there will be some inexactness in interrupt timings. This may lead to bit errors when having heavy data traffic in high baud rates.


Feb 13, 2017, 12:13 pm Last Edit: Feb 13, 2017, 12:21 pm by BuffaloChill
As things are, the ESP8266 is properly equipped with kosher hardware serial, and it therefore seems just silly not to use it.  I understand some ESP boards come with TWO hardware serial ports. I'm sure there is a message in there somewhere.....
The ESP doesnt come with 2 Hardware UART ports.. it has only one.. but you can swap the pins.. with
But I didnt get it running so i just tried a SoftwareSerial for the first test.
Since the ESP only supports Slave I2C and realy need to get it done with UART i am experimenting with the UART at the moment.


Looks like it has TX, Rx pins to me



Feb 14, 2017, 02:59 am Last Edit: Feb 14, 2017, 05:38 am by Nick_Pyner
It has hardware serial, yes. I was looking at the wrong thing, a NodeMcu, which includes an ESP and apparently two ports, but is apparently a different deal altogether.

Go Up