How connect Arduino based PLC with Siemens PLC equipped with Ethernet port

How connect Arduino based PLC with Siemens PLC equipped with Ethernet port

On this post it is showed how to connect Industrial Shields Arduino based PLC (M-Duino‘s) with a Siemens PLC equipped with Ethernet port or communication processor. Any PLC is supported except for 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 Settimino from the link

Requirements of this example:

  • Arduino based PLC with Ethernet connection: M-Duino‘s 
  • Siemens PLC with Ethernet connection

Once we have all the requirements, we can proceed to explain how it works. The main class is 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 a 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, this 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 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 to 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 to the database 24, read 64 bytes from 0 to 64 and handle into the internal buffer.

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

S7Helper

The Siemens data is Big-enidan and the Arduino data is Little-endian. S7Helper is an object that allows to extract 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:

Address Name Type Initial value Comment
0.0   Struct    
+0.0 PRESSURE REAL 0.00000e+000 TRANSDUCER TP1
+4.0 ENCODER DWORD DWs16s0 MOTOR ENCODER
+8.0 COMP_NUMBER INT 0 COMPONENT 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 to this 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 extended model works perfectly on Arduino Leonardo and Arduino Mega, it is possible that you wish reduce even more the using 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 memory model that you need simply to modify the directive on 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 attribute tab.
  • On protection area of the PLC properties you just must select “Complete access (without protection)” and “Allow access PUT/GET communication from PLC, HMI, OPC… “

 

See also:

HOW TO READ AN ENCODER WITH ARDUINO BASED PLC’S

HOW TO TOUCH UP DATA FROM THE EEPROM

HOW TO USE STEPPER MOTOR WITH ARDBOX ANALOG

HOW TO CONNECT AND CONFIGURE A LOAD CELL USING HX711 TRANSMITTER WITH OUR EQUIPMENT’S

HOW TO GENERATE A DIFFERENT PWM’S SIGNALS WITH OURS EQUIPMENT’S

HOW TO USE THE WATCHDOG

RS-485 COMMUNICATION EXAMPLE USING OUR LIBRARIES

HOW TO CREATE A WEB SERVER TO READ A SD CARD WITH OUR PLC’S

HOW TO CONNECT A SD CARD TO A PLC

HOW TO UPLOAD A BOOTLOADER ON A ARDBOX/M-DUINO PLC, 

HOW TO READ ENCODER SPEED THROUGH AN INTERRUPT WITH AN ARDUINO BASED PLC’S,

HOW TO PROGRAM ARDUINO BASED PLC THROUGH ETHERNET

Comments are closed.