I've been working a while on a project using 3 Arduino Nanos, linked together using this tutorial Nick Gammon.

As I am not experienced with Arduino programming, I was making it step by step.

First I get all devices in one network, then managed to get the correct data sent from the correct device to one receiver. I added a Nextion display to visualize the received data. Then I have some physical buttons and some relays as well.

So far everything went fine until today. I wanted to send a command from the Nextion to the Arduino. Only then I realized that when using multiple software serial ports, only one can receive data at a time.

In my case I have an RS485 on SoftwareSerial and the Nextion.

I'm feeling a bit upset now, as I soldered everything on a prototyping board as nice as I can. I tried to move the Nextion on to hardware serial, as that was quite easy to access, but the result was inconsistent.

Please, can someone suggest me how to change my project's hardware and what I need to program (Software Serial or Hardware Serial) to make it to work? Basically I am looking for the right direction now, when I will get that I can figure out the rest by myself.

  • 1
    Please post your code and preferably your wiring. Hardware serial uses interrupts and should work OK with SoftwareSerial unless you are using a low baud rate. SoftwareSerial turns interrupts off and at low baud rates this might be long enough for hardware serial data to be missed. – Nick Gammon Dec 19 '17 at 19:57
  • If you have two different baud rates already try swapping the serial devices around. Put the faster one onto SoftwareSerial. – Nick Gammon Dec 19 '17 at 19:58
  • Thank you for your reply. At the moment i have both devices on 9600. How fast can i go with RS485? I will post code bit later, it is on my laptop at work. Also i want to say huge thank you to You, Nick Gammon for your website. For me being dumb beginner, finding lots of good stuff on it. – zarsss Dec 19 '17 at 20:02
  • RS485 is really an electrical protocol. I don't see why it shouldn't work somewhat faster like 57600 baud. – Nick Gammon Dec 19 '17 at 20:12
  • Ok, now i broke everything, have to start from beginning. Will come back to this, when problems fixed. Thank you anyway. At least i know witch way to dig. – zarsss Dec 19 '17 at 22:03

Hardware serial, on the face of it, should be the more reliable because it uses hardware that can run simultaneously with other code. It uses interrupts to transfer a received byte from its internal register into program RAM.

Software serial, on the other hand, is somewhat more timing-dependent because it uses timing loops to detect each bit at the correct time. In order to do this, it turns off hardware interrupts in order to ensure that each timing loop runs at the expected speed.

If you use Software serial at the same time as hardware serial, the fact that Software serial turns off interrupts may mean that the processor doesn't get a chance to transfer the most recent byte from the serial hardware to RAM.

A work-around, if possible, is to use Software serial at the fastest possible baud rate. That means that interrupts are turned off for a shorter time. When they are turned back on the processor can recover the most recent hardware serial byte.

Thus, if you have two devices using serial, put the faster one onto Software serial, to reduce the time that interrupts are off.

RS485 does not, per se, specify a transfer rate. It is a balanced electrical protocol, which is designed to minimize the impact of noise over long cable runs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.