Hello, In my project I want to make communication between 4 - 5 Arduino using RS-485 protocol can someone explain me what external module to buy and how can I send and receive data?
Thank you
Hello, In my project I want to make communication between 4 - 5 Arduino using RS-485 protocol can someone explain me what external module to buy and how can I send and receive data?
Thank you
These adapters work fine and this example will help. You can use an RS-485 protocol or create your own by sending packets containing an addressee byte. All slaves would listen but only one would respond. Same idea as I2C but much longer cable runs are possible.
@Arctic_Eddie: Your adapters work fine to connect two Arduino by a long cable. But did you really use it to connect more than 4 nodes? The problem is the onboard termination resistor. You should have these only on the ends of the bus and not on nodes connecting in between. I didn't test how many of them you can connect until the communication ends but I would expect bigger problems starting at about 4-5 nodes.
I would strongly recommend not to use SoftwareSerial if ever possible in your project. This is especially true for a multi-node RS-485 bus because else the connected Arduinos will do not much more than waiting for the serial bits to drop in. SoftwareSerial blocks the complete processor while anything is going on on the bus. On a bus with several participants even the Arduinos not actively communicating are blocked.
We tested with only two slaves. My friend in Colorado will be using 16 on a single network but has not tested the complete setup. If the accumulated load resistance becomes too low then the 120R resistors can be removed from all adapters but added to the last one via the A/B terminal block, if the cabling somewhat resembles a wired chain.
We used software serial because the slaves are Pro Minis and the hardware pins are kept open for upload and debug. Your point on the blocking of unaddressed slaves is well taken. However, I believe there are other soft serial libraries that attempt to get around this problem, AltSoftSerial and NewSoftSerial come to mind. In our case, it's not a problem because the slaves have nothing to do until queried by the master. On command from the master, the slave collects the requested data and transmits in return. A more exotic system might use a Teensy V3.6 as the master and V3.2 as slaves and run entirely on hardware serial ports. Both have at least four hardware serial ports. I've tested a pair of T3.2 boards directly on TTL serial and got 4.5Mbps. With the RS485 in line, that speed may not be possible, but still fast. We also created our own protocol for addressing and command and also came up with a scheme to allow any slave to become a temporary master and talk to any other slave. This is part of a home automation system of a large multi-story house with several out buildings. One link goes 1300 feet to the highway entrance. That one uses a special case in wiring due to grounds not being what you would expect.
@Arctic_Eddie: Thank you for your answer,
I have read example blog but one thing I can not understand is how addressing works? how can I select specific slave end send or receive information from it?
The packet the master sends contains addressee and command bytes, and other data. All slaves listen but only the addressee responds based on the command. There is a standard RS-485 protocol but in our case we have one master, numerous slaves, and a four byte fixed data size. It was easier, and more understandable, to create our own packet structure.
Arctic_Eddie wrote:
There is a standard RS-485 protocol
I would like you to provide a link that tells this. I think you are confused and are confusing other readers and the OP.
Let's get this correct again, RS-485 as commonly know, but more correctly EIA-485 or even TIA-485 is NOT a protocol at all. It is simply an electrical interface standard. The RS part of RS-485 and also RS-232 stands for Recommended Standard.
Now, getting back to handling data, say on RS-485, that can be done using a multitude of actual data protocols.
Modbus is one such protocol that has proven itself to work very well on the RS-485 interface.
It has been used in industrial control systems for decades and is becoming popular due to the protocol being open and not propriety.
Depending on what the OP wishes or needs to do with data exchange between the various Arduinos, there may be other options, that may be simpler than using Modbus, which tends to get most inexperienced folks into a certain degree of trouble.
So, lets keep hardware as hardware and software as software, RS-485 is not a protocol and is not software.
Here is an article by one of our moderators Nick Gammon and a quick overview of using RS-485 interface to exchange data between Arduinos. Unfortunately, even Nick gets slips up calling it a RS-485 protocol.
Link to article on RS-485 communications.
baxta31, you might find an answer in this article for your situation.
Paul - VK7KPA
I stand corrected. I was under the impression that there was a protocol based on comments by others over the years. When I use RS-485, I create my own packet scheme which does not have the 32 station limit others have mentioned. Maybe they were referring to Modbus.
Arctic_Eddie, I often find myself being corrected, which hopefully tells me I can still learn
The 32 station limit is not to do with software, but the hardware limitations for a lot of RS-485 driver chips.
These days, you can buy driver chips that support more than 32 mutlidrops, with chips for 64, 128 and even 256 stations.
There are also driver chips for 3.3 volt systems as well as the traditional 5 volt systems.
The Modbus protocol itself is not limited to 32 stations at all, it can address up to 247 unique stations as part of its standard.
Paul - VK7KPA