Wiznet makers

Benjamin

Published June 17, 2024 ©

43 UCC

11 WCC

4 VAR

0 Contests

0 Followers

1 Following

Original Link

Communication with Siemens PLC using M5Stack W5500 LAN Module (M5Stack#LANモジュールでSiemensPLCと通信)

A project using the M5Stack W5500 LAN module to communicate with and visualize data from a Siemens PLC.

COMPONENTS Hardware components

M5Stack - LAN Module with W5500

x 1

Software Apps and online services

Davide Nardella - Settimino Library

x 1


Arduino - Arduino IDE

x 1


PROJECT DESCRIPTION

In today's interconnected world, seamless communication between devices and systems is essential. One of the powerful tools that enable such communication is the WIZnet W5500 chip, especially when integrated into modules like the M5Stack. This article will delve into using the M5Stack W5500 LAN module to communicate with Siemens PLCs, utilizing the Settimino and Ethernet2 libraries.

Introduction to WIZnet W5500 and M5Stack LAN Module

The WIZnet W5500 is a robust and efficient TCP/IP Ethernet controller that simplifies internet connectivity in embedded systems. The M5Stack LAN module, which incorporates the W5500 chip, is designed to facilitate easy network connectivity. This module includes a TCP/IP Ethernet controller and features an HT3.96 connector and a 485 interface, allowing it to connect with other circuits seamlessly.

Features of the M5Stack W5500 LAN Module

  • TCP/IP Ethernet Controller: Ensures reliable and straightforward internet connectivity.
  • HT3.96 Connector: Enables connections to other circuits.
  • 485 Interface: Facilitates communication with other devices.

For more detailed specifications, you can refer to the M5Stack LAN Base documentation.

You can purchase the M5Stack W5500 LAN module here.

Utilizing the Settimino Library for Siemens PLC Communication

The Settimino library is an open-source Ethernet library designed to facilitate communication between Arduino, ESP8266, NodeMCU, ESP32, and Siemens PLCs (S7-1200, 1500, 300, 400, 200, LOGO). This library simplifies the process of interfacing with Siemens PLCs, making it an excellent choice for automation projects.

Installing the Settimino Library

To get started with the Settimino library, download the latest version from SourceForge.

Using the Ethernet2 Library with W5500

The Ethernet2 library is specifically designed for WIZnet W5500 Ethernet shields, supporting both server and client functionalities. It is essential to note that older versions, such as W5100, are not compatible with this library.

You can download the Ethernet2 library from the Arduino Library Reference.

Implementation

This section provides a step-by-step guide to implementing the communication setup, from installation to testing.

Setting Up the Environment

  1. Install Libraries: Ensure both the Settimino and Ethernet2 libraries are installed in your Arduino IDE.
  2. Modify Settimino.h: Adjust the code starting from line 111 to cater to the specific configurations of the M5Stack and LAN module.
  3. Edit Code for M5Core2: If using M5Core2, make necessary adjustments in the code.

 

Example Code

Below is a simplified example code for setting up communication using M5Stack hardware. For the full code and detailed explanations, please refer to the original M5Stack LAN Base documentation.

#include <Platform.h>
#include <Settimino.h>

#define USE_DISPLAY

#ifdef USE_DISPLAY
  #define stdout M5.Lcd
#else
  #define stdout Serial
#endif

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x08, 0xE1 };
IPAddress Local(192,168,0,10);
IPAddress Gateway(192, 168, 0, 1);
IPAddress Subnet(255, 255, 255, 0);

char ssid[] = "SKYNET-AIR";
char pass[] = "password";
IPAddress PLC(192,168,0,12);

int DBValues = 100;
int OFSValues = 0;
int SizeValues = 36;

float V[3] = {0.0,0.0,0.0};
float C[3] = {0.0,0.0,0.0};
float P[3] = {0.0,0.0,0.0};

S7Client Client;

void setup() {
#ifdef M5STACK_LAN
  M5.begin(true, false, true);
#endif
#ifdef M5STACK_WIFI
  M5.begin(true, false, true);
#endif

  Serial.begin(115200);

  // Initialize Ethernet or WiFi
  EthernetInit(mac, Local);
  delay(1000);
  Serial.println("Cable connected");
  Serial.println("Local IP address: ");
  Serial.println(Ethernet.localIP());
  delay(3000);
}

bool Connect() {
  int Result = 1;
  Serial.println("Connecting to ");
  Serial.println(PLC);

  while (Result != 0) {
    Result = Client.ConnectTo(PLC, 0, 1);
    if (Result == 0) {
      Serial.println("Connected, PDU Length = ");
      Serial.println(Client.GetPDULength());
      delay(300);
    } else {
      Serial.print(".");
      delay(500);
    }
  }
  return Result == 0;
}

void loop() {
  if (!Client.Connected)
    Connect();

  int Result = Client.ReadArea(S7AreaDB, DBValues, OFSValues, SizeValues, NULL);

  if (Result == 0) {
    V[0] = S7.FloatAt(0);
    V[1] = S7.FloatAt(4);
    V[2] = S7.FloatAt(8);
    C[0] = S7.FloatAt(12);
    C[1] = S7.FloatAt(16);
    C[2] = S7.FloatAt(20);
    P[0] = S7.FloatAt(24);
    P[1] = S7.FloatAt(28);
    P[2] = S7.FloatAt(32);
    // Display values (add display logic here)
  } else {
    // Handle error (add error handling logic here)
  }

  delay(200);
  M5.update();
}

For the complete code and further details, please refer to the M5Stack LAN Base documentation.

 

Testing the Communication Setup

Before testing the communication, ensure all connections and configurations are correct. After uploading the code, verify the following:

  1. The device connects to the network (either wired or Wi-Fi).
  2. The device successfully communicates with the Siemens PLC.
  3. Data from the PLC is accurately displayed on the M5Stack.

Results

Upon successful implementation, the M5Stack should display real-time data from the Siemens PLC, including voltage, current, and power metrics.

Conclusion

Integrating the WIZnet W5500 chip with M5Stack and utilizing libraries like Settimino and Ethernet2 can significantly simplify the process of setting up robust communication between embedded systems and industrial PLCs. This guide provides a comprehensive overview of setting up such a communication system, making it a valuable resource for engineers and hobbyists alike.

About the Creator

The creator of this guide is a prominent Japanese maker, actively sharing knowledge and projects related to embedded systems and automation. With over 1.3k subscribers on YouTube and 2.2k followers on Twitter, they continue to inspire and educate the maker community.

Find them on:

This guide serves as an invaluable resource for anyone looking to explore the capabilities of the WIZnet W5500 chip and M5Stack in industrial automation projects.

Documents
Comments Write