How to connect Arduino based PLC with Siemens S7 PLC family equipped through Ethernet

December 10, 2018 by
How to connect Arduino based PLC with Siemens S7 PLC family equipped through Ethernet
Alejandro Jabalquinto

Introduction

This post it is showed how to connect Industrial Shields Arduino based PLC (M-Duinoā€˜s) with a SiemensĀ© PLC equipped with an Ethernet port or communication processor. Any PLC is supported except for the old S5Ā© family. To do that we have to useĀ Settimino.Ā SettiminoĀ is an open-source Ethernet library for interfacing Arduino with SiemensĀ© S7 PLCā€™s. CPUā€™s 1200/1500 LOGO 0BA7 and S7200 are also supported.
Download following this linkĀ Settimino.

Requirements

Ethernet PLC:

MDuino Family Products
Ethernet2 Library:Arduino Ethernet2.h library
SiemensĀ© PLC with Ethernet connection


Methodology

Once we have all the requirements, we can proceed to explain how it works. The main class is the S7Client object that is able to connect and transfer data between Arduino based PLC and SiementsĀ© PLC. Ethernet W5100 chip support 4 clients andĀ uses one data buffer for the entire client because just one can be connected at the same time. This data buffer can contain just one PDU (see the SiemensĀ© communication to know what that means).

The PDU variable is global, which means that is visible from the sketch. See an example (consult the syntax of the S7Client to get a better understanding).

This is the PDU defined on Settimino.h:

typedef struct {
   byte H [ Size_WR ];                      Header PDU //
   byte Data [ Shift + MaxPduSize-Size_WR ];  // Data PDU
TPDU};
TPDU PDU; // Declaration

The H matrix contains the protocol header and the Data matrix contains the payload.

Transferring big data:

byte mybuffer [1024]; // 1K matrix
Cliente.ReadArea(S7AreaDB , 24, 0, 1024, y mybuffer);

We are saying that the client can access database 24, to read from 0 to 1024 bytes y handle into mybuffer.

Transferring small data:

Cliente.ReadArea(S7AreaDB, 24, 0, 64, NULL);
Serial.printlnĀ (PDU.DATA [0]);Ā // Printing the first byte
Serial.printlnĀ (PDU.DATA [1]);Ā // Printing the second byte and so on ...

We are saying that the client can access the database 24, read 64 bytes from 0 to 64 and handle it into the internal buffer.

To write we have to do it, in the same way, putting data to PDU.DATA[] and then call WriteArea().

S7Helper

The SiemensĀ© data is Big-endian and the Arduino data is Little-endian. S7Helper is an object that allows extracting values right to left with an intermediate format memory bytes. The name of the request is S7.

Supposing that we want to load this database:

AddressNameTypeInitial valueComment
0.0Ā StructĀ Ā 
+0.0PRESSUREREAL0.00000e+000TRANSDUCER TP1
+4.0ENCODERDWORDDWs16s0MOTOR ENCODER
+8.0COMP_NUMBERINT0COMPONENT NUMBER
=10.0Ā END_STRUCTĀ Ā 

Ā 

flotar pressure;
unsigned long Encoder;
int16_t components;
// getting 10 bytes from 0
Client.ReadArea(S7AreaDB , 100, 0, 10, y mybuffer);

My buffer will contain a serial disorder of bytes.

To access these fills we can write:

Pressure = S7.FloatAt (y mybuffer , 0);
Encoder = S7.DWordAt (y mybuffer , 4);
Componeny = S7.IntegerAt (y mybuffer , 8);

Models Memory

To optimize even more the print, tree memory models are available: small, normal and extended.

Even though the extended model works perfectly on Arduino Leonardo and Arduino Mega, it is possible that you wish to reduce even more the user memory. For example, Settimino Client can control the Stop mode or Run mode of the PL, but if you just need read/write data you donā€™t need this feature.Ā 

To establish a memory model that you need simply to modify the directive at the beginning of the Settimino.h writing:

#define _SMALL
or
#define _NORMAL
or
#define _EXTENDED

The small model has the minimum group of functions to connect to a PLC and reading/writing data.

The normal mode has the S7Helper.

Finally, the extended model has also the remaining extended functions.

By default, Settimino is released as Extended.

Configuration S7 1200:

  • On DB properties you must select "Access optimized to the block" on the attribute tab.
  • On the protection area of the PLC properties, you just must select "Complete access (without protection)" and "Allow access PUT/GET communication from PLC, HMI, OPCā€¦"


ā€‹Search in our Blog

How to connect Arduino based PLC with Siemens S7 PLC family equipped through Ethernet
Alejandro Jabalquinto December 10, 2018
Share this post

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