RS485 Serial Communication Between Arduino Mega and Arduino Nano With Visuino (2024)

Introduction: RS485 Serial Communication Between Arduino Mega and Arduino Nano With Visuino

By BoianMVisuino

More by the author:

Sometimes we need to connect Arduino boards located far away from each other. The RS485 is a very convenient way to connect the boards with just 2 wires, and can work to a distance of 1200m (4000 ft). It also allows multiple boards to be connected easily to the same 2 wires. The downside is that the channel is shared between multiple devices, and only one of them can transmit at a time.

It is very easy to connect Arduino boards with RS485. There are cheap readily available, easy to use modules based on the Maxim Integrated MAX485 chip, and with the help of Visuino a graphical development environment for Arduino it is also very easy to program the communication.

In this Instructable I will show you how easy it is to connect Arduino Nano and Arduino Mega with RS485, and have the Arduino Nano send data from a sensor to the Arduino Mega, and the Arduino Mega to control the LED on the Arduino Nano, while also sending the data received from the Nano to a Serial Terminal.

Step 1: Components

  1. OneArduino compatible board (I use Arduino Nano, because I have one, but any other will be just fine)
  2. One Arduino Mega 2560, or other board with 2 or more Serial ports
  3. One10K Potentiometer
  4. Two MAX485 RS-485 Modules
  5. 9 Female-Female jumper wires
  6. 4 Female-Male jumper wires
  7. 1 Male-Male jumper wires
  8. 2Jumpers with open top (Picture 2) allowing a wire to be inserted from the top side between the pins

Step 2: Connect the Power and Control Wires for the RS485 Module to the Arduino Mega

  1. Connect the Male end of one of the Female-Male jumper wires (Black wire) to the Ground pin of the Arduino Mega (Picture 1)
  2. Connect the Male end of another one of the Female-Male jumper wires (Red wire) to the 5V Power pin of the Arduino Mega (Picture 1)
  3. Connect the Male-Male jumper wire (Blue wire) to the Digital pin 2 of the Arduino Mega (Picture 2)
  4. Connect the Male end of another one of the Female-Male jumper wires (Green wire) to the TX1 (Serial 1 Transmit) pin of the Arduino Mega (Picture 2)
  5. Connect the Male end of another one of the Female-Male jumper wires (Yellow wire) to the RX1 (Serial 1 Receive) pin of the Arduino Mega (Picture 2)
  6. Picture 3 shows where are the Ground, 5V Power, Digital 2, RX1, and TX1, pins of the Arduino Mega

Step 3: Connect the Power and Control Wires for the RS485 Module to the Arduino Nano

  1. Connect one of the Female-Female jumper wires (Black wire) to the Ground pin of the Arduino Nano (Picture 1)
  2. Connect another one of the Female-Female jumper wires (Red wire) to the 5V Power pin of the Arduino Nano (Picture 1)
  3. Connect the Female end of a Female-Male jumper wires (Blue wire) to the Digital pin 2 of the Arduino Nano (Picture 2 and 3)
  4. Connect another one of the Female-Female jumper wires (Yellow wire) to the RX (Serial Receive) pin of the Arduino Nano (Picture 2 and 3)
  5. Connect another one of the Female-Female jumper wires (Green wire) to the TX (Serial Transmit) pin of the Arduino Nano (Picture 2 and 3)
  6. Picture 4 shows where are the Ground, 5V Power, Digital 2, RX, and TX, pins of the Arduino Nano

