2

I'm a newbie in using the Arduino Ethernet Shield v2 (Arduino product code A000024) and I'm experiencing some strange behaviours on a critical work with strict deadline.

The project involve some Arduino (both UNOs and MEGA2560s) sending sensor data via OSC to a couple of destination PCs for later processing.

To do that I'm using what it seemed to me to be a quite simple to use Arduino OSC library, the CNMAT one.

I've noticed this fact, which I think is related to some hardware malfunction.

I've found my code getting stuck even with a correct setup of the LAN. The code stops working, stops sending OSC messages, Ethernet shield is no more reachable with the ping. This persists also after loading again the code, or manually resetting the Arduino board. Initially I thought it was my fault but I've found that, substituting the shield with another one, the problem magically disappeared. On one of the problematic shield I've also experienced many continuous shutdowns and startups of the Arduino every 5 seconds (firmware restart from the setup)!

Are these ethernet shields known to be defective or having some issues? The strange thing is that I've experienced this problem on 3 out of 8 of them: this is super critical! Have you experienced something similar? Do you know of similar problems occurred before?


For debug purposes, here's a code test I've written and tried on a single Arduino UNO, always the same, using the same LAN setup (ethernet cable, IP addresses, Ethernet switch) switching two different Ethernet shields:

/* NET stuff ********************************************/
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
EthernetUDP Udp;

IPAddress ip(10, 3, 3, 210); // the Arduino's IP
byte mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0x83, 0xCE };

#define DELAY 1000

// SETUP //////////////////////////////////////////////////////////////////
void setup() {
  
  Serial.begin( 115200 );
  Serial.println("setup");

  // Ethernet and OSC utilities **************************
  Ethernet.begin(mac, ip);

  // Hardware status check 
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.");
  }
  else if (Ethernet.hardwareStatus() == EthernetW5100) {
    Serial.println("W5100 Ethernet controller detected.");
  }
  else if (Ethernet.hardwareStatus() == EthernetW5200) {
    Serial.println("W5200 Ethernet controller detected.");
  }
  else if (Ethernet.hardwareStatus() == EthernetW5500) {
    Serial.println("W5500 Ethernet controller detected.");
  }

  //Tells you whether the link is active. 
  // LinkOFF could indicate the Ethernet cable is unplugged or defective. 
  if (Ethernet.linkStatus() == Unknown) {
    Serial.println("Link status unknown. Link status detection is only available with W5200 and W5500.");
  }
  else if (Ethernet.linkStatus() == LinkON) {
    Serial.println("Link status: On");
  }
  else if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Link status: Off");
  }

  while( Ethernet.linkStatus() == LinkOFF ) {
    delay( DELAY );
  }
}

// LOOP ///////////////////////////////////////////////////////////////////
void loop() 
{

  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.print("Ethernet link broken!\t");
    Serial.println("please connect the Ethernet cable");
    delay( DELAY );
    return;
  }
  
  Serial.println("LOOP working as expected!");
  delay( DELAY );
}

When I try this code using the "defective" Arduino Ethernet shield the Serial monitor print something like this (note that I'm not doing anything, I'm leaving everything untouched):

