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:



G5 (RX) and G6 (TX).#include <M5Unified.h>
#include <M5GFX.h>
static int cnt;
void setup() {
M5.begin();
M5.Display.clear();
M5.Display.setFont(&fonts::FreeMonoBold9pt7b);
Serial.begin(115200);
// Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert)
Serial2.begin(115200, SERIAL_8N1, 5, 6);
M5.Display.drawCenterString("Press Screen", 64, 0);
M5.Display.drawCenterString("to send", 64, 15);
Serial.printf("Press screen to send\n");
}
void loop() {
M5.update();
if(M5.BtnA.wasClicked()){
Serial2.printf("RS485/232 Send #%d", ++cnt);
Serial.printf("RS485/232 Send #%d\n", cnt);
M5.Display.fillRect(0, 40, 128, 88, TFT_BLACK);
M5.Display.setCursor(5, 40);
M5.Display.printf("Send: #%d", cnt);
delay(20);
}
// When the RS485/232 interface is disconnected, executing the following code will result in garbled characters.
// while (Serial2.available()) {
// char ch = Serial2.read();
// Serial.write(ch);
// }
}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.
