Cannot connect to ethernet shield

Hi. I have an Arduino Uno and an Arduino ethernet shield. I have loaded the example web server sketch with a reserved IP address on our network ( I am a network manager). Whilst I can see the TX and RX LEDs flashing, my switch is reporting a MAC address of 00:00:00:00:00:00 on the port the shield is attached to. Also, whilst the switch is counting both RX and TX bytes, I cannot communicate with shield. Ping reports time out and my browser cannot connect to server.

Can anyone help me?

Sure we can...

You have two options regarding how fast we help you:

1 - provide some of the source code and type of Arduino you are using. (I think this is the fastest)
2 - wait until one of us connects mentally to the Ethernet shield to find out the problem. This is slow... not because we don't want to help, but because we do have to find the IP and routing of your shield (and let's hope we don't run into some firewall in the way!).

bubulindo:
Sure we can...

You have two options regarding how fast we help you:

1 - provide some of the source code and type of Arduino you are using. (I think this is the fastest)
2 - wait until one of us connects mentally to the Ethernet shield to find out the problem. This is slow... not because we don't want to help, but because we do have to find the IP and routing of your shield (and let's hope we don't run into some firewall in the way!).

  1. As I mentioned in my post, the board is an Arduino Uno. Are there different version?
    Code is from the Arduino IDE -
/*
  Web  Server
 
 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield. 
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)
 
 created 18 Dec 2009
 by David A. Mellis
 modified 4 Sep 2010
 by Tom Igoe
 
 */

#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 };
byte ip[] = { 192,168,1, 177 };

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

void setup()
{
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop()
{
  // listen for incoming clients
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // 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();

          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(analogRead(analogChannel));
            client.println("
");
          }
          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();
  }
}
  1. Tried it - didn't work.

The next question will be "What is the ip and subnet assigned to the router interface the ethernet shield is on?".
If it is not 192.168.1.1 and 255.255.255.0, the connection will almost certainly fail.

Thanks for your reply. I have been working on this for sometime with little success. I have a nuelectronics ethernet shield which works fine with the arduino Uno.

Subnet 255.255.255.0 and gateway 192.168.1.1. Have tried the shield on other networks, changing IP address accordingly. I don't understand why the shield is announcing a MAC of 00:00:00:00:00:00 even though it has been configured.

You say you have another shield that works.
By any chance, does it have the same mac address assigned?

Good call. Unfortunately no. It has a different MAC.

Also I only have one Uno so they are never on at the same time. Does the 00:00:00:00:00:00 MAC make any sence to you?

How far apart are the mac addresses? Maybe if you used the mac address of the working shield and increment or decrement the last hex set, the router might "see" the new mac address.

That is about all I could suggest. Maybe bubulindo will see something else.

That's a great idea. Unfortunately, still no joy. I really appreciate your help and quick responses. I wonder if I have a duff board.

Could be a bad board. Stuff happens.

The ethernet shield runtime software does not have a lot of error checking. With the "stock" code, you don't know if the ethernet shield is even connected. My version returns from Ethernet.begin() like all went fine, even if the ethernet shield is removed.

There is a fix to that here, if you are willing to try it. The way you use the new Ethernet.begin() function call and replacement files are at reply #11. The install instructions are later.
http://arduino.cc/forum/index.php/topic,73683.0.html

Then Ethernet.begin() returns a value. It returns 0 if the shield did not respond, and 1 if it did.

Had a look at the thread. It looks promising. I will post back with my results.

Thanks for taking time. World needs more people like you.

I will post back with my results.

Please do. I need feedback from users on that function change.

I like it. It did not increase the size of my code much, especially considering the benefit of knowing you are actually communicating with the w5100 chip. Without that change, you are just guessing. I don't care for "just guessing".

Simple server code you can try.

//zoomkat 12-18-10
//routerbot code
//for use with IDE 0021
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html 
//address will look like http://192.168.1.102:84/ when submited
//for use with W5100 based ethernet shields

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

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(84); //server port

String readString; 

//////////////////////