[...]
14:25:17.906 -> setup
14:25:18.471 -> W5500 Ethernet controller detected.
14:25:18.471 -> Link status: On
[...]
14:26:41.545 -> LOOP working as expected!
14:26:42.542 -> LOOP working as expected!
14:26:43.538 -> LOOP working as expected!
14:26:44.535 -> Ethernet link broken!   please connect the Ethernet cable
14:26:45.531 -> LOOP working as expected!
14:26:46.561 -> LOOP working as expected!
14:26:47.558 -> LOOP working as expected!
14:26:48.555 -> LOOP working as expected!
14:26:49.552 -> Ethernet link broken!   please connect the Ethernet cable
14:26:50.549 -> LOOP working as expected!
14:26:51.546 -> LOOP working as expected!
14:26:52.543 -> LOOP working as expected!
14:26:53.540 -> LOOP working as expected!
14:26:54.570 -> LOOP working as expected!
14:26:55.567 -> Ethernet link broken!   please connect the Ethernet cable
14:26:56.564 -> LOOP working as expected!
14:26:57.561 -> LOOP working as expected!
14:26:58.557 -> LOOP working as expected!
14:26:59.553 -> Ethernet link broken!   please connect the Ethernet cable
14:27:00.550 -> Ethernet link broken!   please connect the Ethernet cable
14:27:01.546 -> LOOP working as expected!
14:27:02.576 -> Ethernet link broken!   please connect the Ethernet cable
14:27:03.572 -> LOOP working as expected!
14:27:04.569 -> LOOP working as expected!
14:27:05.566 -> LOOP working as expected!
14:27:06.563 -> LOOP working as expected!
14:27:07.560 -> LOOP working as expected!
14:27:08.557 -> LOOP working as expected!
14:27:09.587 -> LOOP working as expected!
14:27:10.583 -> Ethernet link broken!   please connect the Ethernet cable
14:27:11.580 -> LOOP working as expected!
14:27:12.577 -> LOOP working as expected!
[...]

In the meantime, the ping stops working and will not work again until I reboot the Arduino:

[...]
64 bytes from 10.3.3.210: icmp_seq=301 ttl=128 time=0.185 ms
64 bytes from 10.3.3.210: icmp_seq=302 ttl=128 time=0.171 ms
64 bytes from 10.3.3.210: icmp_seq=303 ttl=128 time=0.184 ms
64 bytes from 10.3.3.210: icmp_seq=304 ttl=128 time=0.229 ms
64 bytes from 10.3.3.210: icmp_seq=305 ttl=128 time=0.206 ms
64 bytes from 10.3.3.210: icmp_seq=306 ttl=128 time=0.278 ms
64 bytes from 10.3.3.210: icmp_seq=307 ttl=128 time=0.143 ms
64 bytes from 10.3.3.210: icmp_seq=308 ttl=128 time=0.229 ms
64 bytes from 10.3.3.210: icmp_seq=309 ttl=128 time=0.198 ms 
From 10.3.3.165 icmp_seq=335 Destination Host Unreachable
From 10.3.3.165 icmp_seq=336 Destination Host Unreachable
From 10.3.3.165 icmp_seq=339 Destination Host Unreachable
From 10.3.3.165 icmp_seq=342 Destination Host Unreachable
From 10.3.3.165 icmp_seq=343 Destination Host Unreachable
From 10.3.3.165 icmp_seq=344 Destination Host Unreachable
[...]

As you see the "Link" seems to be on and than off repeatedly. I don't know why from the moment. I'm not modifying anything on my network setup (the LAN cable or anything like that).

I don't know why the ping stops working and will not work again even if the Serial monitor is telling the LINK is ON.

Let me know as soon as you can and thank you so much for your help and support.

bests

na

PS: I've posted a similar question on the Arduino forum but I had no way of understanding what kind of problem is this --> link

edit 11/02/2021