Step 4: Connect the Potentiometer to the Arduino Nano

  1. Connect a Female-FemalePower wire(Red wire) to the one end pin of the Potentiometer (Picture 1)
  2. Connect a Female-FemaleSignal wire(Brown wire) to the Wiper(center) pin of the Potentiometer (Picture 1)
  3. Connect a Female-FemaleGround wire(Black wire) to the other end pin of the Potentiometer (Picture 1)
  4. Connect the other end of the Power wire(Red wire) to the REF (5V) pin of the Arduino Nano board (Picture 2)
  5. Connect the other end of the Signal wire(Brown wire) to the Analog pin 0 of the Arduino Nano board (Picture 2)
  6. Connect the other end of the Ground wire(Black wire) to the Ground pin of the Arduino Nano board (Picture 3)
  7. Picture 4 shows in Red the Arduino Nano pins that ware connected in this step. The picture also shows the pins connected in Step 2 in Blue

Step 5: Connect the Power and Control Wires to the RS485 Modules

  1. Connect the other end of the Ground wire(Black wire) from the Arduino Mega to the GND(Ground) pin of the RS485 Module (Picture 1)
  2. Connect the other end of the Power wire(Red wire) from the Arduino Mega to the VCC(Power) pin of the RS485 Module (Picture 1)
  3. Place a jumper between the DE and RE pins of the RS485 Module (Picture 2)
  4. Connect the other end of the TX wire(Green wire) from the Arduino Mega to the DI(Driver Input) pin of the RS485 Module (Picture 3)
  5. Connect the other end of the RX wire(Yellow wire) from the Arduino Mega to the RO(Receiver Output) pin of the RS485 Module (Picture 3)
  6. Connect the other Male end of the Digital Pin 2 wire (Blue wire) from the Arduino Mega to the center of the Jumper between the DE and RE pins of the RS485 Module (Picture 4). Make sure the wire has a good electrical connection with the metal plate in the jumper
  7. Repeat the same steps from 1 to 6 for the other RS485 Module and the Arduino Nano board

Step 6: Connect the Two RS485 Modules to Each Other

The RS485 uses only 2 wires. Every device is connected to the 2 wires (Picture 1). There are some resistors that are needed, however the MAX485 Modules that we use have these resistors already installed, so we can directly connect the modules with just 2 wires.

  1. Connect one end of a Female-Female jumper wire - A wire(White wire) to the "A" pin of one of the RS485 Modules (Picture 2 and 3)
  2. Connect one end of another Female-Female jumper wire - B wire(Brown wire) to the "B" pin of one of the RS485 Modules (Picture 2 and 3)
  3. Connect other end of a A wire(White wire) to the "A" pin of the other RS485 Module (Picture 2 and 3 and 4)
  4. Connect other end of a B wire(Brown wire) to the "B" pin of the other RS485 Module (Picture 2 and 3 and 4)

Step 7: Start Visuino, and Select the Arduino Nano Board Type

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/.

Please be aware that there are some critical bugs in Arduino IDE 1.6.6.

Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuino as shown in the first picture
  2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino
  3. When the dialog appears, select "Arduino Nano" as shown in Picture 2

Step 8: In Visuino: Add and Connect Analog Snapshot, and Clock Generator Components

We will send to the serial the value of Analog Channel 0 once a second. For this we need to use "Analog Snapshot" component, and to clock it once a second with the "Clock Generator":

  1. Type "snap" in the Filter box of the Component Toolbox then select the "Analog Snapshot" component (Picture 1), and drop it in the design area
  2. Connect the "Out" pin of the "Digital[ 14 ]/AnalogIn[ 0 ]" channel of the Arduino component to the "In" pin of the AnalogSnapshot1 component (Picture 2)
  3. Connect the "Out" output pin of the AnalogSnapshot1 component (Picture 3) to the "In" input pin of the "Serial[ 0 ]" channel of the Arduino component (Picture 4)
  4. Type "clock" in the Filter box of the Component Toolbox then select the "Clock Generator" component (Picture 5), and drop it in the design area
  5. Connect the "Out" output pin of the ClockGenerator1 component to the "Snapshot" input pin of the AnalogSnapshot1 component (Picture 6)

Step 9: In Visuino: Connect the Sending Pin of the Serial to the Digital 2 Pin to Control the RS485 Direction

