INTEGRATING ARDUINO INTO PLC SYSTEM

by tuenhidiy in Circuits > Arduino

28734 Views, 48 Favorites, 0 Comments

INTEGRATING ARDUINO INTO PLC SYSTEM

TEMPERATURE.jpg
TITLE_1.jpg

I intend to make an automated system for my home with a combination of PLC SIEMENS and ARDUINO. I think we can combine their own strengths to make the automation system running in stability, optimization and acceptable price. So I took times to consult, study and perform some below experiments before applying them to my home.

  • Toogle a lamp 220 VAC from touch button of Arduino via Profibus-DP.

  • Display the PT100 temperature value on the 64x64 led matrix via Profibus-DP

PARTS LIST

Main component includes:

A. Testing 1: Toogle a lamp 220 VAC from the touch button of Arduino:

B. Testing 2: Display the PT100 temperature value on RGB led matrix 64x64, we need some more components as follow:

SOFTWARES AND MANUALS

I. SOFTWARES:

II. REFERENCE MANUALS:

QUICKVIEW OF PROFIBUS-DP NETWORK

The PROFIBUS DP network is based on an RS485 physical communication and it has to strictly follow the telegram format structure and telegram sequences defined by PROFIBUS network. And RS485 designs use the same basic UART but it convert the UART signal into a bi-directional differential signal. RS 485 transmission technology uses two-cores cable, with positive red core B+ and negative green core A-. The benefit of using a differential signal to minimize noises and allowing for longer cable lengths, up to 1.2 km. It allows for fast data communications up to a bit rate of 12 Mbit/s.

UART CODING AND FRAME FORMAT

PROFIBUS-DP TELEGRAM FORMATS

Each byte in a telegram is transferred as 11 bits (START = 0 ; DATA = 8 BIT ; PARITY = EVEN ; STOP = 1), see FRAME FORMAT picture above.

TBIT: DURATION OF ONE BIT

On PROFIBUS-DP, certain time ratios must be respected to ensure that a telegram sequence can function correctly.

The duration of a bit differs depending on bit rate: for 12 MBit/s tBit = 83 ns and for 1.5 MBit/s tBit = 0.67 µs.

We should study more information about Profibus at following link:

https://www.felser.ch/profibus-manual/index.html

CONNECTIONS

I. PLC connection:

II. Arduino connection:

III. Testing description:

The 220VAC lamp can be controlled in toogle mode by virtual and physical input as follows:

  • Touch button is connected to Arduino plus RS485 shield and send the command to PLC S7-300 via Profibus-DP network at Virtual Input I0.0
  • Inductive sensor is connected to PLC S7-300 directly at Physical Input I124.0
  • 24VDC relay coil is connected to PLC Physical Output Q124.0 and lamp 220VAC is connected to N.O (normal open) contact of this relay. Even though the lamp is controlled by Arduino or PLC, Arduino receive the feedback of lamp status from PLC at virtual output Q0.0 and display lamp status by red led (lamp 220VAC off) /green led (lamp 220VAC on) on touch button.

We can see more detail in "PLC PROGRAMING" step.

PLC HARDWARE CONFIGURATION

PLC hardware configuration is as picture below and we need to do the following steps:

In Simatic Step 7 program (HW CONFIG), we have to install ARDUINO *.GSD file and update your Hardware Catalog using the menu command "Options --> Update catalog". You can check detail at this link to know how to integrate a GSD file into the STEP 7 HW Config for PROFIBUS.

The GSD file is an electronic device datasheet or device database file that identifies the Profibus device. All Profibus devices (class 1 masters and slaves) have their own GSD files. GSD stands for "General Station Description". It is an ASCII text file that contains device-specific data, such as, vendor identification information, supported baud rates, supported message length, number of input/output data, meaning of diagnostic messages, timing information, plus options and features supported, data formats, and available I/O signals.

With Arduino - F_CPU = 16MHz, Profibus network works well at baudrate 45.45 Kbps.

We need to define the number of bytes transmitted and received over the Profibus connection, we can see this setup on above picture:

- 1 Byte Input: PLC receive 1 byte input at virtual input address IB0.

- 1 Byte Output: PLC transmit 1 byte output at virtual output address QB0.

PLC PROGRAMING

It is simple PLC program with:

  • OB1 - Main program.
  • DB1 - Data Block for storage toogle state of LAMP (at DB1.DBX0.0).
  • FB1 - Function Block for carrying out toggle function. It toggles the output Q state with every rising edge of clock (CLK).
  • DB2 - Instant Data Block for FB1.

Program explanation:

  • I0.0 - PLC Virtual Input which is received from Touch Button of Arduino via Profibus-DP.
  • I124.0 - PLC Physical Input which is directly connected to Inductive Sensor.
  • Q124.0 - PLC Physical Output which is connected to coil relay 24VDC.
  • PQB0 - PLC Virtual Output Byte (8bit) which is transmitted to Arduino via Profibus-DP.

"TOOGLE" Function Block FB1 written in SCL (Structured Control Language) can be copied to S7 program/ Sources folder and compiled to LAD/STL. This Function Block toggles the output Q state when it detects every rising edge of clock (CLK). We can see in program, "TOOGLE" function block will toogle Q124.0 when it detects one rising edge pulse at virtual input I0.0 or physical input I124.0

