Serial communication between 2+ arduinos

Hi, I'm currently making a project which involves an Arduino NANO as a remote, and variable number of Arduino megas. I would like to use the built in serial communication (I will not be printing to the serial monitor) to communicate between them. I only want each mega to be connected to at max 2 other megas, and not have every device joined using the same wires such as in I2C communication, so that there is separation between each communication cable.

Here's a simplified schematic of just the communication, using RJ45 keystone jacks

The only data transfer will be a single byte of data at a time, which will be either 1-255 sent from the nano, or 0 sent from any device using Serial and Serial1(except the nano which will only use Serial obviously). If the nano writes a number 1-255 then the first mega will receive it and read it on Serial and send the same number on Serial1, and this repeats until the final mega. If a device receives a 0 on Serial, then it will write 0 on Serial1 and vice versa, except for the nano which will write 0 back to Serial, and the final mega (determined with a switch) which will do the same as the nano. The purpose of sending 0 is to check that every mega is working and connected, as a single disconnected mega will prevent the chain from completing, it's a bit like a pulse being sent in both directions and getting 'bounced' at the ends of the chain.

My question is if using an ethernet cable (unshielded cat6)between each of the megas (or between the nano and first mega) what is the maximum length of ethernet cable I can use? Also, should I put RX and TX on the same twisted pair as in the diagram or different pairs, I was assuming same pair would be better?

Hard to say what is maximum length of cable. Maybe 10m or less would be reliable, but there is no standard for this and it also depends on transfer speed. Slower baud rate means longer cable and vice versa.

You can use same twisted pair but different TP would be probably better.

should be able to get a few hundred feet, depending on baud rate..
i would use a pair for tx and another for rx..

standard was developed in the 60's..
RS-232 Wiki

good luck.. ~q

Thank you for the quick replies, as I don't need fast data transfer, and sending only 1 byte at a time, very infrequently, any rough estimate of length using a baud rate of 1200

Just so you know, the RS232 is different. There is different voltage and it has an impact to usable cable length.

Each of your signals needs to have a ground wire, otherwise you are NOT making a complete circuit. Normally a ground wire will be one of a twisted pair the other being the signal wire. So ALL of your devices will have a common ground connection. Will that interfere with powering your other devices?

consider using RS-485 where you can connect multiple devices to a multidrop bus network

That will make debugging your NANO code next to impossible because you cannot use serial.Print() to help you debug.

There will be a ground wire, the way I currently have it is one twisted pair has RX and TX, another has ground in both wires. I'll swap them around so one pair has TX and gnd, the other has RX and gnd

Currently I've got an OLED display, so I'm using that for debugging, I made sure to get it working before I added in any serial communication. I have currently got a nano communicating with a mega using the serial port through an ethernet cable, and everything working, but the cables only 1m long and I wanted to know how long I can make it

Good! I have done that, too, in the past.

I'll take a look at this, I tried it for a school project but couldn't get it to work, and removed the RS485 modules as I could get away without the long distance communication (my project had to be proof of concept only, I 'forgot' to mention to my teachers the cable range wouldn't be that great). I've still got the modules lying around somewhere so I'll give it another try

RS485 was designed for interconnecting multiple devices over a common serial bus, e.g your multiple megas to a nano etc
have a look at sample code in post esp32-readings-with-wind-direction-sensor-via-rs485
Example is for an ESP32 but Mega code would be similar, e.g. using Serial1 on pins 18 and 19
it is a good idea to get a USB-RS485 dongle for a PC to test and monitor the bus - they are a few £ on EBAY

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.