void setup(){

  pinMode(4, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
  Serial.println("servertest1"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  Client client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString);

          //now output HTML data header

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>HTML form GET example</H1>");

          client.println("<FORM ACTION=\"http://192.168.1.102:84\" method=get >");

          client.println("Pin 4 \"on\" or \"off\": <INPUT TYPE=TEXT NAME=\"LED\" VALUE=\"\" SIZE=\"25\" MAXLENGTH=\"50\">
");

          client.println("<INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Change Pin 4!\">");

          client.println("</FORM>");

          client.println("
");

          client.println("</BODY>");
          client.println("</HTML>");

          delay(1);
          //stopping client
          client.stop();

          /////////////////////
          if(readString.indexOf("on") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

@pedro1389: Run zoomkat's code. See if you can ping it then. The pin 13 LED test is not a valid test on an Uno. My bad.

Also let me know about the new Ethernet.begin() function too.

pedro1389:

  1. As I mentioned in my post, the board is an Arduino Uno. Are there different version?
    Code is from the Arduino IDE -

Actually what I meant was what ethernet shield you had. And yes, there are more boards... a Mega, 2009... and the first one that I have no idea what is the name.
Another thing I noticed, but I may be wrong, the nuelectronics shield uses the microchip Ethernet interface. Your code seems to be using libraries for the Wiz5100.
If you google around there is an ARduino library for it.

pedro1389:
2. Tried it - didn't work.

You can connect mentally to your chips? :stuck_out_tongue: LoL

I was trying to think of the best reason for the Ethernet.begin() function to return a pass/fail value, and here it is:

Another thing I noticed, but I may be wrong, the nuelectronics shield uses the microchip Ethernet interface. Your code seems to be using libraries for the Wiz5100.

That chip would not respond, and the function would return fail.

Each ethernet library would be responsible for verifying communication with it's IC, and return a pass/fail value.

It does not take much code. Here is the total code I added:

  if(readTMSR() == 0x55) return 1;
  return 0;

Most of the modifications were to change void return functions to an uint8_t return functions to get the value passed back to the Ethernet.begin() function, and change it from a void return to an uint8_t return function.

I have not had chance to get to the arduino yet surferTIm & zoomkat. Please don't think I am ignoring you. I hope to get to it after work. Hope to post results tonight.

bubulindo:

pedro1389:

  1. As I mentioned in my post, the board is an Arduino Uno. Are there different version?
    Code is from the Arduino IDE -

Actually what I meant was what ethernet shield you had. And yes, there are more boards... a Mega, 2009... and the first one that I have no idea what is the name.
Another thing I noticed, but I may be wrong, the nuelectronics shield uses the microchip Ethernet interface. Your code seems to be using libraries for the Wiz5100.
If you google around there is an ARduino library for it.

I had success with the nuelectronics shield using the library I downloaded. You are correct to say that the code uses the library for the Wiz5100 as this is the shield I am currently experiencing problems with. Thanks for the tip though.

zoomkat:
Simple server code you can try.

//zoomkat 12-18-10

//routerbot code
//for use with IDE 0021
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html
//address will look like http://192.168.1.102:84/ when submited
//for use with W5100 based ethernet shields

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

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(84); //server port

String readString;

//////////////////////

void setup(){

pinMode(4, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

//enable serial data print
  Serial.begin(9600);
  Serial.println("servertest1"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  Client client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

//read char by char HTTP request
        if (readString.length() < 100) {

//store characters to string
          readString += c;
          //Serial.print(c);
        }

//if HTTP request has ended
        if (c == '\n') {

///////////////
          Serial.println(readString);

//now output HTML data header

client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

client.println("");
          client.println("");
          client.println("Arduino GET test page");
          client.println("");
          client.println("");

client.println("

HTML form GET example

");

client.println("<FORM ACTION="http://192.168.1.102:84" method=get >");

client.println("Pin 4 "on" or "off": <INPUT TYPE=TEXT NAME="LED" VALUE="" SIZE="25" MAXLENGTH="50">
");

client.println("<INPUT TYPE=SUBMIT NAME="submit" VALUE="Change Pin 4!">");

client.println("");

client.println("
");

client.println("");
          client.println("");

delay(1);
          //stopping client
          client.stop();

/////////////////////
          if(readString.indexOf("on") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

}
      }
    }
  }
}

Thanks for this zoomkat, alas still no ping. I do get the serial output 'servertest1' but no LED or ping. I have noticed that although the LEDs on the RJ45 socket the link light is on but no activity from the activity LED. I really think that this board is not going to live.

SurferTim:
@pedro1389: Run zoomkat's code. See if you can ping it then. The pin 13 LED test is not a valid test on an Uno. My bad.

Also let me know about the new Ethernet.begin() function too.

Replaced files from post and tried with improved Ethernet.begin().

It would not compile the errors were:

/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/socket.cpp: In function 'uint16_t recvfrom(SOCKET, uint8_t*, uint16_t, uint8_t*, uint16_t*)':
/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/socket.cpp:241: error: no matching function for call to 'W5100Class::read_data(SOCKET&, uint8_t*, uint8_t [8], int)'
/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/w5100.h:141: note: candidates are: void W5100Class::read_data(SOCKET, volatile uint16_t*, volatile uint8_t*, uint16_t)
/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/socket.cpp:253: error: no matching function for call to 'W5100Class::read_data(SOCKET&, uint8_t*, uint8_t*&, uint16_t&)'
/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/w5100.h:141: note: candidates are: void W5100Class::read_data(SOCKET, volatile uint16_t*, volatile uint8_t*, uint16_t)
/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/socket.cpp:260: error: no matching function for call to 'W5100Class::read_data(SOCKET&, uint8_t*, uint8_t [8], int)'
/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/w5100.h:141: note: candidates are: void W5100Class::read_data(SOCKET, volatile uint16_t*, volatile uint8_t*, uint16_t)
/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/socket.cpp:270: error: no matching function for call to 'W5100Class::read_data(SOCKET&, uint8_t*, uint8_t*&, uint16_t&)'
/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/w5100.h:141: note: candidates are: void W5100Class::read_data(SOCKET, volatile uint16_t*, volatile uint8_t*, uint16_t)
/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/socket.cpp:277: error: no matching function for call to 'W5100Class::read_data(SOCKET&, uint8_t*, uint8_t [8], int)'
/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/w5100.h:141: note: candidates are: void W5100Class::read_data(SOCKET, volatile uint16_t*, volatile uint8_t*, uint16_t)
/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/socket.cpp:282: error: no matching function for call to 'W5100Class::read_data(SOCKET&, uint8_t*, uint8_t*&, uint16_t&)'
/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/w5100.h:141: note: candidates are: void W5100Class::read_data(SOCKET, volatile uint16_t*, volatile uint8_t*, uint16_t)