logo elektroda
logo elektroda
X
logo elektroda

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

madiz08 8610 15
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18302167
    madiz08
    Level 14  
    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?
  • ADVERTISEMENT
  • #2 18302610
    madiz08
    Level 14  
    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  
    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  
  • ADVERTISEMENT
  • #6 18303537
    madiz08
    Level 14  
    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
  • Helpful post
    #7 18303566
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #8 18304402
    madiz08
    Level 14  
    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  
    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  
    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
  • #13 18305743
    Anonymous
    Level 1  
  • #14 18306314
    madiz08
    Level 14  
    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  
    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.
Summary generated by the language model.
ADVERTISEMENT