I've written a new code sketch to always print the status of the link. Here it is.

    /* NET stuff ********************************************/
    #include <SPI.h>
    #include <Ethernet.h>
    #include <EthernetUdp.h>
    EthernetUDP Udp;
    
    IPAddress ip(10, 3, 3, 210); // the Arduino's IP
    byte mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0x83, 0xD5 };
    
    #define DELAY 1000
    
    // SETUP //////////////////////////////////////////////////////////////////
    void setup() {
      
      Serial.begin( 115200 );
      Serial.println("setup");
    
      // Ethernet and OSC utilities **************************
      Ethernet.begin(mac, ip);
    
      // Hardware status check 
      if (Ethernet.hardwareStatus() == EthernetNoHardware) {
        Serial.println("Ethernet shield was not found.");
      }
      else if (Ethernet.hardwareStatus() == EthernetW5100) {
        Serial.println("W5100 Ethernet controller detected.");
      }
      else if (Ethernet.hardwareStatus() == EthernetW5200) {
        Serial.println("W5200 Ethernet controller detected.");
      }
      else if (Ethernet.hardwareStatus() == EthernetW5500) {
        Serial.println("W5500 Ethernet controller detected.");
      }
    
      //Tells you whether the link is active. 
      // LinkOFF could indicate the Ethernet cable is unplugged or defective. 
      if (Ethernet.linkStatus() == Unknown) {
        Serial.println("Link status unknown. Link status detection is only available with W5200 and W5500.");
      }
      else if (Ethernet.linkStatus() == LinkON) {
        Serial.println("Link status: On");
      }
      else if (Ethernet.linkStatus() == LinkOFF) {
        Serial.println("Link status: Off");
      }
    
      while( Ethernet.linkStatus() == LinkOFF ) {
        Serial.println("\tplease connect the Ethernet cable");
        delay( DELAY );
      }
    }
    
    // LOOP ///////////////////////////////////////////////////////////////////
    void loop() 
    {
    
      int LINK_STATUS = Ethernet.linkStatus();
      
      if ( LINK_STATUS == LinkOFF) {
        Serial.print("Ethernet link broken!\t");
        Serial.println("please connect the Ethernet cable");
        delay( DELAY );
        return;
      } else if( LINK_STATUS == Unknown ) {
        Serial.println("LINK_STATUS: Unknown");
        delay( DELAY );
        return;
      } else if( LINK_STATUS == LinkON ) {
        Serial.println("LOOP working as expected! (LINK_STATUS: ON)");
      }
      
      delay( DELAY );
    }

After a while, it gave me this output on the serial monitor (at the same time ping said "Destination Host Unreachable"):

[...]
10:57:21.207 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:22.203 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:23.200 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:24.197 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:25.195 -> Ethernet link broken!   please connect the Ethernet cable
10:57:26.192 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:27.188 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:28.186 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:29.216 -> Ethernet link broken!   please connect the Ethernet cable
10:57:30.213 -> Ethernet link broken!   please connect the Ethernet cable
10:57:31.210 -> Ethernet link broken!   please connect the Ethernet cable
10:57:32.207 -> Ethernet link broken!   please connect the Ethernet cable
10:57:33.204 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:34.202 -> Ethernet link broken!   please connect the Ethernet cable
10:57:35.198 -> Ethernet link broken!   please connect the Ethernet cable
10:57:36.194 -> Ethernet link broken!   please connect the Ethernet cable
10:57:37.224 -> Ethernet link broken!   please connect the Ethernet cable
10:57:38.221 -> Ethernet link broken!   please connect the Ethernet cable
10:57:39.219 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:40.216 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:41.213 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:42.210 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:43.207 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:44.236 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:45.232 -> Ethernet link broken!   please connect the Ethernet cable
10:57:46.228 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:47.225 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:48.222 -> LOOP working as expected! (LINK_STATUS: ON)
10:57:49.218 -> Ethernet link broken!   please connect the Ethernet cable
10:57:50.216 -> Ethernet link broken!   please connect the Ethernet cable
10:57:51.212 -> Ethernet link broken!   please connect the Ethernet cable
10:57:52.242 -> Ethernet link broken!   please connect the Ethernet cable
10:57:53.239 -> Ethernet link broken!   please connect the Ethernet cable
10:57:54.235 -> Ethernet link broken!   please connect the Ethernet cable
10:57:55.231 -> Ethernet link broken!   please connect the Ethernet cable
10:57:56.227 -> Ethernet link broken!   please connect the Ethernet cable
[...]

Adding some new elements here. I've also noticed that, sometimes, even if the LINK status is ON, the ping is not working. It is almost clear to me that the two things are completely uncorrelated.

