Ralph S Bacon

MicroControllers, Electronics and IOT

RS485 Serial Comms

Picture of an RS485 module

My latest video shows how easy it is to set up a couple of RS485 modules connected with two wires and an Arduino µController at either end so you can communicate with an outbuilding, shed or workshop, without using radio waves.

Even better is that you can connect several RS485 modules to the same two wires, so one for the shed and one for the barn, for example.

Did I say “easy”? Well, why did it take me 3 hours to get a very simple couple of sketches running then? Watch the video to find out!

Categories:Uncategorized

29 replies

  1. Hi Ralph, Thanks for your video. I have started looking into Home Automation using arduinos etc as a hobby and wanted to get a power monitor put on my mains… I have some experience with machine learning and wanted to use the electronic signature in change of current usage to identify devices etc… But the main requirement was a reliable power monitor. I tried using a few using PZEM-0004T, emon, etc, and am now trying a EM-115 power meter with RS485. Having no experience on how to interface an Arduino with RS485, I have embarked on this journey to equip myself with some understanding. Your Video and instructions are fantastic and very clearly laid out. I now intend to enhance my understanding and carry on my journey or figuring out how I can read from various registers using the register map 🙂

    Like

    • I’m glad I was able to nudge you in the right direction regarding RS485. These days it’s all Wi-Fi and Bluetooth but there’s still a lot of life left in wired connections!

      Thanks for posting and good luck with your project – and keep safe when using mains electricity!

      Like

  2. This something amazing Ralph, I just came across your post and found solution. Do you have any example with similar setup for more than 2 Arduino nano? I want understand how we can connect more than 2 arduino as all Pins on RS485 will be occupied by these 2.

    Like

  3. Sorry – Should have read Hi Ralph – told you my typing was terrible

    Like

  4. Hi Ray – enjoyed the Arduino RS485 video – is there anywhere that I can download the sketches in order to avoid my terrible typing.
    Vic Pallett
    vic.pallett@outlook.com

    Like

    • Yes, Bill (heh heh), just follow the link to my video (at the start of this blog) and the video description has all the details of my GitHub where you can find the sketches and more! Good luck with your project, Vic, and let us know how you get on.

      Like

  5. Hello Ralph,
    I test and implement your RS485 example, but I am not sure about your arrangement of Arduino Uno and White Board. Could you please provide a plan for it?
    In addition, may I know what is your IDE for opening the Sender.ino and Responder.ino?
    Thank you very much!

    Like

    • I can just talk you through this.

      The pins next to the green screw connectors are VCC and GND, with A and B which are the same as using the green pins. These are connected to the other RS485 module’s A & B pins. The VCC and GND should be connected to your Sender’s Arduino 5v and GND.

      The other end of the module is as follows. Link RE and DE together. That the blue loop of wire you see in the video. It then goes to Arduino pin 5 in the Sender sketch (yellow wire)

      DI is the transmitted data pin, so goes to Arduino pin 7 in my Sender sketch (orange wire).
      R0 is the received data pin, so goes to the Arduino pin 6 in my Sender sketch (green wire).

      The Responder sketch is wired up the same, it is just a simpler sketch as it does very little except echo back the previously received character.

      Finally, I’m using Eclipse IDE, in this video probably the Sloeber version which contains all the Arduino add-in included.

      I hope this helps, Eric.

      Like

      • Hello Ralph,

        It was nice to receive your reply. Your information was valuable to me.
        I have another question about a wire that connected between whiteboard and Responder arduino’s ICSP pin (black one).
        What’s the purpose for this one? And it seemed that the heads of this black line are different (in order to be connected at ICSP)?

        Thank you so much and look forward to hearing from you soon.

        Eric

        Like

        • The black wire simply connects the ground of the receiver Arduino to a common ground – it should not be necessary to have a common ground between Arduinos though. The ground from the receiver Arduino must be connected to the RS485 module, obviously, but should not be connected to any other module.

          Liked by 1 person

      • Hello Ralph,

        Sorry for asking so many questions.
        I have another question about the process of testing. I suppose that we need to verify and upload the Sender.ino and Responder.ino on two Arduino Uno individually.
        In your video, you verify and upload Sender.ino on COM 8 with Sloeber IDE, then Responder.ino will be verified and uploaded on COM 6 with Arduino.
        Because I do not clearly understand how do you test them simultaneously (send and receive).
        Thank you very much and look forward to hearing from you soon again!

        Like

        • This is simple to do: connect both your Arduinos to different USB sockets on your PC. They will be allocated different COM (port) numbers. Make sure you know which is which but it will become obvious anyway. Use the Serial Monitor on an Arduino IDE for one, and use something else (like Putty or Sublime Text or Eclipse, depending on what you have available) for the other COM port, as it is easy to get the Arduino IDE confused about which COM port it is connected to. Then you will have two, simultaneous Serial Monitor windows to see the two outputs on. Good luck!

          Liked by 1 person

      • Hello, again Ralph,

        As your statement “and use something else (like Putty or Sublime Text or Eclipse, depending on what you have available) for the other COM port”, I have Sublime Text at my laptop. But how could I set the other COM port in Sublime Text? (Should I set it?)
        And do I need to verify and upload Responder.ino?
        Sorry if I asked kind of stupid and basic question. 😛

        Like

        • You first need to watch my video #16 COM Ports & Device Drivers: https://youtu.be/7Lc3PtDMijY

          After that you should have figured out that each IDE (or Serial port monitor) will connect to the COM port you tell it. No, you don’t need to load any code (sketch) to do this, as that will be running in the Arduino by then. You should also consider downloading Putty (for Windows, not sure if there is a version for MAC) as it’s the defacto utility for all things serial port.

          But watch the video first, the bits you need are some way into the video but it will all be good background information that you need.

          Liked by 1 person

  6. Hi Ralph. Just an idea for a future product review. I got some HC-12 Serial Comms modules the other day and I’m very impressed initially. Really easy to set up and you can set each module to any of 100 channels just with AT commands. They have a max range of 1.8km line of sight. May be a nice option for wireless serial comms for folks. And none of this bluetooth pairing fiddling around. I also wrote a short method that takes character data and parses it as a string should you want to get data in that form. Works nicely with these units.

    Love your channel Ralph. Thanks.
    Gord – Newmarket, Ontario Canada (gpTeacher on Youtube)

    Like

    • I just had a quick look at what the HC-12 brings us, Imseakin, and I like it. You may have seen my Bedroom lamp controller videos #26 & #27 using a 433Mhz transmitter/receiver, very easy to use but not on any particular channel which could be a problem if I wanted to control multiple items. It seems that this HC-12 might be a worthwhile upgrade. I shall investigate as per your suggestion, thanks for the heads-up!

      Like

  7. suggestion for the sender code. It transmits to receiver and you wait for the transmit to complete then when you go to Rx mode but don’t wait for a received reply by the responder. So miss the last response by about 10 milliseconds at 115200, So add

    while (!RS485.available());

    before

    if (RS485.available())

    Better would be while loop with a timeout so it doesn’t wait for ever if no reply.

    long timeout = millis();
    boolean timeout_occurred = false;
    do
    {
    timeout_occurred = ((millis() – timeout) > 1000);
    }
    while ((!RS485.available())&&(timeout_occurred == false));

    I like a flag (timeout_occurred) to know it happened so can reject data.

    thanks for the code it really helps.
    Graham

    Like

  8. Great idea to set up a blog, Ralph! I just hope it won’t cut your time on video production! Good luck and keep up with your tutoring!

    Like

    • I’m hoping it won’t reduce my YouTube time, Daniel, as I can quickly post things here (with a picture or two) in 10 minutes or so – rather than the several hours to produce a video. We shall see!

      Like

  9. This puts me in mind of a very similar situation I had recently with a kit of parts for an “Arduino on a breadboard” setup. I placed all the components on the breadboard, wired up my FTDI adaptor and attempt to upload the blink sketch. Nothing! Nada! Zilch! After 90 minutes of head-scratching and another 3 serial converters later (including a taking it all apart and putting it back together session) I finally had a rare moment of inspiration.

    “Why not pull the chip off the beardboard and plug it into the socket on an Arduino Uno board?”

    Brilliant idea 🙂

    OK, this is done and still I cannot upload a sketch to the chip. Finally the bloody penny drops: there is no bootloader on the chip. Oh how foolish do I feel now? 40 years a tinkerer and it takes me 90 minutes to figure out the obvious.

    This isn’t quite the end of the saga though. Now since I no longer use the Arduino IDE I have to manually build the bootloader from source and upload it myself using a makefile. Simple? Er, not quite. It turns out the chip I have isn’t an ATmega328P it is an ATmega328 (without a P) so uploading the bootloader fails until I modify the makefile. The signature bytes for the chips are different so avrdude throws an error without changing the chip type.

    Sir Arthur Conan Doyle wrote the famous Sherlock Holmes quote, “When you have eliminated the impossible, whatever remains, however improbable, must be the truth.” Apt indeed.

    Now for the final irony. I bought these 2 kits of parts from an English vendor and not an eBay one either! It just goes to show.

    Like

  10. Brilliant. I am going to utilise this answer. Recently (last November) was registered blind and intended automating some things around the home which already is wired with old call system in every room. This will be a great use for them. I was Arduino literate prior to going blind and have to get friend to do the “putting together” but still enjoy the “thinly” parts. ………….now, all I need is YouTube videos to come with audio description instead of subtitles and that’s me repaired as well!!! 🙂

    Like

  11. Well done. Looking forward to the blog post feedback. 😁
    I’m currently working on an RC2014 classic. Finished the build but my soldering
    and attention to detail were lacking.
    So I am troubleshooting the Serial I/0. Also trying to get an ARDUINO Nano to substitute for an FTDI cable.. fun…. not.

    Like

  12. and welcome back … to another blog posts (a lot of I hope) and the best of luck in the world
    Cheers 🙂

    Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.