Environment Configuration: Refer to the Arduino IDE Quick Start Tutorial to complete the IDE installation, and install the corresponding board management for the development board you are using, as well as the required driver libraries.
Driver libraries used:
Hardware products used:



1. Core Definition:
2. Key Features:
3. Working Principle:
1. Core Definition:
2. Key Features:
3. Working Principle:
In this tutorial, the main control device used is AtomS3R, paired with the Atomic RS485/232 Base. This module communicates via Serial. Modify the pin definitions in the program according to the actual circuit connection. After the device is connected, the corresponding serial pins are G5 (RX) and G6 (TX).
Atomic RS485 Base does not have an integrated 120Ω terminal resistor inside. You can refer to the position in the diagram below to add a 120Ω resistor between the A/B lines.
#include <M5Unified.h>
#include <M5GFX.h>
static int cnt = 0; // Counter for RS485 sent messages (increments per transmission)
String recvBuffer; // Buffer to store received RS485 data
void setup() {
M5.begin();
M5.Display.clear();
M5.Display.setFont(&fonts::FreeMonoBold9pt7b);
M5.Display.drawString("Send :", 0, 5);
M5.Display.drawString("Receive :", 0, 50);
Serial.begin(115200);
// Parameters: baud rate=115200, config=8N1 (8 data bits, 1 stop bit, no parity), RX pin=27, TX pin=19
Serial2.begin(115200, SERIAL_8N1, 5, 6);
}
void loop() {
M5.update();
// --- Send Data ---
String msg = "RS485 #" + String(++cnt);
Serial2.println(msg);
Serial.printf("Send: %s\n", msg.c_str());
// Display sent message on screen
M5.Display.fillRect(0, 25, 128, 20, TFT_BLACK);
M5.Display.setTextColor(GREEN);
M5.Display.setCursor(0, 25);
M5.Display.printf("%s\n", msg.c_str());
// --- Receive Data ---
recvBuffer = "";
while (Serial2.available()) {
char ch = Serial2.read();
recvBuffer += ch;
}
// If valid data is received
if (recvBuffer.length() > 0) {
Serial.print("Recv: ");
Serial.print(recvBuffer);
Serial2.flush();
// Display received message on screen
M5.Display.setTextColor(YELLOW);
M5.Display.fillRect(0, 70, 128, 20, TFT_BLACK);
M5.Display.setCursor(0, 70);
M5.Display.printf("%s", recvBuffer.c_str());
}
delay(2000);
}1. Download Mode: Before flashing the program on different devices, you need to enter download mode. This step may vary depending on the main control device. For details, refer to the list of device program download tutorials at the bottom of the Arduino IDE Quick Start Tutorial page to see the specific operation method.
For AtomS3R, press and hold the reset button (for about 2 seconds) until the internal green LED lights up, then release. At this point, the device has entered download mode and is ready for flashing.
