Introduction
RS-232 is a widely used communication protocol for serial data exchange between devices, offering simplicity and reliability in industrial applications. Industrial Shields PLC families, including the ESP32 PLC, M-Duino PLC, and Ardbox PLC, support RS-232 communication, making them versatile tools for automation projects.
This guide walks you through the hardware and software setup required to enable RS-232 communication with these PLCs. From configuring switches to establishing proper connections and writing your first lines of code, this tutorial ensures you can effectively utilize RS-232 in your projects.
Additionally, we provide examples to help you quickly start using RS-232 communication, whether you're sending, receiving, or monitoring data. For further details, explore the technical features of ESP32 PLC Family, M-Duino PLC Family and Ardbox PLC Family.
Hardware
Switch configurations
To use the RS-232 communication, configure the communications switch as follows:
- For ESP32 PLC Family:
- Set switch 2 of A zone to OFF
- For M-Duino PLC Family:
- No switch configurations needed
- For Ardbox PLC Family:
- Select RS on Top zone switch
- Select RS on Top zone switch
Connections
The connections between devices are GND with GND, TX with RX and RX with TX.
Software
Install the industrialshields-avr board on the Arduino IDE. You can do it by following this tutorial.
Select your board and model:
- For M-Duino PLC Family: Tools > Board > Industrial Shields AVR Boards > M-Duino [Extension] family and Tools > Model > M-Duino [Module]
- For Ardbox PLC Family: Tools > Board > Industrial Shields AVR Boards > Ardbox [Extension] family and Tools > Model > Ardbox [Module] HF+ w/HW RS-485
- For ESP32 PLC Family: Tools > Board > Industrial Shields ESP32 Boards > ESP32 PLC Family and Tools > Model > ESP32 PLC [Module]
Include the RS232 library in your code and use RS232 to refer to the RS-232 port.
Make sure that the baudrate is the same in the all the devices.
Some basic functions
1. Begin RS232 port:
RS232.begin(BAUDRATE);
2. Send data:
RS232.write(tx);
3. Check if data is available to read and read the data
if (RS232.available()) {
byte rx = RS232.read();
}
Check out the examples on Arduino IDE at Examples > RS-232.