Go Down

Topic: Using two serial devices with Arduino Yun (Read 518 times) previous topic - next topic


I would like to use two serial devices with Arduino Yun: the serial 20x4 SerLCD of Sparkfun and the Grove RS-485 adapter (to read the data from RS-485 device). Is it possible to use two serial devices simultaneously?


I have done this with the Yun, and it works well, although you have to use some care in coding.

I used SoftwareSerial to set up two extra serial ports, leaving the hardware Serial to talk to the USB port, and Serial1 to talk to the Linux side of the Yun using D0 and D1.

Read the documentation page carefully. The Yun uses the same processor as the Leonardo, so the note about Leonardo pin restrictions also applies to the Yun. The pins I used are:

First Port:
  • Tx: Pin 8
  • Rx: Pin 9

Second Port:
  • Tx: Pin 10
  • Rx: Pin 11

Also note the restriction that only one port can receive at a time. You need to call the listen() function for a port to allow it to receive characters, which will prevent the other port from receiving. Any data coming in on one port will be lost while the other port is listening. In my case, this wasn't an issue, as I am polling the two remote devices: I call listen() for one port, send the poll request, and wait for a response (with a timeout.) Then I repeat for the other device, alternating back and forth. If your devices are sending data asynchronously (or simultaneously) then SoftwareSerial probably won't work for you.

Go Up