The RS485 uses the same shared channel for both sending and receiving data. It is a Simplex line. This means that the board can't send and receive data at the same time, and the RS485 module needs to be switched between transmitting and receiving mode. The Serial port of the Arduino component in Visuino has a pin indicating that the port is sending data. We will use this pin to control the direction (Transmit/Receive) of the RS485 module.

  • Connect the "Sending" output pin of the "Serial[ 0 ]" channel of the Arduino component to the "Digital" input pin of the "Digital[ 2 ]" channel of the Arduino component (Picture 1)

Step 10: In Visuino: Add and Connect Char to Text Component

We will receive 2 text commands ("on" and "off") through the Serial port controlling the LED on pin 13. The commands will arrive as text followed by enter. To decode the "on" command we first will construct a text from the arriving characters followed by Enter/New Line by using a "Char To Text" component:

  1. Type "char" in the Filter box of the Component Toolbox then select the "Char To Text" component (Picture 1), and drop it in the design area
  2. Connect the "Out" pin of the "Serial[ 0 ]" channel of the Arduino component to the "In" pin of the CharToText1 component

Step 11: In Visuino: Add and Connect Compare Text Value Component

Now that we have the text we need to check if it is "on" or "off". To do this it is enough to check just for "on". For this, we will use "Compare Text Value" component:

  1. Type "compare" in the Filter box of the Component Toolbox then select the "Compare Text Value" component (Picture 1), and drop it in the design area
  2. In the Object Inspector, set the value of the "Value" property to "on" (Picture 2)
  3. Connect the "Out" pin of the CharToText1 component to the to the "In" pin of the CompareTextValue1 component (Picture 3)
  4. Connect the "Out" output pin of the CompareTextValue1 component (Picture 4) to the "Digital" input of the "Digital[ 13 ]" channel of the Arduino component (Picture 5)

Step 12: Generate, Compile, and Upload the Arduino Code to the Arduino Nano

  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. Connect the Arduino Nano with the USB cable to the computer
  3. In the Arduino IDE select the board type as Arduino Nano (Picture 2)
  4. In the Arduino IDE select the serial port to which the Arduino Nano board is connected (Picture 3)
  5. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 4)

Step 13: In Visuino: Select the Arduino Mega Board Type

  1. Start a new Visuino project as shown in the first picture
  2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino
  3. When the dialog appears, select "Arduino Mega 2560" as shown in Picture 2

Step 14: In Visuino: Connect the Output of Serial 1 to the Input of Serial 0

We will send the serial data that we receive from the RS485 module on Serial Port 1 to the computer through Serial Port 0 . For this we need to connect the two ports:

  • Connect the "Out" output pin of the "Serial[ 1 ]" channel of the Arduino component to the "In" input pin of the "Serial[ 0 ]" channel of the Arduino component (Picture 4)

Step 15: In Visuino: Connect the Sending Pin of the Serial 1 to the Digital 2 Pin to Control the RS485 Direction

Since the RS485 uses the same shared channel for both sending and receiving data we will use the "Sending" pin of the Serial Channel 1 to control the direction (Transmit/Receive) of the RS485 module:

  • Connect the "Sending" output pin of the "Serial[ 1 ]" channel of the Arduino component to the "Digital" input pin of the "Digital[ 2 ]" channel of the Arduino component (Picture 1)

Step 16: In Visuino: Add and Connect Delay Component

We want to send "on"/"off" command for the LED to flip it after every value we receive over the RS485. Since the RS485 is simplex, it is better to wait for it to properly switch before we send any data. For this we can use a Delay component set to 100 Milliseconds (100000 Microseconds):

  1. Type "delay" in the Filter box of the Component Toolbox then select the "Delay" component (Picture 1), and drop it in the design area
  2. In the Object Inspector, set the value of the "Interval" property to "100000" (Picture 2)
  3. Connect the "Out" pin of the "Serial[ 1 ]" channel of the Arduino component to the "In" pin of the Delay1 component (Picture 3)

