This how-to is meant to teach you how to establish a raw tcp connection between Arduino Uno/Mega and PLC Siemens S7-1200.
-
Prerequisites:
- Siemens PLC S7-1200
- Arduino Uno/Mega
- Ethernet shield or native Wi-Fi
- Siemens Switch for LAN connections
- TIA Portal
- Arduino IDE
- Ethernet library for Arduino (based on the shield used)
-
Hardware Network Setup
- PLC ethernet port > Switch
- Ethernet shield > Switch
- LAN cable from laptop > Switch for TIA portal
- Set static IPs: 192.168.0.1 (for PLC, Device Configuration > PROFINET Interface) and 192.168.0.xx (for Arduino)
-
Configuration in TIA Portal
3.1. Add TCON and TSEND/TRCV instructions in Main_OB1- TCON - establish connection
- Local Device: Active
- Remote IP: 192.168.0.xx (Arduino’s IP address)
- Remote Port: match Arduino server port
- Active connection: TRUE
- Type: TCP
- TSEND - send data
- TRCV - receive data
3.2. Connections in Main_OB1 for TCON: - REQ - bool
- CONNECT - “DB_TCP”.CONNECT (data block created specifically for TCP connection)
- DONE - bool
- BUSY - bool
- ERROR - bool
- STATUS - word
3.3. Connections in Main_OB1 for TSEND/TRCV:
- REQ - bool
- ID - 1
- DATA - “DB_TCP”.SEND_CODE/RCV_CODE
- In SEND_CODE/RCV_CODE you set the type of data you want to send over (in this case of use, SEND_CODE is a char)
- TCON - establish connection
-
Example of sending over the data in Main_OB1
- Created a function block to handle all the char commands that are being sent
- Example of the function block
- Created a function block to handle all the char commands that are being sent