Index
Introdution
In this post, we are going to explain how to do the basics in order to work with RS-232 communication of Industrial Shields' programmable logic controllers. Reading this post, you will be able to understand how to connect and configure the RS-232 of your industrial Arduino PLC controller.
RS-232 protocol defines the signals that are connected between DTE as a computer terminal and DCE as a modem. Our PLCs have inside the integrated circuit MAX232 that can convert the signals of a series port TIA-232 to proper signals that can be used in digital logic circuits compatible with TTL.
The integrated circuit, MAX232, has outputs that can work with the voltage levels of RS-232, which are produced from the voltage supply of 5V using voltage multipliers in association with external capacitors.Â
Previous reading
We recommend you read the following posts in order to understand the programming of this blog. We used the following blog post to do this example:
- How to program our industrial PLC with Arduino IDE:Â Installing the Industrial Shields's boards in the Arduino IDE >>>
Requirements
In order to work with RS-232 protocol, you will need any of our industrial controllers for industrial automation:
Industrial Shields controllers:
Configuring the switches
On the M-Duino family, you will always have activated the RS-232 as a default, so you will not need to activate it using any switch.For the Ardbox Analog family, there are some switches that we need to configure.Â
- Hardware Serial RS-232.
- I2C * If I2C is active, I0.0 & I0.6 are disabled.
- SPI
- TTL
- USB
- Inputs: 8 of 10 inputs, I0.0, I0.1 & I0.4 to I0.9. * If using I2C, I0.0 is also disabled.
- Digital outputs: All 10 Outputs. * If using I2C, Q0.6 is disabled.
- Analog Outputs: From A0.0 to A0.6. * If using I2C A0.6 is disabled.
The last case is Ardbox Relay family, with the following switches:
Note: In order to enable the RS-232 protocol, the TOP ZONE must be configured as it is shown in the table. Although the switch name only is referenced to RS-485 it is also the same for the RS-232.
Apart from the switches, we have 2 jumpers inside the PLC. Available communications protocol and connections using these jumpers configurations:
- Hardware Serial RS-232.
- I2C * If I2C is active, I0.0 & I0.6 are disabled.
- SPI
- TTL
- USB
- Inputs: All 10 inputs, I0.0 to I0.9. * If using I2C, I0.0 is disabled.
- Relay Outputs: From R1 to R6. * If using I2C, R5 is disabled. R7 & R8 are disabled from the TOP ZONE Switch.
- Analog Outputs: A0.0 & A0.1
Hardware
The first thing we need to do is make sure that the PLC is supplied with 12-24Vdc.
To make the connection, in both families, we use the pins RX and TX in this way:
1st PLCÂ Â Â Â Â Â 2nd PLC
TX------------------RXÂ Â Â Â Â Â (RS232)
RX------------------TXÂ Â Â Â Â Â (RS232)
Software
For all Industrial Shields PLC family ranges:
A basic example of writing in the RS-232:Â
// Include Industrial Shields libraries
#include <RS232.h>
//// IMPORTANT: check switches configuration
//////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
 // Begin serial port
    Serial.begin(9600);
 // Begin RS232 port
 RS232.begin(38400);
}
///////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
 // Wait bytes in the serial port
 if (Serial.available()) {
   byte tx = Serial.read();
   // Echo the byte to the serial port again
   Serial.write(tx);
   // And send it to the RS-232 port
   RS232.write(tx);
 } Â
  }
A basic example of reading of the RS-232 Â
// Include Industrial Shields libraries
#include <RS232.h>
//// IMPORTANT: check switches configuration
//////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
 // Begin serial port
    Serial.begin(9600);
 // Begin RS232 port
 RS232.begin(38400);
}
//////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
 // Print received byte when available
 if (RS232.available()) {
   byte rx = RS232.read();
   // Hexadecimal representation
   Serial.print("HEX: ");
   Serial.print(rx, HEX);
   // Decimal representation
   Serial.print(", DEC: ");
   Serial.println(rx, DEC);
 }Â
}Â
Basics about RS232 of an industrial PLC