Serial between ESP8266 and Arduino leonardo not working correctly

Hi, i am making a project that uses arduino and esp8266 connected via Serial unidirectional ESP TX --> Ard RX. For this project im using SoftwareSerial. If i send a long string, arduino miss some letters and i cant fix this problem.
The String that send ESP:
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
The string that receive Arduino:
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901235678912346789023456890234568901345689012356780123567801235678902345675679012356790123467801234678912346789023457890134568901345689012456780123567801235678912346789023457890234568902345679012456790123567901234678012346789023467890234578901345689013456790124567801235678012356789123467890234578901345689013456790124e67891235678

As you can see, Arduino miss some data.
Serial is configured at 38400baud.

The code that i use for sending data from ESP:

for (int i = 0; i < str.length(); ++i)
      {
        arduino_serial.write((char)str[i]);
      }

The code that is use for receive data from arduino:

 if (mySerial.available() > 0)
  {
    bufferr = mySerial.readString();

    Serial.println(bufferr.c_str());
}

Last thing, the data sended from esp is fine.

Please post the full sketches for both of the Arduinos

Is there a particular reason that you are using SoftwareSerial, particularly on the Leonardo ?

Yes, ESP8266 i use HW serial for debug, and on arduino i use softwareserial for emulate HID on the HW Serial.
Im trying to create a RUBBER DUCKY wifi with some feature as multiple layout support for example

Are you aware that the Leonardo has 2 hardware Serial interfaces ?

1 Like

Perhaps consider using an online past site to store data such as serial data when making a post. That's just my opinion, not any actual rules but yeah just makes it easier to read your post.

I'm guessing the issue may lie in the hardware, software serial isn't that reliable, especially between boards on those typical Arduino jumper leads. For example, on one of my old projects I had an ESP32 sending small amounts of data to a secondary Arduino UNO board to drive an OLED. Worked perfectly fine but every time the projects starter motor relays or other high powered components were activated, the LCD would get all messed up.

Turns out the reason why the software serial functions was acting unstable was that my data wires were getting electrical interference from the EM fields from other wires in close proximity. To fix it I twisted the data wires and double insulated them.

That was my experience might not be the same for you but worth mentioning :blush:

PS: might be worth reading this post on the forum

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