FUNCTION_BLOCK TOGGLE
TITLE = 'TOGGLE'
VAR_INPUT
  CLK : BOOL;
  RST : BOOL;
END_VAR
VAR_OUTPUT
  Q : BOOL;
END_VAR
VAR
  EDGE : BOOL;
END_VAR
BEGIN
IF RST THEN
  Q := 0;
ELSIF CLK AND NOT EDGE THEN
  Q := NOT Q;
END_IF;
EDGE := CLK;
END_FUNCTION_BLOCK

ARDUINO PROGRAMING

The Arduino code including *.GSD file for PLC Hardware Configuration is available at my GitHub.

My program is referenced from German mikrocontroller website by Jörg S., Marc H., Johannes F. and originally it is written for MSP430F2252. If you are German I believe you will collect a lot of information here.

https://www.mikrocontroller.net/topic/106174

For RS485 Shield designed by DFROBOT, it is useful when it is equipped with additional button "Operation and programming mode switch" because Arduino Uno has only 1 UART port for programming and RS485 communication.

  • Switch to OFF: you can download the program for the Arduino controller.
  • Switch to ON: the shield will convert the UART to the RS485.

Important note:

  • The Profibus-DP based on RS485 physical communication has two independent lines known as negative line - A and positive line - B, which transmit similar voltage levels however with opposite polarities. For this reason, it is important that the network is connected with the correct polarity. As my testings with some RS485 modules, in order to correct their polarities, I had to swap 2 cores A and B of Profibus cable together for most RS485 modules at Arduino-side.
  • In order for network working properly, the GND of PLC and the GND of Arduino must be connected together.

DISPLAY PT100 VALUE ON LED MATRIX 64X64

I. TESTING DESCRIPTION:

  • PT100 is connected to 2AI RTD analog module at Remote I/O station, Profibus - DP address: 4.
  • Led matrix module including: Led matrix 64x64 + Arduino Mega 2560 + DIY Profibus Shield, is connected to Profibus network at address: 6.
  • PLC read the temperature from Remote I/O station Profibus Address 6 and then send this value to led matrix module (Profibus Address - 6).

II. SOLDERING A PROFIBUS SHIELD

  • This shield not only handles the Profibus-DP communication, but also controls 64x64 led matrix. You can refer to this GitHub to know how Arduino Mega 2560 can control the led matrix 64x64. This shield includes the following components:

- 01pcs x MAX485 IC

- 01pcs x Decoupling capacitor 0.1uF.

- 03pcs x Pull-up resistor 10K.

- 01pcs x Indication led 5mm and its current limiting resistor.

- 01pcs x DB9 female for Profibus connection.

- 01pcs x 2.45mm 2x8P double row female header, connecting to led matrix PO male header

- 01pcs x Ribbon cable 16P with 2x8P double row female header at 2 sides. It is used for connecting from this shield to led matrix PI male header.

  • Profibus shield - Top View

  • Profibus shield - Bottom View

  • Plugging this shield to Arduino Mega 2560 and then connecting to led matrix 64x64.

III. PLC AND ARDUINO PROGRAMING

2AI RTD module read temperature from PT100 and store in data block (ex: DB1) in real format (Floating-Point Numbers) with 32 bit. Then this 4 bytes real number will be transmitted to Arduino, for example at virtual output PQB0 ~ PQB3.

Take note that PLC SIEMENS S7 ™ use "Big-Endian" data format and ARDUINO™ use "Little-Endian" data format. The terms "Big-Endian" and "Little-Endian" to describe differences in reading and writing data:

  • Big –Endian: MSB (left-most bit) --> LSB (right-most bit), for example, DWORD 0x4C21112F is stored in PLC Siemens S7 ™ as follows:


  • Little Endian: LSB (left-most bit) --> MSB (right-most bit), with same DWORD above but ARDUINO ™ will store in the opposite way DWORD 0x2F11214C

Arduino receive 4 bytes temperature in REAL, BIG-ENDIAN format, for example it is stored at { Profibus_in_register[0] ~ Profibus_in_register[3] }. It need to be processed and converted to FLOAT, LITTE-ENDIAN in Arduino as following tip:

byte Temperature[4];
float Corrected_Value;
Temperature[3] = Profibus_in_register[0];   // swap order, 32-bit Big-Endian float
Temperature[2] = Profibus_in_register[1];	
Temperature[1] = Profibus_in_register[2];
Temperature[0] = Profibus_in_register[3];
float *floatTemp= (float *)Temperature; // format the buffer as a float
Corrected_Value= *floatTemp;		// value in 32-bit Little-Endian float

Picture for testing result:

FINISH

TITLE_4.jpg
TITLE_2.jpg
MATRIX.jpg
TITLE_3.jpg

I have previously posted some projects related to communication between PLC and Arduino on this Instructables site, such as:

https://www.instructables.com/id/Profibus-DP-Commu...

https://www.instructables.com/id/ARDUINO-HACK-PLC-...

https://www.instructables.com/id/WIFI-JOYSTICK/

I hope these projects will inspire the students who don't have much money, to come up with ideas for combining electronic and automation fields together, with low price. Hope you enjoyed my post this time. Thank for your watching!

Please LIKE and SUBSCRIBE to my YouTube channel.