1

I was wondering if I can use the Rx and Tx Hardware on the Arduino Uno and also add another Rx/Tx pins using SoftwareSerial at the same time ? cause I need two to communicate with two motor Controllers (Roboclaw controller) Thx

2 Answers 2

3

Yes, you can. That's the purpose of the SoftwareSerial - to allow you to complement the hardware TX/RX with other pins defined by software.

One thing to note with SoftwareSerial - it's half duplex. It can either send or receive, it can't receive while it's sending.

1
  • 1
    Agreed. See MIDI decoder demonstration - that reads a MIDI device using SoftwareSerial and outputs using HardwareSerial. As you can see it keeps up with the MIDI gadget. As Majenko said, you can't transmit and receive simultaneously using SoftwareSerial.
    – Nick Gammon
    Aug 19, 2015 at 21:40
2

You can, but be aware that SoftwareSerial can cause problems if you need strict timing, as it will keep the Arduino stuck while it is receiving, as it polls in interrupt context.

I would recommend to check which one of the two serial channels is more likely to receive data and use the real HW Serial port for it.

The duration of the polling of the SoftwareSerial library is also influenced by the bitrate used on the port: the higher the bitrate, the shorter the duration of the lockups, so try to use the highest bitrate you can afford, on the Software Serial port.

In case you find out that you cannot afford letting SW handle one of the 2 serial ports, you can try the Arduino Mega 250, which has several UART HW blocks.

About the specific use case: if either of your motor controllers supports I2C or SPI, you could consider using that, as alternative to the SoftwareSerial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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