Know-How
Completed
RS-485: how to check a bus step by step
259 Views •Modbus RTU timeout: 6 checks before blaming the wiring
177 Views •Modbus register 40001 or address 0? 6 checks
16 Views •Modbus RTU master and slave with two ESP32 PLC, step by step
24 Views •4G PLC not connecting: 6 checks before blaming the code
137 Views •LoRa works on the desk, fails in the field: 6 checks before you install
137 Views •LoRaWAN node won't join: 6 checks, in order
61 Views •Choosing a PLC 2: which communications do you really need
63 Views •PLC on Ethernet with no ping? 6 checks
16 Views •Digital input not reading: NPN or PNP, step by step
265 Views •RS-485: how to check a bus step by step
259 Views •4-20 mA input reading wrong: check it step by step
256 Views •Scaling a 4-20 mA signal in the PLC: formula, constants and code
247 Views •Relay or transistor output: which one and how to check it
213 Views •Modbus RTU timeout: 6 checks before blaming the wiring
177 Views •Upload fails: 6 checks before blaming the code
160 Views •4G PLC not connecting: 6 checks before blaming the code
137 Views •LoRa works on the desk, fails in the field: 6 checks before you install
137 Views •Choosing a PLC 2: which communications do you really need
63 Views •LoRaWAN node won't join: 6 checks, in order
61 Views •Arduino IDE compile error: 6 checks before the code
59 Views •SD card corrupted? 6 habits for Linux in the field
59 Views •Choosing a PLC 1: count the I/O and leave spare
57 Views •Touch panel: screen turned, touch didn't. 6 checks
56 Views •Modbus RTU master and slave with two ESP32 PLC, step by step
24 Views •Node-RED not starting after a reboot? 6 checks
18 Views •PLC on Ethernet with no ping? 6 checks
16 Views •Modbus register 40001 or address 0? 6 checks
16 Views •PLC on Ethernet with no ping? 6 checks
Short answer: when a PLC has an IP address and does not answer the ping, check the subnet, the mask, the gateway, DHCP and duplicate IP or MAC addresses and, in the code, the order of the arguments of Ethernet.begin(), in this order.
Download the checklist (PDF, 2 pages)
Descarga la lista de comprobación (PDF, 2 páginas)
These checks apply to any IPv4 device: PLC, gateway or PC. Only check 6 is specific to the Arduino Ethernet library, used by Arduino PLC and ESP32 PLC. Before you start, rule out power, cable and link: on an Arduino PLC, USB alone does not power the Ethernet port, so power the PLC with 12 to 24 Vdc. IPv6, VLANs and Modbus TCP are outside this lesson.
Six checks, in this order
| Check | What to do | Good result |
|---|---|---|
| 1. Subnet | The mask decides which part of the address is the network. With 255.255.255.0 (/24), PLC and PC need the same first three numbers and a different last one, for example 192.168.1.20 and 192.168.1.10. With another mask the rule changes: with 255.255.0.0, only the first two numbers have to match. | Same network part, different host part. |
| 2. Mask | Set the same mask on both devices. With a wrong mask, a device can take a local address for a remote one and send it to the gateway: communication fails with some nearby networks and works with distant ones. | The same mask on both sides. |
| 3. Gateway | The gateway is used only to reach other networks. Between two devices on the same subnet, the traffic goes directly through the switch. To reach another network, the gateway is the address of a router inside your subnet. With a wrong gateway, the device still talks to its own segment but fails with some or all remote networks. | A router address inside the subnet, used only for other networks. |
| 4. DHCP or static | With DHCP, the server can give the same address, a new one or none when the lease is renewed or after a reboot. If other devices connect to the PLC, use an address reserved in the DHCP server or a fixed address outside the DHCP range, agreed with whoever manages the network. In the Arduino library, Ethernet.begin(mac) uses DHCP and returns 1 or 0; call Ethernet.maintain() regularly to renew the lease. | The IP does not change after a reboot. |
| 5. Duplicates | The same IP or the same MAC on two devices causes intermittent faults that are hard to trace; a switch that learns the same MAC on two ports reports MAC flapping. On Industrial Shields PLCs the MAC is defined in the code, and the examples share the same value: give each device its own. To test, disconnect the PLC and ping its IP: a reply comes from another device. | No reply with the PLC disconnected; one MAC per device. |
| 6. Code | In the Arduino Ethernet library the order is Ethernet.begin(mac, ip, dns, gateway, subnet). With three values, the third is the DNS, not the gateway. Arguments left out take defaults: dns and gateway are the device IP with the last octet set to 1, and subnet is 255.255.255.0. Old examples written for begin(mac, ip, gateway, subnet) pass the gateway as DNS and the mask as gateway. | Arguments in this order; Ethernet.localIP() prints the expected address. |
Symptom, cause and what to do
- No ping, the IP belongs to another network: the PLC is outside the subnet. Use an IP and a mask from the same range.
- Ping works with the PC next to it, not with a device on another network: the gateway. Set the router of the subnet as gateway.
- It works, and after a reboot the client cannot find it: DHCP. Reserve the address in the server or use an agreed fixed IP.
- It works on and off, or a second PLC drops the first: duplicate IP or MAC. One IP and one MAC per device.
- The code compiles and the IP is right, but other networks or names do not work: the order of the arguments. Use mac, ip, dns, gateway, subnet.
hardwareStatus()returns EthernetNoHardware orlinkStatus()returns LinkOFF: hardware, power or cable. Fix it before the six checks.
Arduino PLC and ESP32 PLC
The Industrial Shields examples for M-Duino and ESP32 PLC use Ethernet.h. The improved version of the library comes with the board packages, from version 1.1.45 for M-Duino and 2.3.0 for ESP32 PLC, and, in the ESP32 PLC package 2.7.1 checked here, begin() keeps the same order of arguments and the same defaults. If the Arduino Ethernet library is also installed in Documents/Arduino/libraries, the Arduino IDE may compile that one instead: the Used: line of the compile log tells you which copy was used.
Example configuration
Example network, with private addresses (change them for your network):
PC 192.168.1.10/24 ---+
+--- switch --- router 192.168.1.1 --- other networks
PLC 192.168.1.20/24 ---+
PC <-> PLC: direct through the switch (the gateway is not used)
PLC <-> other network: through 192.168.1.1 (gateway)Reference code with Ethernet.h and a static address:
#include <Ethernet.h>
// A different MAC for each device on the network (change at least the last byte)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x21 };
IPAddress ip(192, 168, 1, 20); // outside the DHCP range, or reserved
IPAddress dns(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1); // only to leave the subnet
IPAddress subnet(255, 255, 255, 0);
void setup() {
Serial.begin(9600);
// Static: the order is mac, ip, dns, gateway, subnet
Ethernet.begin(mac, ip, dns, gateway, subnet);
// DHCP alternative: returns 1 if it gets an address, 0 if not
// if (Ethernet.begin(mac) == 0) { Serial.println("DHCP failed"); }
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet controller not found");
}
if (Ethernet.linkStatus() == LinkOFF) { // W5200 and W5500 only
Serial.println("Cable not connected");
}
Serial.print("IP: ");
Serial.println(Ethernet.localIP());
}
void loop() {
// With DHCP, call it often to renew the lease
// Ethernet.maintain();
}Typical mistake with the same values: Ethernet.begin(mac, ip, gateway, subnet); passes the gateway as DNS and the mask as gateway, and the subnet stays at the default 255.255.255.0. The code compiles without errors or warnings for ESP32 PLC with the Industrial Shields ESP32 boards 2.7.1; it has not been compiled here for Arduino PLC.
Next steps
- M-Duino Ethernet: fixed IP and a first TCP server
- Ethernet connection on ESP32 PLC and M-Duino PLC
- Improved Ethernet library for M-Duino and ESP32 PLCs
- Ethernet troubleshooting
- ESP32 PLC: industrial PLCs with Wi-Fi and Bluetooth
Sources
Microsoft Learn: Understand TCP/IP addressing and subnetting basics. IETF: RFC 5227, IPv4 Address Conflict Detection. Arduino Ethernet library 2.0.2 reference: Ethernet.begin() and Ethernet.maintain(). Cisco: Troubleshoot MAC address flap notifications. Industrial Shields: Ethernet troubleshooting, Ethernet connection with an ESP32 PLC or an M-Duino PLC, Improved Ethernet library for M-Duino and ESP32 PLCs.
Commenting is not enabled on this course.