Arduino Nano - RS422

In this tutorial, we'll explore the process of establishing RS422 communication with an Arduino Nano. We'll cover the following steps in detail:

The tutorial also provides the instruction for both Hardware Serial and SoftwareSerial.

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×TTL to RS422 Module
1×Jumper Wires
1×Breadboard
1×(Optional) RS422 to USB Cable
1×(Recommended) Screw Terminal Expansion Board for Arduino Nano
1×(Recommended) Breakout Expansion Board for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of TTL to RS422 Module

When employing serial communication on the Arduino Nano using functions such as Serial.print(), Serial.read(), and Serial.write(), data transmission occurs via the TX pin while data reception takes place through the RX pin. These pins operate at TTL level, meaning they handle signals with limited range. Consequently, for serial communication over extended distances, it becomes necessary to convert the TTL signal to standards such as RS232, RS422, or RS485.

In this tutorial, we'll explore the integration of RS422 (also referred to as RS-422) with the Arduino Nano, achieved through the utilization of a TTL to RS422 module. This module facilitates the conversion of TTL signals to RS422 signals and vice versa.

Pinout

The RS422 to TTL module has two interfaces:

  • The TTL interface (connnected to Arduino Nano) includes 4 pins
    • VCC pin: power pin, needs to be connected to VCC (5V, or 3.3V)
    • GND pin: power pin, needs to be connected to GND (0V)
    • RXD pin: data pin, needs to be connected a TX pin of Arduino Nano
    • TXD pin: data pin, needs to be connected a RX pin of Arduino Nano
  • The RS422 interface comprises the following pins:
    • A (R+) pin: RX+ pin of the module, connect this pin to TX+ pin (T+ or Y pin) of the other RS422 device.
    • B (R-) pin: RX- pin of the module, connect this pin to TX- pin (T- or Z pin) of the other RS422 device.
    • Y (T+) pin: TX+ pin of the module, connect this pin to RX+ pin (R+ or A pin) of the other RS422 device.
    • Z (T-) pin: TX- pin of the module, connect this pin to RX- pin (R- or B pin) of the other RS422 device.
    RS-422 module Pinout
    image source: diyables.io

Wiring Diagram

  • Wiring diagram if using hardware serial
The wiring diagram between Arduino Nano and TTL to RS422

This image is created using Fritzing. Click to enlarge image

  • Wiring diagram if using software serial
The wiring diagram between Arduino Nano and RS-422 to TTL

This image is created using Fritzing. Click to enlarge image

How To Program Arduino Nano to use the RS422 module

  • Initializes the Serial interface:
Serial.begin(9600);
  • If you use SoftwareSerial, you need to include the library and declare a SoftwareSerial object:
#include <SoftwareSerial.h> #define RX_PIN 3 #define TX_PIN 2 // Define the SoftwareSerial objects and their pins SoftwareSerial rs422(RX_PIN, TX_PIN);

Arduino Nano Code for Hardware Serial

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-rs422 */ void setup() { // start communication with baud rate 9600 Serial.begin(9600); // wait a moment to allow serial ports to initialize delay(100); } void loop() { // Check if there's data available on Serial if (Serial.available()) { char data = Serial.read(); // read the received character Serial.print(data); // echo back to data to the sender } }

Arduino Nano Code for Software Serial

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-rs422 */ #include <SoftwareSerial.h> #define RX_PIN 3 #define TX_PIN 2 // define the SoftwareSerial object and their pins SoftwareSerial rs422(RX_PIN, TX_PIN); void setup() { // start communication with baud rate 9600 rs422.begin(9600); // wait a moment to allow serial ports to initialize delay(100); } void loop() { // Check if there's data available on rs422 if (rs422.available()) { char data = rs422.read(); // read the received character rs422.print(data); // echo back to data to the sender } }

Testing

You can do a test by sending data from your PC to Arduino Nano via RS-422 and vice versa. To do it, follow the below steps:

  • Connect Arduino Nano to your PC via RS422-to-USB cable as below:
Arduino Nano RS422 to PC communication
  • Install a Serial Terminal Program like Tera Term or PuTTY
  • Open the Serial Terminal Program and configure the Serial parameters (COM port, baurate...)
  • Type some data from the Serial Termial to send it to Arduino Nano.
  • If successful, you will see the echo data on the Serial Terminal.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!