RS-485 node control for Arduino

rs-485-arduino-nodes

Wanting to control a split flap display that was not near a computer [Tom] looked to a common solution for communicating over distances not practical for I2C or SPI. He developed his own hardware and packet format using the RS-485 protocol.

This is part of a larger project he has been working on to feed data to a split flap display that he plans to hang on the wall. RS-485 is designed to work over long distances and overcome noise issues. The core of the communications system is the board seen on the left. It uses a MAX1483 chip, a pair of RJ45 jacks for Ethernet cables, and two terminal blocks for power and communications. There are a few nice things about this. The board acts as a pass-through making it easy to chain nodes together, and the data structure is completely independent of the hardware itself. Because of this [Tom] developed his own packet format that will be a bit more resilient than the Arduino networking scheme we looked at the other day.

Comments

  1. Gizmos says:

    Any time I have a need for a simple protocol like this I use S.N.A.P.

    http://www.hth.com/snap/

    I’ve used it a lot and it has always served me well. I found it years ago.

    S.N.A.P is an free and open network protocol.

    – Easy to learn, use and implement.
    – Free and open network protocol.
    – Free development tools available.
    – Scaleable binary protocol with small overhead.
    – Requires minimal MCU resources to implement.
    – Up to 16.7 million node addresses.
    – Up to 24 protocol specific flags.
    – Optional ACK/NAK request.
    – Optional command mode.
    – 8 different error detecting methods (Checksum, CRC, FEC etc.).
    – Can be used in master/slave and/or peer-to-peer.

  2. Matt says:

    That’s a nice, compact design. I like it. Props for designing his own framing. Adding POE would make this really awesome.

    • EccentricElectron says:

      Why? RS485 isn’t ethernet, even if the connectors look similar.

      • Matt says:

        POE exploits the fact that 10×100 baseT internet only uses 2 pairs.(out of 4).. so you can run power over the unused wires.

        RS485 is a 3 wire serial link. 8 wires – 3 wires = 5 wires not doing anything….so why not run power on them.

        • Gizmos says:

          POE is Power Over Ethernet. You would be adding Power to something that is Ethernet to get POE.

          You just mean run power? In this case there are 8 wires, but there is no cable definition for RS485.

          • Matt says:

            You could still follow the POE standard even if the data lines were not technically Ethernet. You could also obviously understood what I meant, so why be a semantic douche?

          • Gizmos says:

            Matt: I don’t use childish name calling, so if you want that from me you’l be disappointed. POE is more than “run power on wires” and the reason for my comment is that enough people are perceiving this hack as somehow related to Ethernet.

            You, I’m sure, will insist on using the term POE incorrectly. That is your choice.

          • Matt says:

            That’s funny…I saw no confused statements about this being TCP/IP. The only confusing statements I see are the snarky “It’s not TECHNICALLY Ethernet” comments.

        • John says:

          Power over ethernet doesn’t use unused pairs, because gigabit uses all 4 pairs. It adds a dc bias to one of the pairs. You should check out the wikipedia article.

        • Cyril says:

          485 uses http://en.wikipedia.org/wiki/Differential_signaling so in full duplex it uses 5 (or more)

          If designed properly and the nodes do not have significant power requirements (usually a design issue), one can phantom power the nodes, ie use the power on the rx line(s).

    • Tom says:

      There is no reason it couldn’t have a 5v power line but I wonder how the length cable runs might cause the power to drop off down the line, and also if there might be noise issues? Regardless for my needs each node will have a motor needing a fair chunk of power so it isn’t appropriate for the project, I have thrown it up on GitHub so you could always add it.

  3. Steve says:

    I guess whenever I see RS-485, I immediately jump to Modbus. Tons of equipment speak it, open and typical for just about any control guy. I see they have a Modbus library for Arduino: http://www.arduino.cc/playground/Code/ModbusMaster

  4. Michael says:

    This is a very nice setup and designed well. I also believe adding POE in the future would even add to the beauty of this design.

  5. bleullama says:

    Very nice indeed! i dig your minimal Arduino board too!

  6. JWC says:

    Hmm, what’s the difference between the MAX1482 and the MAX485 (or TI’s equivalent: SN75176B)? Is it only that the former is full duplex? If so, then what’s the difference between the 1483 and the 485?

  7. deathventure says:

    I wonder why there’s so much confusion happening between what RS485 and ethernet is…

    • willy says:

      because the average (uneducated) thinks ethernet is defined by the wire and connectors. this hack uses rj45 connectors and twisted pair. the uneducated thinks this is ethernet when in fact, it is just the wiring he chose.

    • Eye Security says:

      I made the mistake of thinking it was Ethernet by looking at the picture and not actually reading the title RS485 or the article. Only skimmed it. I was also doing 6 different things at once but I should of known better as I created a implementation using the RS485 standard not to long ago. In other words I fail at doing several things at once and just skimming.

    • Gizmos says:

      Probably because there are “Ethernet connectors” in the picture. And I say that quoted phrase tongue-in-cheek.

    • Gizmos says:

      This reminds me of an older gentleman that couldn’t send emails on his computer. The problem? The “email cable” fell out the back. Once he reattached the “email cable” then he could send emails again.

      People see the cable as an Ethernet cable and not as an RS485 connection. Hence adding power is POE despite the fact that there is no Ethernet going on here. The communication would be TCP/IP, despite the fact that it is not Ethernet.

      When all you have is a hammer, everything looks like a nail.

  8. Pete.S. says:

    Couldn’t find the schematics for the RS485 board so can’t be sure but I didn’t see any termination. RS485 needs termination at each end, typical 120 ohm or so.

    In a multidrop configuration with duplex communication you also need pull up and pull down resistors to put the bus in a known state when there is no communication since there is no driver that is active. Failure to do this will result in lot of communication errors in a noisy environment.

    There are 4 pairs of wire in a CAT6 cable so one or two pairs could carry power to each device if the current consumption is low. Preferably higher voltage like 24V since there will be some voltage drop. With switching voltage regulators on each node it’s no problem to get 5V or 3.3V without having to use a heatsink.

    • Pete.S. says:

      “multidrop configuration with duplex communication” should have been “multidrop configuration with HALV duplex communication” meaning only one master at a time.

      If there a several nodes that could initiate communication at any time you need some type of collision detect. Easiest way is to read from the bus at the same time as you send. If you don’t receive what you send wait a random time and then transmit again.

      IME the hardware with a RS485 bus is the easy part.It’s the software with error detection, retransmittion, timeouts etc that is the tricky part. At least when you put it in industrial environments.

      Ethernet is only 100m betwean nodes but you would just run some fiber when you need anything longer. I tink singlemode 1000base LX goes to 10 km or so.

      • Matt says:

        In reality, since he is using cat5 cable, he could implement RS422 instead, which would allow for full duplex and reduce collisions. The max148x family of chips even support 422 already, so it would only take a board revision (or some jumper wires) to change it.

      • Eccentric Electron says:

        The 100m Ethernet limit is a function of the ethernet protocol + media (cat5(e), cat6). You can comfortably get 1000m+ over 485, in a noisy environment, provided you are willing to compromise on baud rate – it was designed specifically for this purpose, which is why it uses differential signalling.

    • Tom says:

      I have uploaded it to GitHub:

      https://github.com/unknowndomain/Basic-Arduino

      https://github.com/unknowndomain/RS-485-Adapter

      I did a lot of reading about RS-422 and RS-485 and it turns out that you don’t always need a terminating resistor and as a result you shouldn’t use one by default but when actually needed as it can be bad. Additionally the use of a 120 ohm resistor isn’t always true either, it depends on the cable you use, CAT5 isn’t 120 ohm, it’s 100 ohm (if I recall correctly).

      RS-422 wouldn’t be suitable in this environment as it is intended to be used to extend RS-232 lines on a point-to-point basis, where as RS-485 is intended for multi-node communication, in my case I am using multi-drop but you could use the MAX1482 which has a separate line driver and line receiver allowing full duplex, however you’d need to figure out how to avoid collisions, using a variety of techniques.

      RS-485 is essentially what DMX uses and the DMX architecture was what I wanted to mirror, multiple fixtures in a ‘universe’ that listen, with one device barking orders out but not getting a response, only presuming that the fixtures heard the message. Using my simple protocol/messaging frame I haven’t had any messages interpreted incorrectly over 50 meters of CAT5.

  9. momche says:

    Additionally implementing the MCPM mode of the ATMega reduces the data nodes have to listen to. This can easily be found in the datasheet. In short – there is a 9 bit mode of the UART – the 9th bit means that the following byte is an address. Every packet ends with the address again. If a node sees it’s address it starts building a packet and if a timeout is not reached and the CRC is OK then the packet can be used further.
    I am using MCPM with SNAP like protocol and it works well.

  10. Bogdan says:

    Dear Hack a day writers: please learn what a protocol is. RS 485 is not a protocol, it is a standard for a physical interface.
    Protocol is a set of rules regarding how information is exchanged. The same protocol can be used with different physical interfaces.

  11. Chris C. says:

    Funny all the confusion over CAT5/6 cable and RJ45 connectors being used for something other than Ethernet. They’re a convenient choice whenever a robust multi-conductor cable and connector is needed. I’ve used them for carrying audio, video, I2C, SPI, power, and more.

  12. Tanki Online Hack says:

    Simply want to say your article is as astounding. The clarity for your put
    up is just cool and i could assume you are a professional on this subject.
    Fine together with your permission let me to grab your RSS feed to
    keep up to date with forthcoming post. Thank you one million and please continue the enjoyable work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 96,771 other followers