Software Serial Communication Issues on UNO R4 with Garbled Output

Hello everyone,

I am currently working on a project where I'm trying to communicate with my ESP01 using a software serial connection, primarily via AT commands.

Please refer to the following image for my wiring setup:

A few months ago, both the UNO R3 and R4 models worked perfectly fine with this setup.

However, I recently encountered a problem when attempting the same with the UNO R4; the serial monitor displays extensive garbled text, preventing me from configuring my ESP01 as I could before. Could there have been changes to the SoftwareSerial.h library or something else I might be overlooking? Any advice or insights would be greatly appreciated.

Hereโ€™s the code Iโ€™m using:

#include <SoftwareSerial.h>
SoftwareSerial espSerial(2, 3); //Rx,Tx

void setup() {
    // put your setup code here, to run once:
    Serial.begin(115200);
    espSerial.begin(115200);
}

void loop() {
    if (espSerial.available()) {
        Serial.write(espSerial.read());
    }
    if (Serial.available()) {
        espSerial.write(Serial.read());
    }
}

On the UNO R3, the setup generally functions correctly despite some occasional garbled text, as shown in the image below:
R3

On the UNO R4, however, the output is nearly unreadable:
R4

I would be truly grateful for any help or suggestions from this community. Thank you in advance for your time and assistance!

Why are you using SoftwareSerial when the Uno R4 has two serial interfaces, unlike the Uno R3. In any case, SoftwareSerial does not work at 115200 baud

Use pins 0 and 1 and the Serial1 interface to communicate with the ESP01. It will not interfere with use of the Serial monitor or uploading code, again unlike the Uno R3

1 Like

Thanks for your reply!

Beacuse I would like the code to be reusable for both the R3 and R4. To add, when I use the Serial1 interface on the R4 to communicate with the ESP01, everything works perfectly.

Could you please tell more about "SoftwareSerial does not work at 115200 baud"?

If you want to keep the sketch compatible with both the R3 and R4 Unos then you could consider conditional compilation to allow you to use SS of the R3 and Serial1 on the R4

SoftwareSerial has to share resources with whatever else is running on the Arduino and it generally cannot keep up with a high baud rate

I don't know whether SS is compatible with the R4

1 Like

Yes, it is compatible and it has been discussed several times by ptillisch ... however, there are specific pins for the RX depending on the board used (on R4 they are all good for TX) ... you can see HERE :wink:

Guglielmo

1 Like

I found this thread while searching for answers to my very similar problem. I had an UNO R4 Wifi using a total of 3 serial ports: Serial for programming and debugging, Serial1 to talk to a UART water flow sensor at 2400 8E1 (settings hard coded in the sensor- ScioSense UFM-01) and a software serial port going to an RS-232 converter for communicating with upstream data gathering equipment. I had to use the hardware serial pins 0 and 1 on the R4 because the water flow sensor could not use the software serial, since it was unable to send and receive data simultaneously, as when resetting the sensor's accumulated flow. Also, I was having difficulty with the 2400 8E1 format.
It was all working fine until recently, after some software update. The software serial port was initialized as shown in the code snippet below.

#include <SoftwareSerial.h>  //needed for RS-232 comms to shield to CON board
// Note any pin can be used for TX, but only the following pins
// can be used for RX:
// D0, D1, D2, D3, D8, D14, D15, A1, A2, A3, A4, A5
SoftwareSerial SoftSerial(2,3);  // Rx, Tx for RS232 shield

And in setup:

SoftSerial.begin(9600); // serial prints "@AF!" messages,

Now, very similar to wulu above, I sometimes get the data I sent out SoftSerial, but more often than not get gibberish. The speed is low enough (I had read that 57600 was about the highest software serial could go without errors), and like wulu and I both said, it used to work. Something has changed with Software Serial in one of the updates. I am using IDE version 2.2.1, with the boards packages and libraries receiving their regular updates. My other computer is using IDE version 2.3.2, and does not get board and library updates as regularly. Due to IT dept. limitations, it is not easy to do software updates on my primary computer due to not having admin access on it.

-Please be understanding, this is my first post here. I have tried to use the code tags and all to conform to the standards expected of users here.

1 Like

By kludge trial and error, we were able to make the output read correctly by inserting a millis delay of 5 mSec between each of the 32 bytes of the data package. Not very pretty, but it works. Looking forward to a more elegant solution, such as a fix to the R4's SoftwareSerial library.

1 Like

Setting delays only put a band aid on the problem. The real solution is here: Fix Your Arduino UNO R4 UART Issues - Hackster.io

1 Like

Check out the priority of the UART. USB communications using the Serial Monitor will block not only the hardware serial, but also starve SoftwareSerial. USB, SPI, and Timers are also other related issues that hopefully will be addressed eventually as the platform matures. Also I believe the RingBuffer interrupt issue is also used in SoftwareSerial.

2 Likes