Ethernet Shield w5500

Hi!

I have been having problems with my Ethernet shield which I got from RS Components here:
http://au.rs-online.com/web/p/processor-microcontroller-development-kits/8732285/+

The problem is that when I upload the Web Server sketch to my shield, which is stacked on top of my Arduino Uno, all that comes up on the Serial Monitor is:

server is at 10.0.0.139

and when I go to that ip address, my browser says it can't reach the page.

I have only made two modifications to the program, the MAC address which I have changed to the one on the sticker on the bottom of the shield, and the ip address to 10.0.0.139 as my computer's ip is 10.0.0.101

I have used this code in another post and it turned out fine:

SurferTim:
Then try this code. It checks the SPI side of the w5200. If the serial monitor shows 192.168.0.2, then the SPI side is working. If it shows anything else, the SPI side has failed.

#include <SPI.h>

#include <EthernetV2_0.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,2);

void setup() {
  Serial.begin(9600);

// disable SD card if one in the slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

Serial.println("Starting w5200");
  Ethernet.begin(mac,ip);

Serial.println(Ethernet.localIP());
}

void loop() {
}

I hope someone can help me so if you need extra information about the problem, please let me know!

Thanks!

The EthernetV2_0 library is for W5200, not W5500. If you're using the arduino.org IDE then you can just change the line:

#include <Ethernet.h>

to:

#include <Ethernet2.h>

If you're using the arduino.cc (this website) IDE, which I would highly recommend, then you only need to install an Ethernet library that supports the W5500. There are a few choices:

Ethernet2 library - this is the same library included with the arduino.org IDE with a little extra work done on it by Adafruit I think.

  • Sketch > Include Library > Manage Libraries
  • In the "Filter your search" box type "Ethernet2"
  • Click on Ethernet2
  • Click "Install"
  • Click "Close"
  • change the line #include <EthernetV2_0.h> in your sketch to:#include <Ethernet2.h>

EthernetMod W5x00 branch - This supports W5100, W5200, and W5500 without needing any modifications
GitHub - per1234/EthernetMod at W5x00 follow the installation instructions on that page. Change the line #include <EthernetV2_0.h> in your sketch to:#include <Ethernet.h>

Wiznet Ethernet Library - GitHub - Wiznet/WIZ_Ethernet_Library: WIZnet Ethernet Library this is already set up to support the W5500 but unlike the other two libraries you need to do a manual installation so let me know if you want to use that one and need help with installation.

Hi!

I forgot to let you know that I have downloaded the Ethernet2 library and changed the included library to Ethernet2.h. I am using the Arduino.cc IDE 1.6.5.

I hope that helps.

Thanks!

Hi!

One more thing I forgot, I want to ask if it is possible to connect the shield directly to the computer because the router is about 10 metres away and I don't have a long enough USB or Ethernet cable.

Thanks!

Hi!

I don't know how many things I will forget so forgive me for my memory. When I used the DhcpAddressPrinter, the result I got from the Serial Monitor is:

Failed to configure Ethernet with DHCP

So the ip address in the Web Server sketch I used is made up.

Thanks!

If you don't have a DHCP server on the localnet, that is not unusual.

The code in your first post will not respond to a browser request. You don't have any server code uploaded. Check out the example included with the IDE.

I have a server example in the playground. The second example on this page might be enough for you.
http://playground.arduino.cc/Code/WebServerST

itssohard:
One more thing I forgot, I want to ask if it is possible to connect the shield directly to the computer because the router is about 10 metres away and I don't have a long enough USB or Ethernet cable.

My understanding is that yes, you can connect the Ethernet cable from the shield directly to your computer, but I haven't actually tried it.

itssohard:
Hi!

One more thing I forgot, I want to ask if it is possible to connect the shield directly to the computer because the router is about 10 metres away and I don't have a long enough USB or Ethernet cable.

Thanks!

unless the port in your computer is auto-switching, you will need a ethernet crossover cable, you will also need to set the ip addresses on both the computer and shield rather than relying on dhcp.

That's interesting, I knew that W5100 has auto MDIX so I assumed the newer W5500 would also have that feature but I just checked the datasheet and W5500 does not support auto MDIX.

Hi!

I would want to know if a specific type of crossover cable is needed, which side I will need to connect to the shield and how to set the ip address for my shield. Also, this is the code from SurferTim which I have modified:

/* 
   Web server sketch for IDE v1.0.3 and w5100/w5200
   Originally posted October 2012 by SurferTim
   Modified 6 June 2015 by SurferTim
*/

#include <SPI.h>
#include <Ethernet2.h>
// uncomment next line if using SD
// #include <SD.h>

// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x04, 0xBA };

// change to your network settings
IPAddress ip( 10,0,0,139 );
IPAddress gateway( 10,0,0,138 );
IPAddress subnet( 255,255,255,0 );

EthernetServer server(80);

void setup()
{
  Serial.begin(9600);

  // disable w5100 while setting up SD
  // uncomment next 4 lines if using a microSD card

  //  digitalWrite(10,HIGH);
  // Serial.print(F("Starting SD.."));
  // if(!SD.begin(4)) Serial.println(F("failed"));
  // else Serial.println(F("ok"));

  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  delay(2000);
  server.begin();
  Serial.println(F("Ready"));
}

