3 Arduinos Connected by Serial

How can I connect 3 Arduinos using the TX and RX pins (0 & 1)? How should I wire it? What about the code? Is there a method to know wich slave I am talking to? Please answer!

Thanks for reading!

-Positive07-

You could use RS485 for this with a max485 chip or you could use a Arduino mega with two serial conections. Another option is using the softserial library for more serial ports.

If the devices are not very far apart, just have them talk directly using the Rx/Tx pins:

Get an 5V TTL AND gate. Master drives TX to both slaves' RX input. Slaves TX drives the AND gates, output goes to the Master's RX. Either slave TX going low will show as a low to the master. Arrange your comms so only 1 slave responds at a time and avoid conflicts that way.

..long time back I connected several 8748s to a PC (via rs232) such that all mcus were connected in parallel (all rxes and all txes) and those 2 wires (plus gnd) to the PC. So I needed 3 wires. I developed a "protocol" where all mcus were listening as slaves. Each command had ~2 bytes, where the 1st byte was the mcu's unique ID. Master (PC) was sending requests with specific IDs and the requested mcu then did some action (ie. it measured some values and sent back to the PC). You can tristate the tx when listening. It worked. P.

How do you tristate the Tx Line after enabling serial comm’s?
Serial.begin(9600);

I have the AND gate to address that.

hmmm, I do not know how to tristate when calling serial.begin.. Maybe sw serial may help.. When using AND gate you need a lot of wires then (for each tx one wire). Maybe an OpenCollector at each mcu?? And all txes on one single wire then (wiredOR)..P. PS: of course with 3 arduinos maybe the AND is ok, my solution adressed 256 x 8748 chips ('87) :astonished:

OP only said 3 uCs, so AND gate is simple solution. TI & Philips sell single AND gates in 5-pin package. Was going to suggest maybe 4 transistors too, two as inverters, then two as open collector inverter to provide same function as the AND gate. And a bunch of resistors. (either signal going low results in a low output)

Seeing as the signals are all 0v and 5v, one might be able to make direct connections.

"Seeing as the signals are all 0v and 5v, one might be able to make direct connections."

That's how I started Reply #2.

That's how I started Reply #2.

Why is there an AND gate in the mix?

The AND gate acts as a MUX for the output from the 2 slaves. The Output will go low when either input goes low. The TTL Serial output on the slave TX lines is high when there is no activity, and goes low as the start bit to start a serial transfer of a byte.

Interesting, the rx pin is also high with no activity. Guess it gets pulled low by ther the other unit's tx pin.

Yes, the TX pins (and thus the RX inputs they are connected to) are high with no activity.

On my arduino, the rx pin is also high with no activity and it is not connected to another tx pin. Perhaps it has a high value resistor that normally holds it high, but can be pulled low when a connected tx goes low. A diode on each slave tx pin that would provide for some electrical seperation (prevent one slave tx from trying to pull the other slave tx low) might limit tx pin conflicts.

I have not looked at the Serial.begin() code, its certainly possible the internal pullup is enabled to make the Rx line sit high.

Here are the 2 options discussed - more are possible.

5-pin AND gates are available, http://www.fairchildsemi.com/ds/NC/NC7SZ08.pdf
43 cents at digikey.

I have not looked at the Serial.begin() code, its certainly possible the internal pullup is enabled to make the Rx line sit high.

Just being curious, I loaded the simple blink sketch and the rx pin was still high with no serial declarations in the code. That led me to think that the rx pin is normally weakly held high allowing the slave tx pin to easily pull it low.

Rx could also be held high from the USB interface being connected to those pins.

The rx may be weakly held high to preclude floating pin issues.

Perfect CrossRoad I got it!! Thanks a lot!! It's more difficult than expected but it'll work great!

Thanks for reading and answer it is solved right now... I'll open this post again if there is some mistake or something like that...

P.S.: I haven't been in the forum for a while but thanks for everything you explained very well. Thanks!!

-Positive07-

What part was difficult? The AND gate; the 2 diodes and resistor; or writing the code so only 1 slave responded at a time?