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.
Take it further
Put RS-232 to work: a QR reader checked by an Ardbox, a barcode scanner on a sorter and a power supply driven over a serial line.
Case study
Three checks against bad parts. One small Ardbox PLC.
One of the checks reads a QR code with a reader on the RS-232 port and compares it with the reference.
Read the case study
Simulator
Sort a picking wave on a conveyor
An M-Duino 42+ reads a barcode scanner on RS-232, follows each item with an encoder and fires four diverters into the lanes of the orders.
Open the simulator
PLC Solution Library
Driving a programmable power supply over SCPI from a PLC
A Raspberry PLC 19R drives a lab power supply over USB serial at 9600 baud with pyserial: setpoints, output switching and readback.
See the example