SoftwareSerial has an alternative AltSoftSerial

So this really isn't a plea for help or anything like that, more of an informational post. I was doing some tinkering with a serial LCD that I came across and had need to make use of another serial port since the hardware port is tied up by the Uno. I was making a crude clock display and noticed that it was losing an unusual amount of time so I dug into it.

Turns out that SoftwareSerial has some "quirks" that aren't documented as well as they should be.

  1. You can't send and receive at the same time. If you try to overlap send/receiving you WILL lose incoming data.
  2. It blocks with interrupts disabled for the entire time it is sending or receiving a byte. This is really bad since it takes approx 1mS to send a byte at 9600 baud.
  3. Due to number 2, functions that depend upon the Arduino's use of Timer0 (millis(), micros() and delay()) will be severely impacted since timer0 overflows will be completely missed and not handled before another occurs.

All is not lost though. There is an alternative serial library that uses interrupts to do things and otherwise plays much more nicely. It's not without it's limits though.

  1. It hijacks Timer1 to do its thing which precludes using pins 9 and 10 for PWM.
  2. It forces you to use pins 8 and 9, so it only offers one additional port.

Each has its benefits and downfalls, so both should be evaluated. The later one isn't screwing up my timekeeping at all. The previous was making my "clock" lose nearly an hour per day. Now it's keeping time as I expected.

The library is called AltSoftSerial and is available here:
http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html

Can AltSoftSerial use with Ethernet shield together this pin restrictions?

Can AltSoftSerial use with Ethernet shield together this pin restrictions?

Yes. The ethernet shield doesn't use pins 8 and 9.

I have another concern, because my project is use RS485 (MAX485) connection with SoftwareSerial as shown in the figure.

  • How can I use AltSoftSerial with this setup?
  • Do I need another pin (other than RX and TX) like in SoftwareSerial library?