pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

Atomic RS485/232 Base Arduino Tutorial

1. Preparation

2. Example

  • 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).
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#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);
    // }
}

3. Compile and Upload

  • 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.

  • 2. Select the device port, click the Compile and Upload button in the upper left of Arduino IDE, and wait for the program to complete compilation and upload to the device.

4. Example Effect Demonstration

  • After successfully downloading the above example and powering on the device, pressing the screen once will send a message to the RS485/232 interface and receive feedback on the PC side. The main controller screen will display as shown below.
On This Page