logo elektroda
logo elektroda
X
logo elektroda

[Solved] ESP32 communication with Siemens PLC - Ethernet connection using ENC28J60

madiz08 9735 15
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18302167
    madiz08
    Level 14  
    Posts: 517
    Help: 4
    Rate: 172
    The topic is probably a bit off topic for this section, but probably in the Automation section, no one will be able to help me in this topic.
    Some time ago someone wrote the Settimino.h library for communication between Arduino and Siemens PLC. With an ethernet connection, I use UNO or Mega with the W5100 ethernet module, if I use ESP32, I connect via WiFi and everything is fine.
    I would like to use a LAN cable connection, but using ESP32, which has no comparison at all with UNO or MEGA in terms of speed, multifunctionality, etc.
    https://www.elektroda.pl/rtvforum/topic3634381.html
    In the link above, I have already received help on how to configure the ESP32 + enc28j60 ethernet module together. I assembled a board for this purpose:
    ESP32 communication with Siemens PLC - Ethernet connection using ENC28J60
    At the beginning, I uploaded the following program to check if a connection to the network and then to the PLC will be established
    Code: C / C++
    Log in, to see the code


    Watching the serial monitor, I noticed that the microcontroller establishes a connection to the network, connects to the assigned IP, but when trying to establish a connection with the PLC, unfortunately, the program resets again and again.
    There is an important thing in the settimino library, namely the file platform.h
    Code: C / C++
    Log in, to see the code


    Depending on the microcontroller you are using, you should select the appropriate hardware there
    Code: C / C++
    Log in, to see the code

    Which as you can see below in the library affects the choice and "EthernetClient.h" or and "WiFiClient.h"
    I changed the ESP32 selection to:
    Code: C / C++
    Log in, to see the code

    Compilation errors
    I tried another way:
    Code: C / C++
    Log in, to see the code

    I was getting the same compile errors
    Code: C / C++
    Log in, to see the code
    https://www.elektroda.pl/rtvforum/posting.php?mode=newtopic&f=428#
    Could any of your colleagues spare some time to analyze this problem?
    Attachments:
    • EtherCard-master.rar (120.55 KB) You must be logged in to download this attachment.
    • Settimino_V2.0.0.rar (24.1 KB) You must be logged in to download this attachment.
  • ADVERTISEMENT
  • #2 18302610
    madiz08
    Level 14  
    Posts: 517
    Help: 4
    Rate: 172
    error: 'EthernetClass Ethernet' redeclared as different kind of symbol extern EthernetClass Ethernet;

    Added after 7 [minutes]:

    If I comment out two lines:
    //#include "Settimino.h"
    //S7Client Client;//
    and get rid of the connect() function, then everything is ok. This ENC28J6 module uses and the settimino library refers to . Two libraries used together cause errors and whether it could be somehow unified
  • Helpful post
    #3 18302935
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #4 18303455
    madiz08
    Level 14  
    Posts: 517
    Help: 4
    Rate: 172
    ESP32 communication with Siemens PLC - Ethernet connection using ENC28J60
    In fact, I managed to compile after your corrections, but when IP was assigned and ESP32 started to establish connection with PLC via Settimino.h, then the microcontroller restarted as in the attached picture after entering the Connect() function.

    Added after 1 [minutes]:

    After removing Ethernet.h, information about the lack of Ethernet.h popped up during compilation. Thanks for the advice, I'll try the other library again
  • Helpful post
    #5 18303507
    Anonymous
    Level 1  
  • #6 18303537
    madiz08
    Level 14  
    Posts: 517
    Help: 4
    Rate: 172
    So maybe it's worth staying with the current library? and try to change Settimino along with platform.h. Unfortunately, I'm bad at these libraries, but it seems to me that establishing a connection with the PLC is done via TCP client. I didn't find anything like that in EtherCard.
    The first thing in settimino is:
    void EthernetInit(uint8_t *mac, IPAddress ip);
    In settimino.cpp there is an extension of this function:
    Code: C / C++
    Log in, to see the code

    and below is a link to the client
    Code: C / C++
    Log in, to see the code

    and the Ethernet.Client file is black magic for me
  • ADVERTISEMENT
  • Helpful post
    #7 18303566
    Anonymous
    Level 1  
  • #8 18304402
    madiz08
    Level 14  
    Posts: 517
    Help: 4
    Rate: 172
    I downloaded the library and already when checking the examples there are problems with compiling for ESP32. I'm checking it on my laptop at work. At home, I also remember some problems with compiling ethernet connections for ESP32, but I managed to solve this problem somehow, so when I come back after work, I will check it right away.

    Added after 5 [hours] 43 [minutes]:

    Ok, everything is compiling, first I will try to look for some examples using enc28j60 and connecting to the network, and if I succeed, I will try to make changes in settimino

    Added after 37 [minutes]:

    I played the TCP_Server example to start with
    Code: C / C++
    Log in, to see the code

    At the beginning of the library there is information that it is an adaptation for Enc28J60, so I played it without any changes. First I tried to ping it after connecting to the network and unfortunately no response every time, also no connection to the local network.
    I started to wonder if the connection is the same as before. The UIPEthernet library in the hardware folder contains pictures of the connections for individual boards, but no ESP32. In the case of ESP8266, the connection looks like this:
    ESP32 communication with Siemens PLC - Ethernet connection using ENC28J60
    It looks like it should be the same, but it doesn't work. The connection on the board is 100% ok, because using the EtherCard library I can ping, i.e. the device is seen in the network
  • #9 18305121
    Anonymous
    Level 1  
  • #10 18305445
    madiz08
    Level 14  
    Posts: 517
    Help: 4
    Rate: 172
    ESP32 communication with Siemens PLC - Ethernet connection using ENC28J60
    At the beginning also 0 responses, but when I added SPI.h to the TCPServer.ino example, it's ok, also positive for now :) second and third ping correct
  • #11 18305459
    Anonymous
    Level 1  
  • #12 18305516
    madiz08
    Level 14  
    Posts: 517
    Help: 4
    Rate: 172
    And could you guide me where to change these SPI pins to 12, 13, 14, 15 as in the case of EtherCard? If it's not advisable, then of course I'll stay with it. I just mean that now, I connect the second ESP32 with wires to the ethernet module, and if I had the same pins as in EtherCard, I could use my board, where I already have milled paths. But of course, if it's inadvisable, it stays what it is. In SPI.cpp I see either the default choice or just 12, 13, 14, 15, which is probably not here

    Added after 1 [minutes]:

    Code: C / C++
    Log in, to see the code

    The above is in SPI.cpp
  • ADVERTISEMENT
  • #13 18305743
    Anonymous
    Level 1  
  • #14 18306314
    madiz08
    Level 14  
    Posts: 517
    Help: 4
    Rate: 172
    Unfortunately, it didn't help. I also scanned the entire computer and there is no HardwareSPI.h file
  • #15 18307439
    Anonymous
    Level 1  
  • #16 18326706
    madiz08
    Level 14  
    Posts: 517
    Help: 4
    Rate: 172
    Sorry for not answering for more than a week, but really only now I was able to get back to the topic.
    Regarding the attempt to modify the library, due to the change of the SPI pins, the modification did not help here, but it is irrelevant. I made a second board with pins for the enc28j60 pins, according to the pattern you presented to me earlier, i.e.:
    C.S. = 5
    MOSI = 23
    MISO = 19
    SCK = 18
    Then in platform.h for ESP32 I set S7WIRED and replaced it according to the guidelines:
    Ethernet.h => UIPEthernet.h
    EthernetClient.h => UIPClient.h
    Everything works as it should :) It is true that it probably works on the principle of connect - send - disconnect, where you need to spend 500ms on it, but still I can easily exchange data with the PLC in both directions using ESP32.
    Once again thank you very much for your help.

