ESP32 S3 UNO RS422

This ESP32 S3 Uno RS422 tutorial shows you how to send and receive serial data over long cables with a TTL to RS422 module. The ESP32 S3 Uno form board talks to the module with plain UART, and the module turns it into a strong differential RS-422 signal. At the end, you will type text on your PC and see it come back through the RS422 line.

In this tutorial, you will:

  1. Wire a TTL to RS422 module to the ESP32 S3 Uno.
  2. Receive data from an RS422 device with Arduino code.
  3. Send data to an RS422 device through the module.
  4. Use a second hardware UART (Serial2) on any pins instead of SoftwareSerial.
  5. Test RS-422 communication with your PC in both directions.
ESP32 S3 Uno RS422

Hardware Preparation

1×ESP32 S3 Uno-form Board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×TTL to RS422 Module
1×Jumper Wires
1×Optionally, RS422 to USB Cable
1×Recommended: 5V to 3.3V Level Converter for the TXD signal

Or you can buy the following kits:

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

The board's own TX and RX pins are fine for short wires on your desk. For long cables or noisy places, you need a stronger signal, and that is the job of this module.

When you call Serial.print(), Serial.read() or Serial.write(), the ESP32 S3 Uno sends bits out of a TX pin and reads bits on an RX pin. These pins use TTL logic levels (0V and 3.3V on this board). A TTL signal gets weak and picks up noise after a few meters, so it is not good for long distances. Standards like RS232, RS422 and RS485 solve this problem.

The TTL to RS422 module converts the board's TTL signal into an RS422 signal, and back again. RS422 sends each signal on a pair of wires (a differential pair), so it can travel far and ignore most electrical noise.

Pinout

The module has two sides. One side talks to the ESP32 S3 Uno, and the other side talks to the RS422 device.

TTL Side (to the ESP32 S3 Uno)

Pin What it does
VCC Power input. Connect to 5V or 3.3V
GND Ground. Connect to GND (0V)
RXD Data input of the module. Connect to the TX pin of the ESP32 S3 Uno
TXD Data output of the module. Connect to the RX pin of the ESP32 S3 Uno

RS422 Side (to the other device)

Pin What it does
A (R+) RX+ of the module. Connect to TX+ (T+ or Y) of the other RS422 device
B (R-) RX- of the module. Connect to TX- (T- or Z) of the other RS422 device
Y (T+) TX+ of the module. Connect to RX+ (R+ or A) of the other RS422 device
Z (T-) TX- of the module. Connect to RX- (R- or B) of the other RS422 device

Remember the simple rule: the transmit pair of one device always goes to the receive pair of the other.

RS-422 module Pinout
image source: diyables.io

ESP32 S3 Uno Pinout

The image below shows the pinout of the ESP32 S3 Uno form board. Use it to find the Uno header pins (D0, D1, D6, D7…) and their GPIO numbers while you wire the module.

ESP32 S3 Uno pinout diagram

Wiring Diagram

This tutorial has two wiring options. Pick the one that matches the code you plan to upload.

Option 1 - Serial1 on D0 and D1

The wiring diagram between ESP32 S3 Uno TTL to RS422

This image is created using Fritzing. Click to enlarge image

RS422 Module Pin ESP32 S3 Uno Pin
VCC 5V
GND GND
RXD D1 (GPIO43)
TXD D0 (GPIO44)

WARNING

D0 (GPIO44) and D1 (GPIO43) are the UART0 pins of the ESP32 S3 Uno. They are also used for USB serial, code upload and boot messages. While the module is connected here, uploading can fail and the RS422 device can get boot messages at power-up. Unplug the TXD and RXD wires while you upload code. If you also need the Serial Monitor, use Option 2 instead.

Option 2 - Serial2 on D6 and D7

The wiring diagram between ESP32 S3 Uno RS-422 to TTL

This image is created using Fritzing. Click to enlarge image

RS422 Module Pin ESP32 S3 Uno Pin
VCC 5V
GND GND
RXD D7 (GPIO14)
TXD D6 (GPIO3)

WARNING

D6 is GPIO3, a boot strapping pin on the ESP32 S3 Uno. The chip reads it at startup. If the module pulls this pin to a strange level during power-up, the board may not boot or upload correctly. If that happens, unplug the TXD wire from D6, upload or reset, then plug it back in.

