Arduino Nano 33 IoT - RS485

This guide shows you how to use RS485 communication with the Arduino Nano 33 IoT. We will learn about these topics:

Arduino Nano 33 IoT TTL to RS485

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×TTL to RS485 Module
1×Jumper Wires
1×Optionally, USB to RS485 Converter
1×Optionally, USB to RS485 Cable
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter 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 RS485 Module

When using serial communication on the Arduino Nano 33 IoT with commands like Serial.print(), Serial.read(), and Serial.write(), the data is sent out through the TX pin and received through the RX pin. These pins work at a basic voltage level (TTL) with a limited range. So, if you want to communicate over long distances, you need to change the TTL signal into other standards like RS232, RS485, or RS422.

In this guide, we will learn how to use RS485 (also known as RS-485) with the Arduino Nano 33 IoT using a TTL to RS485 module. This module changes TTL signals into RS485 signals and back, which makes it easier to communicate over long distances.

Pinout

The RS485 to TTL module has two ports.

  • TTL Interface (connected to Arduino Nano 33 IoT):
    • VCC Pin: Connect this power pin to VCC (5V or 3.3V).
    • GND Pin: Connect this power pin to GND (0V).
    • RXD Pin: Connect this data pin to the TX pin on the Arduino Nano 33 IoT.
    • TXD Pin: Connect this data pin to the RX pin on the Arduino Nano 33 IoT.
  • RS485 Interface:
    • D+ (A or TR+) Pin: This pin is used for sending and receiving data.
    • D- (B or TR-) Pin: This pin is used for data transmission.
    • GND Pin: This ground pin is optional, but it is best to use it to reduce noise and improve performance.
    RS-485 module Pinout
    image source: diyables.io

Wiring Diagram

The wiring diagram between Arduino Nano and 33 IoT TTL to RS485

This image is created using Fritzing. Click to enlarge image

How To Program Arduino Nano 33 IoT to use the RS485 module

  • Set up the pins for serial communication:
#define RX1PIN D2 #define TX1PIN D3
  • Sets up the Serial connection:
Serial1.begin(9600, SERIAL_8N1, RX1PIN, TX1PIN); // Initialize RS232 serial communication
  • To read data from RS485, you can use these functions:
  • Serial.read() (see https://arduinogetstarted.com/reference/serial-read)
  • Serial.readBytes() (see https://arduinogetstarted.com/reference/serial-readbytes)
  • Serial.readBytesUntil() (see https://arduinogetstarted.com/reference/serial-readbytesuntil)
  • Serial.readString() (see https://arduinogetstarted.com/reference/serial-readstring)
  • Serial.readStringUntil() (see https://arduinogetstarted.com/reference/serial-readstringuntil)
  • To write data to RS485, you can use these functions:
  • Serial.print() (see https://arduinogetstarted.com/reference/serial-print)
  • Serial.println() (see https://arduinogetstarted.com/reference/serial-println)
  • Serial.write() (see https://arduinogetstarted.com/reference/serial-write)
  • You can also find more RS485 functions in the Serial reference at https://arduinogetstarted.com/reference/arduino-serial

Arduino Nano 33 IoT Code

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-rs485 */ #define RX1PIN 2 #define TX1PIN 3 void setup() { // start communication with baud rate 9600 Serial.begin(9600); // Serial Monitor Serial1.begin(9600, SERIAL_8N1, RX1PIN, TX1PIN); // RS485 // 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 try a test by sending information from your computer to the Arduino Nano 33 IoT using RS-485 and then back again. Follow these steps:

  • Connect the Arduino Nano 33 IoT to your computer using an RS485-to-USB cable as shown below.
Arduino Nano 33 IoT RS485 to PC communication
  • Download and install a serial terminal program such as Tera Term or PuTTY.
  • Open the terminal program and set up the serial connection details (like COM port and baud rate).
  • Type some text in the terminal to send it to the Arduino Nano 33 IoT.
  • If it works, you will see the same text appear back on the 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!