Arduino Nano ESP32 - RS422

This tutorial instructs you how to use RS422 communication with ESP32. We'll learn through the following steps:

Hardware Preparation

1×Arduino Nano ESP32
1×USB Cable Type-C
1×TTL to RS422 Module
1×Jumper Wires
1×(Optional) RS422 to USB Cable
1×(Recommended) Screw Terminal Adapter for Arduino Nano

Or you can buy the following sensor kit:

1×DIYables Sensor Kit 30 types, 69 units
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. We appreciate your support.

Overview of TTL to RS422 Module

When employing serial communication on the Arduino Nano ESP32 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 function at TTL level, meaning they handle signals with a limited range. Therefore, for serial communication over longer distances, it becomes essential to convert the TTL signal to RS232, RS422, or RS485 standards.

In this guide, we will explore the use of RS422 (also referred to as RS-422) with the Arduino Nano ESP32 by incorporating 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 features two interfaces:

  • TTL Interface (connected to ESP32):
    • VCC Pin: This power pin should be connected to VCC (5V or 3.3V).
    • GND Pin: This power pin should be connected to GND (0V).
    • RXD Pin: This data pin should be connected to a TX pin of the Arduino Nano ESP32.
    • TXD Pin: This data pin should be connected to an RX pin of the Arduino Nano ESP32.
  • RS422 Interface:
    • A (R+) Pin: This is the RX+ pin of the module. Connect this pin to the TX+ pin (T+ or Y pin) of the other RS422 device.
    • B (R-) Pin: This is the RX- pin of the module. Connect this pin to the TX- pin (T- or Z pin) of the other RS422 device.
    • Y (T+) Pin: This is the TX+ pin of the module. Connect this pin to the RX+ pin (R+ or A pin) of the other RS422 device.
    • Z (T-) Pin: This is the TX- pin of the module. Connect this pin to the RX- pin (R- or B pin) of the other RS422 device.
    RS-422 module Pinout
    image source: diyables.io

Wiring Diagram

The wiring diagram between Arduino Nano ESP32 and TTL to RS422

This image is created using Fritzing. Click to enlarge image

How To Program Arduino Nano ESP32 to use the RS422 module

  • Define the serial pin pins:
#define RX1PIN D3 #define TX1PIN D2
  • Initializes the Serial interface:
Serial1.begin(9600, SERIAL_8N1, RX1PIN, TX1PIN); // RS232

Arduino Nano ESP32 Code

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

Testing

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

  • Connect Arduino Nano ESP32 to your PC via RS422-to-USB cable as below:
Arduino Nano ESP32 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 ESP32.
  • 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!