WARNING

ESP32 S3 Uno pins are NOT 5V tolerant. When the module is powered from 5V, its TXD pin sends 5V signals into the board's RX pin (D0 or D6). To protect the board, either power the module from the 3.3V pin instead of 5V (the module works at 3.3V), or put a 5V to 3.3V level converter on the TXD line. The RXD line (board to module) is safe, because the board only sends 3.3V.

How To Program ESP32 S3 Uno to use the RS422 module

The module does all the RS422 conversion for you. On the code side, it looks like a normal serial port, so you only need the standard Serial functions.

Start a Hardware Serial Port

The ESP32 S3 Uno lets you place a hardware UART on almost any pins. You tell begin() the baud rate, the data format, the RX pin and the TX pin:

Serial1.begin(9600, SERIAL_8N1, 44, 43); // RX on D0 (GPIO44), TX on D1 (GPIO43)

No SoftwareSerial? Use Serial2

The SoftwareSerial library does not exist for the ESP32 S3 Uno. You do not need it, because the board has a spare hardware UART. Put Serial2 on D6 and D7 like this:

Serial2.begin(9600, SERIAL_8N1, 3, 14); // RX on D6 (GPIO3), TX on D7 (GPIO14)

Read Data from RS422

Use any of these functions to read what the RS422 device sends:

Send Data to RS422

Use any of these functions to send data out to the RS422 device:

Just replace Serial with Serial1 or Serial2. You can find more functions in the Serial reference.

ESP32 S3 Uno Code for Hardware Serial

This sketch starts Serial1 on D0 (GPIO44) and D1 (GPIO43) at 9600 baud. Every character that arrives from the RS422 line is sent straight back, so the other device sees an echo. Use it with the Option 1 wiring.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-rs422 */ #define RS422_RX_PIN 44 // ESP32 S3 Uno pin D0 (GPIO44) connected to TXD of the RS422 module #define RS422_TX_PIN 43 // ESP32 S3 Uno pin D1 (GPIO43) connected to RXD of the RS422 module void setup() { // start communication with baud rate 9600 on hardware serial port 1 Serial1.begin(9600, SERIAL_8N1, RS422_RX_PIN, RS422_TX_PIN); // wait a moment to allow serial ports to initialize delay(100); } void loop() { // Check if there's data available on Serial1 if (Serial1.available()) { char data = Serial1.read(); // read the received character Serial1.print(data); // echo back to data to the sender } }

ESP32 S3 Uno Code for Serial2 (instead of Software Serial)

This version does the same echo job, but it uses Serial2 on D6 (GPIO3) and D7 (GPIO14). It replaces the SoftwareSerial sketch used on other boards, and it keeps the USB serial port free. Use it with the Option 2 wiring.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-rs422 */ // The ESP32 S3 Uno has no SoftwareSerial. It uses the hardware serial port 2 on any pins instead #define RS422_RX_PIN 3 // ESP32 S3 Uno pin D6 (GPIO3) connected to TXD of the RS422 module #define RS422_TX_PIN 14 // ESP32 S3 Uno pin D7 (GPIO14) connected to RXD of the RS422 module void setup() { // start communication with baud rate 9600 on hardware serial port 2 Serial2.begin(9600, SERIAL_8N1, RS422_RX_PIN, RS422_TX_PIN); // wait a moment to allow serial ports to initialize delay(100); } void loop() { // Check if there's data available on Serial2 if (Serial2.available()) { char data = Serial2.read(); // read the received character Serial2.print(data); // echo back to data to the sender } }

Testing

The quickest way to test is to let your PC play the role of the RS422 device. You type text on the PC, it travels through the RS422 cable, and the ESP32 S3 Uno sends it right back.

Upload the Code

  1. New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
  2. Wire it up as shown in the diagram for the option you chose.
  3. Connect the board to your computer with a USB Type-C cable.
  4. Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
  5. Copy the code for your wiring option and paste it into the Arduino IDE.
  6. Upload the code by clicking the Upload button. With Option 1, unplug the module's TXD and RXD wires during upload and plug them back in after.

Talk to the Board from Your PC

  1. Connect the RS422 side of the module to your PC with an RS422 to USB cable, as shown below.