void loop()
{
  EthernetClient client = server.available();
  if(client) {
    boolean currentLineIsBlank = true;
    boolean currentLineIsGet = true;
    int tCount = 0;
    char tBuf[64];
    int r,t;
    char *pch;

    Serial.print(F("Client request: "));

    // this controls the timeout
    int loopCount = 0;

    while (client.connected()) {
      while(client.available()) {
        // if packet, reset loopCount
        loopCount = 0;
        char c = client.read();

        if(currentLineIsGet && tCount < 63)
        {
          tBuf[tCount] = c;
          tCount++;
        }

        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response
          Serial.println(tBuf);
          Serial.print(F("POST data: "));
          while(client.available()) Serial.write(client.read());
          Serial.println();

          pch = strtok(tBuf,"?");

          while(pch != NULL)
          {
            if(strncmp(pch,"t=",2) == 0)
            {
              t = atoi(pch+2);
              Serial.print("t=");
              Serial.println(t,DEC);             
            }

            if(strncmp(pch,"r=",2) == 0)
            {
              r = atoi(pch+2);
              Serial.print("r=");              
              Serial.println(r,DEC);
            }


            pch = strtok(NULL,"& ");
          }
          Serial.println(F("Sending response"));
          client.print(F("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<html>"));

          client.println(F("<head><script type=\"text/javascript\">"));
          client.println(F("function show_alert() {alert(\"This is an alert\");}"));
          client.println(F("</script></head>"));


          client.println(F("<body><H1>TEST</H1>"));

          client.println(F("<form method=GET onSubmit=\"show_alert()\">T: <input type=text name=t>
"));
          client.println(F("R: <input type=text name=r>
<input type=submit></form>"));


          client.println(F("</body></html>"));
          client.stop();
        }
        else if (c == '\n') {
          currentLineIsBlank = true;
          currentLineIsGet = false;
        } 
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }

      loopCount++;

      // if 10000ms has passed since last packet
      if(loopCount > 10000) {
        // close connection
        client.stop();
        Serial.println("\r\nTimeout");
      }

      // delay 1ms for timeout timing
      delay(1);
    }
    Serial.println(F("done"));
  }
}

I just want to check what I'm supposed to type in the address bar now and if the ip is supposed to be my computer's ip, the ip that which I have chosen or some other ip.

Thanks!

The IP address of the shield must be within the localnet range and unique to the localnet. So do not use the IP of the PC or any other device on your localnet.

Hi!

Sorry I haven't been replying, I have also used this code from another post:

#include <SPI.h>
#include <Ethernet2.h>

byte mac[] = {  0x90, 0xA2, 0xDA, 0x10, 0x04, 0xBA };

void setup() {
 Serial.begin(9600);

 // disable SD SPI
 pinMode(4,OUTPUT);
 digitalWrite(4,HIGH);

 Serial.print(F("Starting ethernet..."));
 if(!Ethernet.begin(mac)) Serial.println(F("failed"));
 else {
     Serial.println(Ethernet.localIP());
     Serial.println(Ethernet.gatewayIP());
 }
}

void loop() {
}

The serial monitor shows:

Starting ethernet...failed

Is there a reason why it says that?

Thanks!

Either because you are using the incorrect library for the W5500, your hardware is connected incorrectly, or there is no DHCP server on your localnet.

Hi!

May I know how I can find out if there is a DHCP server in my localnet? Also, I am using the Ethernet2 library which is for the W5500, isn't it?

Thanks!

itssohard:
I am using the Ethernet2 library which is for the W5500, isn't it?

Correct.

pert:
That's interesting, I knew that W5100 has auto MDIX so I assumed the newer W5500 would also have that feature but I just checked the datasheet and W5500 does not support auto MDIX.

The 5100 and the 5200 both have Auto-MDX, but alas, the 5500 does not. WizNet also changed some other memory and interface features too.

Hi!

I just found out how to see if I have a DHCP server and I do! Why doesn't the address printer work then? What can I do to make it work?

Thanks!

This is the library I recommend.

Hi!

SurferTim, I have downloaded the library and tried the address printer and the web server examples and both did not work. May I know what the difference is between this library and the Ethernet2 as well as what I do now?

Thanks!

The Wiznet library has some changes the Ethernet2 library does not have. It is also compatible with all Wiznet ICs by changing a define. It is set ti the w5500 as the default.

Compile and run this test code. It should display 192.168.0.2 on the serial monitor. If it does, the SPI bus side of the w5500 is ok. If not, you have a problem on the SPI side of the Wiznet IC, or the library is incorrect..

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

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,2);

void setup() {
  Serial.begin(9600);

  // disable SD card if one in the slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.println("Starting ethernet");
  Ethernet.begin(mac,ip);

  Serial.println(Ethernet.localIP());
}

void loop() {
}

If that works, then try this DHCP code.

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

byte mac[] = {  0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

void setup() {
  Serial.begin(9600);

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.print(F("Starting ethernet..."));
  if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  else {
      Serial.println(Ethernet.localIP());
      Serial.println(Ethernet.gatewayIP());
  }
}

void loop() {
}