Browse our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteria

Learning the basics about RS232 of an industrial PLC

Introduction

On 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 computer terminal and DCE as 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 to 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:

Configuring the switches

We have 2 families of PLCs: Mduino and Ardbox. 
On the Mduino 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 is some switches that we need to configure. 

 
A part from the switches, we have 3 jumpers insinde 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.



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 R

S-485 it is also the same for the RS-232.


A part from the switches, we have 2 jumpers insinde the PLC.  Available communications protocol and connections using this 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

First thing we need to do is make sure that 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

First step is downloading the  Arduino based PLC boardsfor 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 including the library RS232.h  founded in our website. After this, in the function setup, take care to do the right implementation of your communication.

For all Industrial Shields PLC family ranges:

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);

  }   

   }

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


 
 

Do you want more information?

Open Source technology allows you to develop your installations.

Just fill the form and we will contact you as soon as we can.

Send