Possibly Defective HanRun Ethernet Shield?

Hello all,

I am new to the forum here at Arduino, so I apologize ahead of time if my post doesn't thoroughly-explain my problem. I was basically interested in doing this instructables project that required use of the HanRun ethernet shield, so I acquired one from a local retailer whom sells almost any piece of Arduino hardware you can think of. I was testing the example library sketches to explore some basic features like IP addresses, web servers, etc. The first thing I tried was viewing my IP address, as my project required me to obtain one for locational accuracy, so I used the example sketch "DhcpAddressPrinter" to print a custom IP address. The code is as follows:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  // this check is only needed on the Leonardo:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for (;;)
      ;
  }
  // print your local IP address:
  printIPAddress();
}

void loop() {

  switch (Ethernet.maintain())
  {
    case 1:
      //renewed fail
      Serial.println("Error: renewed fail");
      break;

    case 2:
      //renewed success
      Serial.println("Renewed success");

      //print your local IP address:
      printIPAddress();
      break;

    case 3:
      //rebind fail
      Serial.println("Error: rebind fail");
      break;

    case 4:
      //rebind success
      Serial.println("Rebind success");

      //print your local IP address:
      printIPAddress();
      break;

    default:
      //nothing happened
      break;

  }
}

void printIPAddress()
{
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
  }

  Serial.println();
}

Now, it is to my understanding that the newer HanRun boards have their IP address printed on a sticker on the back. However, mine does not have that, (so I wrote my own custom one), and it also has a slightly-different layout from the other ones I have seen in different users' topics. It too has an SD card slot, which I have verified is empty, so it shouldn't be influencing my code. When I am running the sketch, nothing is being printed in my serial monitor. Even after leaving it for five minutes or more, nothing appears (not even a failure message). Baudrate is 9600 as it should be, so it can't be that. I have verified all my connections are good, including my one to the router. I suspected that I might have the newer W5500 board, as I read on other posts that people solve their issue when they switch to the "ethernet2" library, but I tried it too and had no luck. So I decided to switch to the other example, "WebServer", which allows to view the I/O and analog input statuses on a web page. The sketch is below:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 167);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("
");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

I used the same custom IP address but even though the code uploaded to the board correctly, I kept on getting the "page could not be loaded" error message on my browser. Again, even through repeated resets and checking that all my pins were plugged in and my ethernet cable is connected properly, nothing seemed to work. I feel that its worth mentioning that I have no circuits wired to my board currently, I am just trying to test it and understand how it all works before implementing it into my project. The fact that neither of these examples worked (nor did those in "ethernet2" library) leads me to wonder if this particular board is defective, though I believe that it comes from Arduino itself as it bears the brand logo and name on it. I even tried switching to another one of my UNO's to see if it was my UNO board itself (which is not an Arduino-made board) causing the issue, but had no luck.

I apologize if this is a very drawn-out question, but I have viewed my YouTube videos and existing forums and tried to use them to fix my issue with no luck. Should I just try exchanging the HanRun board or is there a possible different issue that I am overlooking? Thank you in advance.

WadenatorW65:
required use of the HanRun ethernet shield

HanRun is just the manufacturer of the RJ45 jack on the board. That name is not really relevant when describing an Ethernet shield. What's important is which Ethernet controller chip is used on the shield. The common chips are W5100, W5200, W5500, ENC28J60

WadenatorW65:
Now, it is to my understanding that the newer HanRun boards have their IP address printed on a sticker on the back. However, mine does not have that, (so I wrote my own custom one)

Some Ethernet shields have a unique MAC address on a sticker. For the shields without a sticker, you can make up any MAC address you like as long as it's unique on the network the Ethernet shield is connected to. No Ethernet shields have an IP address on a sticker. That wouldn't make sense because the IP address depends on the network the shield is connected to. You can set the shield to use any static IP address on your network as long as no other devices on the network are already using that address.

WadenatorW65:
I suspected that I might have the newer W5500 board, as I read on other posts that people solve their issue when they switch to the "ethernet2" library

The newest release of the official Arduino Ethernet library (2.0.0) supports W5100, W5200, and W5500. It's no longer necessary to use the Ethernet2 library for an Ethernet shield with the W5500. You can check the version of your Ethernet library at Sketch > Include Library > Manage Libraries...

However, neither the Ethernet library nor the Ethernet2 library support the ENC28J60. You need to look at the writing on the biggest black chip on your shield to see which one it is. If it's the ENC28J60, then you will need to use a different library. The two most popular are called UIPEthernet and EtherCard. I have only used UIPEthernet but the author of that library has abandoned it. EtherCard has recently started to be actively maintained. The nice thing about UIPEthernet is that it has an API compatible with the Ethernet library, so it's very simple to modify sketches written for the Ethernet library. EtherCard has a different API. However, it does come with a bunch of example sketches.

Thank you pert,

pert:
HanRun is just the manufacturer of the RJ45 jack on the board. That name is not really relevant when describing an Ethernet shield. What's important is which Ethernet controller chip is used on the shield.

Ah, thank you for specifying.

pert:
Some Ethernet shields have a unique MAC address on a sticker. For the shields without a sticker, you can make up any MAC address you like as long as it's unique on the network the Ethernet shield is connected to. No Ethernet shields have an IP address on a sticker. That wouldn't make sense because the IP address depends on the network the shield is connected to. You can set the shield to use any static IP address on your network as long as no other devices on the network are already using that address.

Thank you for specifying that as well, I suppose that wouldn't make sense.

pert:
What's important is which Ethernet controller chip is used on the shield. The common chips are W5100, W5200, W5500, ENC28J60

Okay, it looks like I have the W5100, based on what I am reading on the control chip.

pert:
It's no longer necessary to use the Ethernet2 library for an Ethernet shield with the W5500. You can check the version of your Ethernet library at Sketch > Include Library > Manage Libraries...

Okay, so it did look like I had an older version of the library (1.2 I believe), and through updating it to the newest version, I am now getting some response on the serial monitor. Unfortunately, it is "Failed to configure Ethernet using DHCP", however this is progress. What is the most-common cause of this issue? I have set the MAC address to my own custom one, and my Ethernet board is plugged directly into my router (I read that it won't work if it's plugged into the ethernet adaptor on my laptop).

Thank you for the detailed response.

Avoid setting an IP if you can as it is not always needed and more so with DHCP.
Ensure your router is offering DHCP would be the first step.

Have had occasions where also not defining the MAC has helped too on some older boards.

It wont work through the laptop unless you have the laptop set up itself to offer DHCP (can be done but not a beginner topic)

Also check your router LOG for any signs in there of a problem such as an out of range / subnet IP or some other form of refusal error.

DHCP will cause the sketch to use significantly more memory. On the other hand, it might make getting started a bit easier since it eliminates the problem of using an incorrect static IP address.