Basics about RS232 of an industrial PLC

RS232 of an industrial PLC controller for industrial automation
March 5, 2020 by
Basics about RS232 of an industrial PLC
Boot & Work Corp. S.L., David Martin

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:

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


We have 2 families of PLCs: M-Duino and Ardbox. 
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.
 

Configuring the switches - Basics about RS232 
Apart from the switches, we have 3 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: 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.
Configuring the switches - Basics about RS232

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.

Configuring the switches - Basics about RS232

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

Configuring the switches - Basics about RS232


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

The first step is downloading the  Arduino based PLC boards for Arduino IDE.
After making the hardware configuration, we need to continue with the software configuration and also how we use it. To begin this process, it is necessary to include the library RS232.h  founded on our website. After this, in the function set up, take care to do the right implementation of your communication.

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: Implementation of RS-232 protocol

 
 

​Search in our Blog

Basics about RS232 of an industrial PLC
Boot & Work Corp. S.L., David Martin March 5, 2020

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>