ESP32 S3 UNO RS485

This ESP32 S3 Uno RS485 tutorial shows you how to connect a TTL to RS485 module to the ESP32 S3 Uno form board and exchange data over a long RS-485 line. You will write Arduino code that receives bytes from an RS485 device and sends them back, then check the result from your PC with a USB to RS485 converter.

In this tutorial, you will:

  1. Wire a TTL to RS485 module to the ESP32 S3 Uno
  2. Receive data from an RS-485 device with the hardware serial port
  3. Send data to an RS-485 device with Serial.print() style functions
  4. Use a second UART on other pins instead of SoftwareSerial
  5. Test RS485 communication between your PC and the board
ESP32 S3 Uno RS485

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 RS485 Module
1×Alternatively, MAX485 RS485 to TTL Module (NOT soldered)
1×Alternatively, MAX485 RS485 to TTL Module *(soldered)
1×Jumper Wires
1×5V to 3.3V Level Converter (for the TXD signal, if the module runs at 5V)
1×Optionally, USB to RS485 Converter
1×Optionally, USB to RS485 Cable

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 RS485 Module

The UART pins of the ESP32 S3 Uno (TX and RX) work at TTL level. That is fine for a few centimeters of wire, but the signal gets weak and noisy over a long cable. To send serial data far away, you change the TTL signal into a stronger standard such as RS232, RS485 or RS422.

RS485 sends each bit as a difference between two wires, so it resists noise very well. It can run over cables up to about 1200 meters, and many devices can share the same bus. A TTL to RS485 module does the conversion for you, in both directions. Your code still uses normal serial functions like read() and print().

Pinout

The module has two sides. One side talks to the ESP32 S3 Uno, and the other side goes to the RS485 bus.

TTL Interface (to the ESP32 S3 Uno)

Pin Description
VCC Power input. Connect to 5V or 3.3V, depending on your module
GND Ground (0V)
RXD Data input of the module. Connect to a TX pin of the ESP32 S3 Uno
TXD Data output of the module. Connect to an RX pin of the ESP32 S3 Uno

RS485 Interface (to the RS485 bus)

Pin Description
D+ (A or TR+) Positive line of the differential data pair
D- (B or TR-) Negative line of the differential data pair
GND Optional, but recommended. It gives both devices the same reference and cuts noise
RS-485 module Pinout
image source: diyables.io

ESP32 S3 Uno Pinout

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

ESP32 S3 Uno pinout diagram

Wiring Diagram

There are two ways to wire the module. Pick the one that matches the sketch you plan to upload.

Option 1: D0 and D1 (Serial1 code)

The wiring diagram between ESP32 S3 Uno TTL to RS485

This image is created using Fritzing. Click to enlarge image

TTL to RS485 Module 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 wired to the on-board USB-serial chip, and the board prints boot messages on D1 at every reset. Unplug the TXD and RXD wires while you upload code, and expect a few strange bytes on the RS485 bus when the board starts. If this causes trouble, use Option 2.

Option 2: D6 and D7 (Serial2 code)

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

This image is created using Fritzing. Click to enlarge image

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

WARNING

D6 is GPIO3, a boot strapping pin of the ESP32 S3 Uno. The board reads it at startup. On most boards this is not a problem, because the module keeps TXD high when idle. If the board does not boot or upload correctly, unplug the TXD wire from D6, upload or reset, then plug it back in.

WARNING

The ESP32 S3 Uno pins are NOT 5V tolerant. When the module is powered from 5V, its TXD pin sends 5V signals into the RX pin (D0 or D6). Fix this in one of two ways: power the module from 3.3V if it supports 3.3V (for example MAX3485 based modules), or put a 5V to 3.3V level converter on the TXD line. The RXD line is safe, because the 3.3V output of the ESP32 S3 Uno is read as HIGH by a 5V module.

How To Program ESP32 S3 Uno to use the RS485 module

The module turns RS485 into plain UART, so the code is just serial code. The only thing to watch is which serial port you use. On the ESP32 S3 Uno, Serial is the link to your computer, so the RS485 module gets its own port: Serial1 or Serial2. The ESP32 S3 Uno lets you put these ports on almost any GPIO.

Start the serial port

For the D0/D1 wiring, start Serial1 and give it the RX and TX GPIO numbers:

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

No SoftwareSerial? Use Serial2

The SoftwareSerial library does not exist for the ESP32 S3 Uno. You do not need it. The board has spare hardware UARTs, so you start Serial2 on the same D6/D7 positions instead:

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

Read data from RS485

These functions read data that comes in from the bus. They work the same on Serial1 and Serial2:

Send data to RS485

These functions send data out to the bus:

You can find more functions in the Serial reference.

ESP32 S3 Uno Code for Hardware Serial

This sketch is for the D0/D1 wiring. It starts Serial1 at 9600 baud on GPIO44 (RX) and GPIO43 (TX). Every character that arrives from the RS485 bus is sent straight back, so the sketch works as a simple echo test.

