Support for Arduino RS485 concurrent multi-drop communication.

Hi,

For those who want to communicate over RS485, you might be interested in the project I published here: GitHub - MichaelJonker/HardwareSerialRS485: Arduino Software for RS485 support with collision detection and message handling capabilities .

This project provides a software suite to support the use of an RS485 transceiver connected to the USART (Tx/Rx pins) in a half-duplex, concurrent multi-drop (i.e. multi-master, multi-slave) environment. For this purpose, the software suite has capabilities for message addressing and filtering as well as collision detection and avoidance.
For further questions and discussion (English, French, or Dutch) please reply to this topic.

Looks nice at first glance.


Rob

Seems like your software could be used basically unchanged with CAN transcievers instead of RS485. Those can even be cheaper than RS485 too. I've had good results using them for lighting control in a similar application. They are also simpler to drive because there is only a drive and receive pin, and if the bus floats high unless at least one node pulls it low. Collision detection is a lot simpler.

Also, you might want to define a few header strings as "reserved" if you think this might ever get popular. I did it the easy way and reserved everything less than 6 bytes long. That way you can add features later.

What I do in for collision detection is just to monitor the bus for one full byte-time before I send, I don't bother detecting bus occupancy when I'm not trying to transmit. I also do automatic collision detection retry based on a random backoff(which is constantly being reseeded by the data on the bus and exact arrival times)

All in all it looks really useful and like a great project!

Hello, thanks for your reply.

As for my project, I need to talk with up to 16 arduino’s over a distance of 500m using a field bus in real fields (cow shit included :grin: ). For this RS485 seemed most appropriate. However, the CAN bus might have done as well I guess (Electrically speaking the two busses are not so different: RS485 drives the voltage in two directions, CAN transceivers in only one).

As price is concerned this does not seem to be an issue (and RS485 transceivers are slightly cheaper). I designed my own printed circuit board with an Atmega328/Arduino and all the electronics I need for my application. Adding an RS485 transceivers was of the order of 1 €.

For bus occupancy detection I do the same as what you described and make sure the bus is idle for at least some time (dependent on the node priority) before transmitting. However, I do not have to explicitly wait for this time. Since I also read from the bus, the software just notes down the last receive ms time. Before transmitting one can see how long the bus has been idle and only wait if needed. In addition, this soft also detects collisions. This is achieved by reading while it is writing. Any mismatch or frame error is a sign of collision. In this case transmission will stop and can be retried sometimes later. (I have to admit that I should still ‘bench-mark’ the collision detection when transmitters are spread over large distances).

This soft uses the Tx/Rx lines of the integrated USART of the Atmega, so there is no need for a softSerial class. As I also want to be able to talk to the Arduino over the normal RS232 (Tx/Rx) lines, it needs full control over the individual RS485 TE/RE enable. Like this I can reload the Arduino from the IDE and start up in RS232 mode, and interact with it over USB/RS232. The program can then switch programmatically to the RS485 mode. When writing to RS232/RS485, the data will always be visible on RS232/USB, however, one cannot read from both UBS/RS232 and RS485/RS232.

I think that the soft can be adapted to CAN bus transceivers, but as said above for full functionality there need to be control over the Rx and Tx enable lines, not all CAN transceivers have them. Without this control, you will lose the flexibility to transparently upload a new application from the IDE. A clumsy solution would be based on jumpers which you change before and after reloading the program.

Last remark, this software implement a bare message transport with some primitives for address based message filtering. One can probably implement a higher level protocol on top of it. This is however, not my highest priority right now.

But I would be interested in a reference to any public domain CAN controller software for the Arduino for comparison.

Gr. Michael

Plz give me an example to how use this library

Bonjour,
j'envisage de réaliser un véhicule téléguide sous marin avec liaison filaire et suis très intéressé par le RS485 pour réaliser la liaison entre le rov et le poste de pilotage en surface.
Ma longueur de fil sera de 100 mètres.
Je veux pouvoir commandé 4 à 5 moteurs, avoir des retours d'informations de capteurs, profondeur, température, cap etc ..
Pour ce faire, je suis à la recherche de solution de communication avec arduino et d'exemples, car pour l'instant j'ai du mal à appréhender cette technologie.
D'avance merci pour votre aide .
Cordialement

Features of this lib - sound very nice, im going to try.
Just now im building hw for testing, but from sources i figured, it will not be easy to use - especially set pins for 485 circuit in that board.txt file looks ugly, why cant be this defined in sketch like pin for status LED ?

Also im abit confused about that 485 and RS232 switch feature, dont have an idea for what is this good :open_mouth:

Is there someone who successfully tested this lib ?

thanx for any info