Step 17: In Visuino: Add and Connect T Flip Flop Component

We want to switch between "on", and "off" command every time a new text arrives over the serial. To do that we need to use a Flip-Flop. The most convenient for this purpose is the Toggle(T)-FlipFlop:

  1. Type "flip" in the Filter box of the Component Toolbox then select the "Toggle(T) Flip-Flop" component (Picture 1), and drop it in the design area
  2. Connect the "Out" pin of the Delay1 to the "In" pin of the TFlipFlop1 (Picture 2)

Step 18: In Visuino: Add and Connect Digital to Text Component

The Flip-Flop will generate Digital(Boolean) value switching between True and False. We need to convert this into "on" and "off" text. For this we will use "Digital To Text" component:

  1. Type "To Text" in the Filter box of the Component Toolbox then select the "Digital To Text" component (Picture 1), and drop it in the design area
  2. In the Object Inspector, set the value of the "FalseValue" property to "off" (Picture 2)
  3. In the Object Inspector, set the value of the "TrueValue" property to "on" (Picture 3)
  4. Connect the "Out" pin of the TFlipFlop1 component to the "In" pin of the DigitalToText1 component (Picture 4)
  5. Connect the "Out" output pin of the DigitalToText1 component to the "In" input pin of the "Serial[ 1 ]" channel of the Arduino component (Picture 4)

Step 19: Generate, Compile, and Upload the Arduino Code to the Arduino Mega

  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. Connect the Arduino Mega with the USB cable to the computer
  3. In the Arduino IDE select the board type as Arduino Mega (Picture 2)
  4. In the Arduino IDE select the serial port to which the Arduino Mega board is connected (Picture 3)
  5. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 4)

Step 20: And Play...

Congratulations! You have implemented RS485 communication between 2 Arduino boards.

Picture 1 and the Video show the connected and powered up project.

If you connect to the Arduino Mega with Serial Terminal or Visuino you will see the position of the potentiometer displayed in text form (Picture 2). In Visuino you can also see it plotted in the Scope (Picture 3) . If you turn the Potentiometer the values will change. The LED on the Arduino Nano will also turn On and Off every second, when new data is received by the Arduino Mega.

On Picture 4 you can see the complete Visuino diagram for the Arduino Nano.

And on Picture 5 you can see the complete Visuino diagram for the Arduino Mega.

Also attached are the Visuino projects, that I created for this Instructable. You can download and open them in Visuino: https://www.visuino.com

Attachments

  • RS485SimpleDataCommunicationInstructable.zip

    Download

RS485 Serial Communication Between Arduino Mega and Arduino Nano With Visuino (6)

Participated in the
Raspberry Pi Contest 2016

RS485 Serial Communication Between Arduino Mega and Arduino Nano With Visuino (2024)

FAQs

Is RS-485 compatible with Arduino? ›

Thanks to the Arduino ecosystem tools, such as the Arduino IDE and the ArduinoRS485 library, it is really easy to implement communication protocols using the RS-485 interface.

How to communicate 3 or 32 Arduinos via RS-485? ›

Pins DI and R0 are used to transmit data (DI - Data Input) and receive data (RO - Received Output). Connect the TX pin to the DI and the RX to the RO. The configuration of the data transfer or reception mode is done through the DE and RE pins. The first thing you must do is connect the pins with a jumper.

What is the best way to communicate between two Arduinos? ›

Inter-Integrated Circuit or I2C (pronounced I squared C) is the best solution. I2C is an interesting protocol. It's usually used to communicate between components on motherboards in cameras and in any embedded electronic system. Here, we will make an I2C bus using two Arduinos.

What is an example of RS-485 communication? ›

Some of the examples are robotics, base stations, motor drives, video surveillance and also home appliances. In computer systems, RS485 is used for data transmission between the controller and a disk drive. Commercial aircraft cabins also use RS485 for low-speed data communications.

How to connect RS-485 module to Arduino? ›