ESP32 S3 Uno RS422 to PC communication
  1. Install a serial terminal such as Tera Term or PuTTY.
  2. Open the terminal on the COM port of the RS422 to USB cable, and set it to 9600 baud, 8 data bits, no parity, 1 stop bit.
  3. Type some text in the terminal window.
  4. Check the echo. Each character you type should appear on the screen, because the ESP32 S3 Uno sends it back over RS422.
  5. Tip: If you see nothing, swap the A/B and Y/Z pairs on one side first. Mixed-up pairs are the most common RS422 mistake.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
Hello ESP32 S3 Uno RS422 test 123 Long cable OK
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

Video Tutorial

Watch the video below to see this ESP32 S3 Uno project step by step.

FAQ

Can the ESP32 S3 Uno use SoftwareSerial for RS422?

No. The SoftwareSerial library is made for AVR and some other boards, not for the ESP32 S3 Uno. You do not need it, because the board has extra hardware UARTs. Use Serial2.begin(9600, SERIAL_8N1, RX, TX) and pick the RX and TX pins you want.

Is the TTL to RS422 module safe with the 3.3V ESP32 S3 Uno?

Yes, if you take care of the voltage. ESP32 S3 Uno pins are not 5V tolerant. If the module runs on 5V, its TXD output is 5V. Power the module from 3.3V, or add a 5V to 3.3V level converter on the TXD line.

Why not use D0 and D1 for RS422 on the ESP32 S3 Uno?

You can, but D0 (GPIO44) and D1 (GPIO43) are the UART0 pins that also handle USB serial, uploading and boot messages. The RS422 module can block an upload, and the RS422 device may get boot text at power-up. Serial2 on D6 and D7 avoids these problems.

How far can RS422 send data with the ESP32 S3 Uno?

RS422 can reach about 1200 meters (4000 feet) at low baud rates like 9600. Higher baud rates mean shorter distances. Use twisted-pair cable for each A/B and Y/Z pair to get the best range.

What is the difference between RS422 and RS485?

RS422 uses two separate pairs, one to send and one to receive, so data can flow both ways at the same time (full duplex). It usually links one sender to up to 10 receivers. RS485 often uses a single pair shared by many devices, so it needs direction control in code.

What if my project needs more pins than the Uno headers give?

The ESP32 S3 Uno has two extra rows of holes with more GPIOs: GPIO15 and GPIO16 (I/O, PWM, analog), GPIO45 and GPIO35 to GPIO42 (I/O, PWM), and GPIO47/GPIO48 (output only, PWM). Solder pin headers to use them, and write the GPIO number in code. For an extra UART, GPIO35 to GPIO42 or GPIO15/GPIO16 are good choices; do not use GPIO47/GPIO48 for an RX pin, because they are output only. Two warnings: (1) GPIO47/GPIO48 may run at 1.8V instead of 3.3V on some modules (especially ones with "V" in the name, like R8V or R16V), so 3.3V devices can be damaged or act strangely; (2) GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code. Use the other extra pins first.

Troubleshooting

Problem Possible Cause Solution
No COM port in Arduino IDE USB driver missing or board not in upload mode Install the CP210x or CH340 driver, or hold BOOT while you press RESET
Upload fails with the Option 1 wiring The module is connected to D0 and D1, which are also the upload pins Unplug the TXD and RXD wires during upload, or use the Serial2 wiring on D6 and D7
Board does not boot with the Option 2 wiring The module pulls D6 (GPIO3), a boot strapping pin, at startup Unplug the TXD wire from D6, reset the board, then plug it back in
Nothing comes back in the terminal TX and RX pairs are crossed wrong, or TXD and RXD are swapped Connect Y/Z to the other device's A/B, and module RXD to the board TX pin
Strange characters in the terminal Baud rate or data format does not match Set the terminal to 9600 baud, 8N1, same as the code
Data works only on short cables Cable is not twisted pair or the line is too long for the baud rate Use twisted-pair cable and lower the baud rate
Board gets hot or resets randomly 5V signal from the module TXD goes into a 3.3V pin Power the module from 3.3V or add a level converter on TXD
Module LED is off No power or loose GND wire Check the VCC and GND wires and the power source

※ 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!