Go Down

Topic: SoftwareSerial library isn't reliable in a loopback sketch even if 2 bytes sent (Read 842 times) previous topic - next topic


Hi everyone, I believe it's my first post here on the forum but i ran through a serious problem when i was exploring SoftwareSerial library to see its performance in my application and I uploaded the following simple sketch:

Code: [Select]
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10,11);

void setup() {

void loop() {
    byte data = mySerial.read();

It's a simple loopback sketch but the results were surprising...! The library couldn't reply back with the data I sent, even when i tested with data as low as 2 bytes per transaction.

I have tried with all standard baud rates mentioned on Arduino website and even went with rates as low as 300 bps.

Here are some sample data that I sent and received in hex:

Baud Rate = 9600
[TX] - 92 29
[RX] - 92 FF

Baud Rate = 9600

[TX] - FF 29 A5 09 02 FD 02 FD 01 00
[RX] - FF 95 13 02 01 FF

Baud Rate = 4800

[TX] - FF 29 A5 09 02 FD 02 FD 01 00
[RX] - FF 95 13 02 01 FF

Baud Rate = 300

[TX] - FF 29 A5 09 02 FD 02 FD 01 00
[RX] - FF 95 12 02 01 FF

As you may see, there is a pattern. The data is the same but the baud rate is different and still the data sequence is very similar.

My tests were performed using the last version of Arduino 1.6.8 using a USB to serial cable connected to the software serial pins. I repeated the tests on different Windows/OSX machines, different Arduino boards (Uno and Mega) and different USB-Serial cables and all of them had the same results.

I've tried AltSoftSerial library and all my tests where working with baud rates up to 57600 and data up to 200 bytes per transaction.

I think the implementation is broken somehow, I know its an issue related to interruption "as the Tx pin is interrupted by the receiver when sending" but still i can't figure out how to solve this problem on my side.

It is not mentioned anywhere that the communication is half-duplex, As i have tested the library by letting one Arduino sending data using SoftwareSerial and another Arduino receives data also by SoftwareSerial and all the packets were received successfully.

Your documentation mentions that it is possible to have multiple software serial posts with baud rates up to 115200, could you explain how that is possible but running my simple loopback sketch isn't?

Am i missing something ? Please advise.



Am i missing something ?
A schematic and a picture of your half-duplex setup.  I suspect power and noisy/incorrectly wired TX/RX lines.
Really, I used to be /dev.  :(


I also suspected the same but when i used an alternative library "AltSoftSerial" and everything kept the same but only the sketch was changed to use the AltSoftSerial, It worked 100% correctly which indicates that there are no problems with the Serial cable along with the Serial terminal i have used.


I think the answer is simple. SoftwareSerial does not work well. It is OK for a single instance working at 9600 baud or maybe a bit more.

Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up