BroomCloset
Posts: 1
Joined: Wed Nov 30, 2016 12:23 am

UART with 3 devices

Wed Nov 30, 2016 12:27 am

Hello,

I was wondering if it would be possible to have two raspberry pis and one other device communicate with each other via UART. My thought is this:

Device 1 TX to device 2 RX
Device 2 TX to device 3 RX
Device 3 TX to device 1 RX

I2C and SPI are going to be used by other modules, so I can't use those. Would this setup be possible, or is there a better solution?

Thank you

User avatar
joan
Posts: 14887
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: UART with 3 devices

Wed Nov 30, 2016 9:42 am

Daisy chaining the serial links seems like a good solution.

User avatar
procount
Posts: 2209
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: UART with 3 devices

Wed Nov 30, 2016 10:16 am

Yep, entirely possible.
I used this technique to create a ring-type network between about 10 PCs in the 1980s, sending simple popup messages to each PC using a DOS TSR program (anyone remember those?), and even transferring files.
You probably need to create a protocol to allow messages to be addressed to a specific device, and don't forget to remove messages from the ring that were originally sent from yourself, otherwise they will circulate forever.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

wildfire
Posts: 606
Joined: Sat Sep 03, 2016 10:39 am
Location: Dundee, Scotland

Re: UART with 3 devices

Wed Nov 30, 2016 12:41 pm

procount wrote:DOS TSR program (anyone remember those?)
Terminate and Stay Resident, Remember them well :D
E8 85 A2 64 C9 64 81 94 64 81 95 64 89 84 89 96 A3
Still NF Shirls

ElEscalador
Posts: 839
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: UART with 3 devices

Wed Nov 30, 2016 1:27 pm

Sounds solid...although depending on what each pi is doing timing could be a bugger. Food for thought: You can also use the USB for serial comms and having that extra port can sometimes prevent the need to "daisychain" and simplify the code to route data to where it needs to go. ie -

device 1 tx and rx to PI 1 via UART,
then just pi to pi with serial.
Robotics tips, hacks, book extras https://youtube.com/practicalrobotics

PiGraham
Posts: 3929
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: UART with 3 devices

Wed Nov 30, 2016 2:00 pm

Daisy-chaining will work.

You could also use a RS485 / RS422 line transceiver (cheap chip available on breakout boards) on each UART port and have bidirectional two-wire differential data bus shared by all devices. Good for short or long distance communications between multiple devices.
Use one gpio on each device to control it's own driver direction (transmit to the bus or receive from it).

Direction control can be managed with the RTS handshake. That should be available on gpio17 (bcm numbering) as an ALT function. Or use any spare gpio under software control.

You will need some scheme to coordinate which device transmits at any time. e.g. make one Pi the 'master' an dhave it send out a frame start byte every so often. Have slave1 transmit A ms after frame start and slave 2 transmit at B ms after, where A and B are different enough to ensure the two transmissions never collide.

Or have the master address a slave and get a reply, then address the other slave and get a reply. Slaves stay quiet unless addressed.

You can also use USB serial devices on the Pis
You can also use bit-bang soft serial ports on any gpio.
http://abyz.co.uk/rpi/pigpio/cif.html#gpioWaveAddSerial

User avatar
mikronauts
Posts: 2779
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: UART with 3 devices

Wed Nov 30, 2016 4:41 pm

Daisy chaining will work if you wrote the code on the attached devices.

If the devices are meant to connect directly, it will not work.

Easiest solution is to add USB serial adapters.
BroomCloset wrote:Hello,

I was wondering if it would be possible to have two raspberry pis and one other device communicate with each other via UART. My thought is this:

Device 1 TX to device 2 RX
Device 2 TX to device 3 RX
Device 3 TX to device 1 RX

I2C and SPI are going to be used by other modules, so I can't use those. Would this setup be possible, or is there a better solution?

Thank you
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

PiGraham
Posts: 3929
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: UART with 3 devices

Wed Nov 30, 2016 5:00 pm

mikronauts wrote:Easiest solution is to add USB serial adapters.
Agreed, that is the easiest. The other options require special software to be written. USB serial just gives you more standard serial ports compatible with any method that talks to a serial port.

Return to “Beginners”