Topic summary

✨ The discussion revolves around establishing an Ethernet connection between an ESP32 and a Siemens PLC using the ENC28J60 Ethernet module. The user initially faced compilation errors due to conflicts between the Settimino library and Ethernet libraries. Solutions included modifying library includes and using the UIPEthernet library, which is compatible with the ENC28J60. The user successfully compiled the code after adjusting the SPI pin assignments and library configurations. Ultimately, the ESP32 was able to communicate with the PLC, albeit with a connection method that required a delay for data exchange.
Generated by the language model.

FAQ

TL;DR: For ESP32 + ENC28J60 to a Siemens PLC, use UIPEthernet ("emulates EthernetClient") and set S7WIRED; a test build used 25% flash. This FAQ is for makers wanting wired ESP32-PLC comms without Wi‑Fi hiccups. [Elektroda, khoam, post #18302935]

Why it matters: It removes library conflicts and reboots so your ESP32 talks to the PLC reliably over LAN.

Quick Facts

How do I wire ENC28J60 to ESP32 correctly?

Use VSPI defaults: CS=5, MOSI=23, MISO=19, SCK=18. SS acts as CS unless you call Ethernet.init(CS_PIN). Keep wires short and ground common. These pins matched stable pings and TCP traffic in tests. [Elektroda, khoam, post #18305121]

How do I fix ‘EthernetClass Ethernet redeclared as different kind of symbol’ on ESP32?

Remove the Arduino Ethernet library and stop mixing EtherCard with Settimino. Switch to UIPEthernet, which supports ENC28J60 and emulates Ethernet/EthernetClient, matching Settimino’s expectations. This resolves the symbol clash and compile failures. [Elektroda, khoam, post #18302935]

Do I need SPI.h on ESP32 with ENC28J60?

Yes. Without SPI.h, the ENC28J60 will not communicate and pings fail. After including SPI.h, pings and server examples worked. As one expert put it, “Without SPI support, the ESP32 is unlikely to communicate with the ENC28J60.” [Elektroda, khoam, post #18305459]

How do I configure Settimino for wired Ethernet on ESP32?

In Platform.h keep ESP32 config but define S7WIRED. Replace Ethernet.h with UIPEthernet.h and EthernetClient.h with UIPClient.h. Do not remove S7WIRED for ESP32; Settimino then uses the UIPEthernet client transparently. [Elektroda, khoam, post #18303507]

Why does my ESP32 reboot when I call Client.ConnectTo()?

Reboots stem from library/API mismatches and wrong platform flags. Use UIPEthernet with S7WIRED and correct pins, then connect. After these changes, stable two‑way PLC data exchange worked over LAN without reboots. [Elektroda, madiz08, post #18326706]

Should I use EtherCard or UIPEthernet with Settimino?

Use UIPEthernet. Settimino expects the standard Ethernet/EthernetClient API. EtherCard does not provide that API, causing incompatibilities. UIPEthernet supports ENC28J60 and emulates the needed classes, so Settimino can connect normally. [Elektroda, khoam, post #18302935]

Can I change SPI pins to 12/13/14/15 instead of 23/19/18/5?

You can try overriding pin macros in UIPEthernet’s Enc28J60Network.h (ENC28J60_CONTROL_CS, SPI_MOSI, SPI_MISO, SPI_SCK). This forces a custom mapping. If unreliable, revert and use the default VSPI pins on ESP32 hardware. [Elektroda, khoam, post #18307439]

How do I set a custom CS pin for the ENC28J60 on ESP32?

Call Ethernet.init(CS_PIN) before Ethernet.begin(). By default SS is used as CS. This lets you keep VSPI SCK/MISO/MOSI while moving only CS to a convenient GPIO. [Elektroda, khoam, post #18305121]

What quick test proves the ENC28J60 is alive on ESP32?

Load UIPEthernet’s TCP_Server example, include SPI.h, set MAC/IP, and start the server. Ping the IP, then open a TCP client to LISTENPORT and send text. Pings failed until SPI.h was added; then they succeeded. [Elektroda, madiz08, post #18305445]

How do I avoid conflicts when migrating from EtherCard?

Uninstall the Arduino Ethernet library, stop including EtherCard, and use UIPEthernet instead. UIPEthernet supplies Ethernet/EthernetClient, preventing the ‘Ethernet’ symbol clash and enabling Settimino’s client to build cleanly. [Elektroda, khoam, post #18302935]

What connection pattern works with Siemens PLC over UIPEthernet?

A connect → send/receive → disconnect cycle around 500 ms worked reliably. This pattern avoided resets and kept PLC exchanges stable on ESP32. It’s a practical baseline before optimizing. [Elektroda, madiz08, post #18326706]

What resource usage should I expect for a basic build?

A reference ESP32 build reported 25% program flash and 6% dynamic memory usage. This left ample headroom for PLC logic and buffers. Treat it as a typical starting point, not a hard limit. [Elektroda, khoam, post #18302935]

Why did EtherCard + Settimino crash or fail to compile?

EtherCard typedefs ‘Ethernet’, which collides with the Arduino Ethernet library and Settimino’s required API. The result is redeclaration errors and instability. UIPEthernet removes this mismatch by emulating the standard classes. [Elektroda, madiz08, post #18302610]

How do I set the PLC IP in my sketch for Settimino?

Define the PLC IP as a byte array and pass it to Client.ConnectTo(). Ensure your LAN and PLC subnet match your ESP32 static IP configuration. This mirrors the working code pattern shared in the thread. [Elektroda, madiz08, post #18302167]

How-To: migrate EtherCard project to UIPEthernet + Settimino on ESP32?

  1. Uninstall Arduino Ethernet; remove EtherCard includes; add UIPEthernet and SPI.h.
  2. In Settimino Platform.h define S7WIRED; map Ethernet.h→UIPEthernet.h and EthernetClient.h→UIPClient.h.
  3. Wire ENC28J60 to VSPI pins; optionally call Ethernet.init(CS_PIN); build and test with ping. [Elektroda, khoam, post #18303507]
Generated by the language model.
ADVERTISEMENT