RS-485 module as transmitter

In order to be used as a transmitter, RE pin and DE pin must be connected to 5V, and DI pin is connected to TX. Data is sent from Arduino TX pin to module DI pin, then data will be sent through AB.

How to connect RS-485 to microcontroller? ›

Wiring. Unlike how you normally wire UART ports (TX to RX and RX to TX), we have to connect the RX pin of the microcontroller to the RXD pin of the RS-485 module and the TX pin to the TXD pin. This is because the RS-485 module is not a UART device itself, but a pass-through system only.

How to check RS-485 communication? ›

For communication errors, the left side decimal point of the symbol display on the main unit blinks. If the SD or RD indicators light on upstream devices, check whether both are blinking.

How to send serial data between Arduinos? ›

One or multiple bytes can easily be transferred using a serial connection, using the "TX" (transmit) and "RX" (receive) pins of the Arduinos. You just connect the TX pin from Arduino #1 to the "RX" pin of Arduino #2 - and: connect the GND pins of the two.

What are the 2 types of serial communication in Arduino? ›

Types of Serial Communications
  • Synchronous − Devices that are synchronized use the same clock and their timing is in synchronization with each other.
  • Asynchronous − Devices that are asynchronous have their own clocks and are triggered by the output of the previous state.

Can you connect two Arduinos to one computer? ›

Any 2-4 types of Arduino boards can be attached simultaneously to program. Here, 2 are attached for programming. Five for each of the matching circuits of this demonstration.

Can Arduino communicate wirelessly? ›

The Arduino Wireless SD Shield allows an Arduino board to communicate wirelessly using a wireless module.

Is RS-485 a serial communication protocol? ›

RS-485, also known as TIA-485(-A) or EIA-485, is a standard, originally introduced in 1983, defining the electrical characteristics of drivers and receivers for use in serial communications systems. Electrical signaling is balanced, and multipoint systems are supported.

What is RS-485 communication system? ›

RS-485 simply stands for Recommended Standard #485, and it's been around since 1983. It is used for Serial communication. Devices that use Serial ports usually have a 9 pin D connector or a terminal block connector.

How does RS-485 addressing work? ›

Commands on a RS-485 bus are preceded by an address ID, usually 1 byte. All devices on the bus will receive commands sent to the bus and if a device is not programmed to respond to a particular ID, it will ignore the command.

Can Arduino read Modbus? ›

A lot of Arduino boards are Modbus compatible especially if you consider Ethernet-type messages. In case you want to communicate via RS-485, MKR 485 Shields will help you convert any MKR board into a Modbus compatible device.

Is RS-485 same as canbus? ›

Maximum Cable Length: The maximum cable length supported by the CAN bus is 500 meters, however, the maximum cable length supported by RS485 is 1200 meters. Data Transfer Rate: While RS485 allows up to 10 Mbps, CAN bus offers a greater 1 Mbps data transfer rate.

What code does Arduino accept? ›

Arduino uses a variant of the C++ programming language. The code is written in C++ with an addition of special methods and functions. Moreover, when you create a 'sketch' (the name given to code files in this language), it is processed and compiled to machine language.

Is RS-485 obsolete? ›

Two of the oldest interfaces are RS-232 and RS-485. Surprisingly, these legacy interfaces aren't obsolete. Both are still used in a variety of applications.

Top Articles
Latest Posts
Article information

Author: Maia Crooks Jr

Last Updated:

Views: 6413

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Maia Crooks Jr

Birthday: 1997-09-21

Address: 93119 Joseph Street, Peggyfurt, NC 11582

Phone: +2983088926881

Job: Principal Design Liaison

Hobby: Web surfing, Skiing, role-playing games, Sketching, Polo, Sewing, Genealogy

Introduction: My name is Maia Crooks Jr, I am a homely, joyous, shiny, successful, hilarious, thoughtful, joyous person who loves writing and wants to share my knowledge and understanding with you.