/* * 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-rs485 */ #define RS485_RX_PIN 44 // ESP32 S3 Uno pin D0 (GPIO44) connected to TXD of the RS485 module #define RS485_TX_PIN 43 // ESP32 S3 Uno pin D1 (GPIO43) connected to RXD of the RS485 module void setup() { // start communication with baud rate 9600 on hardware serial port 1 Serial1.begin(9600, SERIAL_8N1, RS485_RX_PIN, RS485_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 Software Serial

This sketch is for the D6/D7 wiring. It replaces SoftwareSerial with the hardware port Serial2, mapped to GPIO3 (RX) and GPIO14 (TX). The echo logic is the same as the first sketch, and it is more reliable than a software UART because the hardware handles the timing.

/* * 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-rs485 */ // The ESP32 S3 Uno has no SoftwareSerial. It uses the hardware serial port 2 on any pins instead #define RS485_RX_PIN 3 // ESP32 S3 Uno pin D6 (GPIO3) connected to TXD of the RS485 module #define RS485_TX_PIN 14 // ESP32 S3 Uno pin D7 (GPIO14) connected to RXD of the RS485 module void setup() { // start communication with baud rate 9600 on hardware serial port 2 Serial2.begin(9600, SERIAL_8N1, RS485_RX_PIN, RS485_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

First, upload the sketch to the board. Then check the link from your PC with a USB to RS485 converter and a serial terminal program.

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 that matches your sketch.
  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 and paste it into the Arduino IDE.
  6. Upload the code by clicking the Upload button. With the D0/D1 wiring, unplug the TXD and RXD wires first, and plug them back in after the upload.

Test with your PC

  1. Connect the RS485 side of the module to your PC with a USB to RS485 cable, as shown below.
ESP32 S3 Uno RS485 to PC communication
  1. Install a serial terminal, such as Tera Term or PuTTY.
  2. Open the terminal and set the COM port of the USB to RS485 cable, 9600 baud, 8 data bits, no parity, 1 stop bit.
  3. Type some text in the terminal. The ESP32 S3 Uno receives it over RS485.
  4. Check the echo. Each character you type comes back and shows in the terminal.
  5. Tip: If nothing comes back, swap the D+ and D- wires. Mixed-up A/B lines are the most common RS485 mistake.

Video Tutorial

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

FAQ

Can I use SoftwareSerial for RS485 on the ESP32 S3 Uno?

No, the SoftwareSerial library is not part of the Arduino core for this board. You do not need it, because the ESP32 S3 Uno has extra hardware UARTs. Start Serial1 or Serial2 with begin(baud, SERIAL_8N1, RX, TX) and pick the GPIO numbers you want.

Why does the code use Serial1 instead of Serial on D0 and D1?

On the ESP32 S3 Uno, Serial is used for upload and the Serial Monitor through the USB port. The sketch maps Serial1 to GPIO44 and GPIO43 (D0 and D1) to talk to the RS485 module. Because these pins are shared with the USB-serial chip, unplug the module wires while uploading, or use the D6/D7 wiring with Serial2.

Can I power the RS485 module from 5V with the ESP32 S3 Uno?

Yes, but the module's TXD output will then be 5V, and the ESP32 S3 Uno pins are not 5V tolerant. Add a 5V to 3.3V level converter on the TXD line, or power the module from 3.3V if it is rated for 3.3V. Modules based on the MAX3485 work at 3.3V, while MAX13487 based modules need 5V.

How long can my RS485 cable be?

RS485 can work up to about 1200 meters at low baud rates such as 9600. Use twisted pair cable for D+ and D-, connect GND between devices, and add a 120 ohm terminator at each end of a long bus.

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 a second RS485 port, GPIO35 to GPIO42 are good choices, because a UART can be mapped to them; do not use GPIO47/GPIO48 for RX, since they are output only. Be careful with two things. First, GPIO47 and 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. Second, 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.

Can I connect more than one device to the same RS485 bus?

Yes. RS485 supports up to 32 standard devices on one pair of wires. This simple module has no direction control pin, so it is best for point-to-point links. For a multi-device bus, use a protocol like Modbus where only one device talks at a time.

Troubleshooting

Problem Possible Cause Solution
No COM port in Arduino IDE USB driver missing or board not in boot mode Install the CP210x or CH340 driver, try another cable, or hold BOOT while pressing RESET
Upload fails with the D0/D1 wiring The module drives GPIO44 and fights the USB-serial chip Unplug the TXD and RXD wires during upload, then plug them back in
Board does not boot with the D6/D7 wiring GPIO3 (D6) is a strapping pin and is pulled the wrong way at startup Unplug the TXD wire from D6, reset the board, then reconnect it
No echo in the terminal D+ and D- are swapped or TXD/RXD are swapped Swap D+ and D-, and check that TXD goes to the RX pin and RXD to the TX pin
Garbage characters in the terminal Baud rate or frame settings do not match Set the terminal to 9600 baud, 8 data bits, no parity, 1 stop bit
Strange bytes after every reset Boot messages go out on D1 (GPIO43) Use the D6/D7 wiring with Serial2, or ignore the first bytes after reset
Module LED off Module has no power or GND is missing Check the VCC and GND wires and the supply voltage the module needs
RX pin gets hot or acts strangely 5V signal from TXD into a 3.3V pin Add a 5V to 3.3V level converter on TXD, or power the module from 3.3V if it allows it

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