I've made some experiments in changing also the MAC address (setting a MAC address which is different from the one I see on the label on the shield). The "wrong" MAC address seems not to be cause of problems. Can it be that a MAC address misconfiguration on the Arduino firmware can make the things work the wrong way?

I've also made many attempts in disconnetting and re-connecting the ethernet cable to the shield without powering the Arduino off and I've experinced a series of different behaviours.

1A) disconnecting the ethernet cable:

  • Serial monitor prints: "Ethernet link broken! please connect the Ethernet cable"
  • ping stops;

1B) re-connecting the ethernet cable:

  • on the Serial monitor LinkOn and LinkOff alternate between themselves, then, "LOOP working as expected! (LINK_STATUS: ON)" becomes stable;
  • ping still prints "Destination Host Unreachable";

2) reset of the Arduino Board (not the reset on the shield)

  • Serial monitor: "LOOP working as expected! (LINK_STATUS: ON)"
  • ping works again;

3A) Trying to repeat the same procedure as before (1A). Disconnecting the Ethernet cable:

  • Serial monitor prints "Ethernet link broken! please connect the Ethernet cable";
  • ping stops;

3B) re-connecting the ethernet cable:

  • on the Serial monitor LinkOn and LinkOff alternate between themselves, then, "LOOP working as expected! (LINK_STATUS: ON)" becomes stable;
  • ping works again (which is a different behaviour from before!!!);

This problem is really difficult for me to debug. It seems we have a lot of variables to take into consideration here, which are not under my control: if I repeat the same procedure again and again, behaviour changes.

I'm not sure if it depends on the board, on the W5500 chip, maybe on other things happening on the net. Is it possible?

I don't know how to write a code to be capable of detecting these malfunctions.

Thank you so much for your help. na

3
  • 2
    when your code prints "LOOP working as expected!", the actual status is not indicated, except that it is not LinkOFF
    – jsotola
    Feb 10 '21 at 16:43
  • 1
    I've had similar issues with the Ethernet V2 shield, which were probably caused by the (unused) SD Card interface on the Ethernet V2 shield interfering with Ethernet functionality (both use the SPI bus). I've solved this by explicitly disabling the SD Card interface CS (by setting pin 4 to high) at the start of my setup() code with: #define SDSelect 4 pinMode (SDSelect, OUTPUT); digitalWrite (SDSelect, HIGH); This solved my issues.
    – StarCat
    Feb 11 '21 at 13:15
  • Thank you @StarCat for your tip! I've tried this on a "defective" shield and, in fact, things seem to be going a little better. Now the Serial monitor is always reporting the link status as ON (without strange ON - OFF - ON status switching). But today, after two days of continuous "ping" of the Ethernet shield bymy laptop, the console tells me icmp_seq=10493 Destination Host Unreachable. Ping works again if I do a manual reset of the Arduino. Why? Is there a sort of buffer on the W5500 that fills up over time and, because of this, prevents the ping from working?
    – orestino
    Feb 14 '21 at 10:14
3

I've had similar issues with the Ethernet V2 shield, which were probably caused by the (unused) SD Card interface on the Ethernet V2 shield interfering with Ethernet functionality (both use the SPI bus).

From what I could see in the Ethernet Shield2 schematics, there is no pull-up on the signal controlling the SD card Chip Select (D4/SD_CS), which means an unitialized I/O pin on the Arduino side could potentially cause random noise on the SD CS input.

My solution was to explicitly disable the SD Card interface CS, by setting pin 4 to high at the start of my setup() code.

I used the following code:

#define SDSelect  4

... Other initialization code

setup() {
    pinMode (SDSelect, OUTPUT);
    digitalWrite (SDSelect, HIGH);

    ... Code continues ...

This solved my issues with random crashing. I realize that I can't remember if there was an SD card present in the slot at the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.