In this blog post, we explain how to configure and test Ethernet connectivity on any ESP32 PLC or M-Duino PLC from Industrial Shields, using the Arduino Ethernet library.
The example sketch connects the PLC to the internet via DHCP, identifies the Ethernet hardware chip, verifies the local IP address, and attempts a TCP connection to a remote host. Once uploaded through Arduino IDE, you can confirm that the Ethernet port is working correctly.
Connecting the Ethernet port
Connect an Ethernet cable from the PLC to any Ethernet port on your network (switch, router, or PC). No additional wiring is required.
For connector pinout and hardware details, check the Technical Features page for your model.
Ethernet test sketch for Arduino IDE
The sketch uses the Ethernet.h library. Download the following code as a test_ethernet.ino file, verify the board and model, select the correct port, and upload it using Arduino IDE.
#include <Ethernet.h>
#define REMOTE "www.google.com"
const uint16_t port = 80;
uint8_t mac[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0x01};
EthernetClient c;
void setup() {
Serial.begin(9600L);
Serial.println("ethernet started");
test();
}
void loop() {
if (!c.connected()) {
Serial.println("Disconnected");
test();
}
delay(1000);
}
void test() {
Ethernet.begin(mac);
switch (Ethernet.hardwareStatus()) {
case EthernetW5100: Serial.println("W5100 found"); break;
case EthernetW5200: Serial.println("W5200 found"); break;
case EthernetW5500: Serial.println("W5500 found"); break;
default: Serial.println("Unknown hardware"); break;
}
uint8_t MAC[6];
Ethernet.MACAddress(MAC);
for (int i = 0; i < 6; ++i) {
if (i > 0) Serial.print(':');
Serial.print(MAC[i], HEX);
}
Serial.println();
Serial.println(Ethernet.localIP());
if (Ethernet.localIP() == IPAddress({0,0,0,0})) {
Serial.println("Local IP FAIL");
} else {
Serial.println("Local IP OK");
if (c.connect(REMOTE, port)) {
Serial.println("Remote connection OK");
} else {
Serial.println("Remote connection FAIL");
}
}
}
Verifying the Ethernet connection
After uploading, open the Serial Monitor. If the Ethernet port is working correctly, you should see output similar to this:
ethernet started W5500 found AA:BB:CC:DD:EE:1 10.42.0.226 Local IP OK Remote connection OK

Ethernet connection with an ESP32 PLC or an M-Duino PLC