Failed to configure Ethernet using DHCP

I've been perusing the forums on this topic but still have yet to find out why my setup won't work, so I thought I'd be a little more direct.

Anyway, I'm fairly new to Arduino in general so forgive my naivete. Here we go:

I've plugged my ethernet shield (HanRun HR911105A 12/11) into my arduino uno, made all the connections (USB to my Mac OS X laptop, ethernet to the router using a one to one cable) and uploaded the DhcpAddressPrinter sketch. After waiting a while I'll eventually see the "Failed to configure Ethernet using DHCP" message. Also, the RX,100M,FULLD, and LINK LEDs appear to pulse at regular intervals with TX and COLL remaining off.

Also, whenever the ethernet cable has been plugged in for a while the RX, 100M, and FULLD LEDs are lit, with the LINK LED flashing. The rest (TX and COLL) are off

When I check the router the light corresponding to the the plug I'm using for the arduino blinks (which I thought should indicate some sort of interaction).

I then tried the WebServer sketch and assigned the Arduino a static IP. The router light still blinks but if I try to ping the IP address from the router admin section nothing is getting through. It does output the IP I assigned with Serial.println(), but if I navigate to that IP address on my laptop (that is on the same network) it can't find anything.

I'm thinking that anything I do with Ethernet.begin() just isn't connecting... Does anyone have any suggestions? Any help is appreciated

getting an address from the router is only going to work, if the router is authorised to hand out addresses using dhcp. Do you know that yours does ?

The blinking light next to the ethernet cable plug doesn't seem to mean very much, it seems to only mean that the other end of the cable is plugged into something. Mine blink even when the computers are turned off.

I'm pretty sure it is authorized, but I could be mistaken. Within the router's settings the Internet Connection Type is set to "Automatic Configuration - DHCP" and the DHCP Server is enabled.

This sketch tests the connection between the Arduino and the ethernet shield. I presume the shield is a w5100, and not an ENC28j60. Don't change anything. It is just a test. Upload it and check the serial monitor. If it shows anything but 192.168.2.2, then you have a problem with the SPI or w5100..

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

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

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

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

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

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

void loop() {
}

You are correct, it is a w5100. Anyway, I ran the code you suggested and the output to the serial monitor was 192.168.2.2. I'm guessing that means that the problem is elsewhere, but I have no idea what I need to do next to fix it.

Thanks in advance for the help (and for the help you all have already given)

Have you tried a different cable? What make/model router are you connecting it to?

Does your computer connect to the same router? Does it use dhcp to get an ip?

edit: Do you have a SD card in the slot if the shield has one? If so, remove it for a test.

I'll have to try a new cable when I get back home, though I was able to use the same cable for a wired connection on my laptop (if that means anything). As for the router, it's a linksys E1000, and my computer does use dhcp to get an ip.

And no, I haven't been making use of the SD card slot, as I remember reading somewhere on these forums that the two cannot operate at the same time. So I haven't had a SD card in the slot.

The ethernet and SD can operate in the same sketch. They just need to be initialized correctly. If you do not disable or initialize the SD, it will cause the dhcp request from the w5100 to fail.

Oh, my mistake, thanks for clearing that up.

So I finally was able to try another cable, while using the WebServer sketch and came up with the same problem. Any attempts to ping the static ip (or load the ip address from my laptop) still failed.

You can try the below code to see if you get a response from the server. If you get a response your issue may be code related instead of your network/hardware setup.

//zoomkat 9-22-12
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//remove SD card if inserted

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

char serverName[] = "web.comporium.net"; // zoomkat's test web page server
EthernetClient client;

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

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600); 
  Serial.println("Better client test 9/22/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

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

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.1"); //download text
    client.println("Host: web.comporium.net");
    client.println("Connection: close");  //close 1.1 persistent connection  
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

@zoomkat: You are still using this buggy code?

  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

I pointed this out to you here:
http://forum.arduino.cc/index.php?topic=201186.msg1487043#msg1487043

I tried zoomkat's code and didn't get any output to the Serial monitor. So I'm not sure what's up. From what I followed in the code I don't think that my arduino was getting to a point where the discussion between SurferTim and zoomkat came in to play, but I could be mistaken.

rauddm:
I tried zoomkat's code and didn't get any output to the Serial monitor. So I'm not sure what's up. From what I followed in the code I don't think that my arduino was getting to a point where the discussion between SurferTim and zoomkat came in to play, but I could be mistaken.

You are not there yet. I was bringing that to zoomkat's attention. It caused a problem in a previous topic that caused a bunch of funny ys in the output. Funny y = ÿ = 255 = -1 = no characters available

However, zoomkat's code should have produced the "Failed to configure Ethernet using DHCP" on your serial monitor within a couple minutes if there was no dhcp server or the network connection failed. If it didn't, you have other problems, probably related to the SPI bus. That is why I asked about the SD card earlier.

When I tried zoomkat's code I didn't even get the prompt to type e to run the test. I did send an "e" anyway, but still there was no output to the serial monitor. That seems like it might be a bad omen, especially since I waited a substantial amount of time before throwing in the towel

Try this dhcp test sketch. It is stripped down to the basic code. Do you get "failed" or the dhcp IP?

#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());
}

void loop() {
}

edit: It may take a couple minutes to return "failed" if it fails. That is a dhcp request timeout thing. If you wait more than a few minutes and you still get nothing, then the SPI or the w5100 has failed.

Make sure the shield is well seated on the Arduino, especially the 2x3 ICSP header. I have both of mine screwed down at that location to ensure they stay seated.

When I ran that last sketch the display to the serial monitor was "Starting ethernet...failed" granted there was a period of time before the word failed was appended.

I did also check to see that the ethernet shield was well seated on the arduino and as far as I can tell it is.

Then try this code. It should assign 192,.168.1.2 to your Arduino. Once you run this code, try to ping 192.168.1.2 from your computer.

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

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

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

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

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

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

void loop() {
}

When I tried the new block of code the IP address was printed on the Serial Monitor, however when I tried to ping the arduino I got nothing. More specifically:

--- 192.168.1.2 ping statistics ---
17 packets transmitted, 0 packets received, 100.0% packet loss

On a side note, this time when I plugged it all in I got a new prompt that I haven't seen before. I'm working from a mac and when I plugged the arduino in i was informed that the USB Modem 2 was not configured... Hopefully that's helpful

It appears you have a problem with your w5100 device. I wish I could be more help, but the tests you tried are all I can do remotely. The SPI bus and the SPI end of the w5100 is working, but the network end is not. :frowning: