Failed to configure Ethernet using DHCP

Hi All,
I've got an arduino uno 3 with a Ethernet shield on it with a w5100 chip I think.
I've uploaded the DHCPaddressprinter example as per most tutorials, but when I run it I get the following message
"Failed to configure Ethernet using DHCP"

The green and orange led's on the ethernet adapter is constant on and when I load the sketch the led's on the board (6 of them) flicker, so it looks like it's all relatively ok.

Any idea why I can't get it to work, below is the sketch.

any help would be great

#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 Leonardo 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(;:wink:
;
}
// print your local IP address:
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();
}

void loop() {

}

Another version you can try. Use the # in the tool bar to put your code in a code box to avoid the emoticons.

//open serial monitor to see assigned IP address

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

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

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

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

  Serial.println("Starting w5100...");
  if(!Ethernet.begin(mac)) Serial.println("failed");
  else Serial.println(Ethernet.localIP());
}

void loop() {

}

thanks zoomkat, tried that with the results below:

Starting w5100...
failed

any other ideas?

When plugged into my router, my Ethernet shield has a red and three yellow LEDs lit, and a green LED that blinks. Do you see something similar?

I have the red (at the bottom of the board) and 3 yellow ones constantly on and the tx will flash every now and again. I don't have a green one blinking as it would on the two led's on the back of a router

dippies:
thanks zoomkat, tried that with the results below:

Starting w5100...
failed

any other ideas?

Some switches and routers are not compatible with W5100 ethernet interface. I have real experience with HP ProCurve Switch 1800-24G - never working with Ethernet Shield (also not working with new models of Ruckus Wireless AP), so I had to use $10 switch as "bridge" between backbone network and Arduinos and APs.

On my router, DHCP can be switched off..... You sure yours is configured for DHCP?

I have it connected to a router now and when I go to the Ethernet connection in my control panel and look under ipv4, dhcp is enabled, but when I do a <ipconfig /all> it says 'DHCP enabled : no'

when it's connected directly to my laptop I cannot se the connection under network and sharing

Try the below code and see if you get a response.

//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

}

Still get this:

"Failed to configure Ethernet using DHCP"

It's driving me nuts... hahaha suffer- suffer - suffer

Could it be due to me running windows 8.1?

Have you gone into your router's setup to see if the arduino is identified as a connected device?

It's not connecting to the router

Got it back connected directly to the pc. and I can now see the connection.
Below is from ipconfig /all

Ethernet adapter Ethernet:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Realtek PCIe GBE Family Controller
Physical Address. . . . . . . . . : 84-34-97-18-E4-1B
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::b844:f5a9:a33:e85%4(Preferred)
Autoconfiguration IPv4 Address. . : 168.254.14.132(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
DHCPv6 IAID . . . . . . . . . . . : 75773079
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1A-3B-D0-C1-84-34-97-18-E4-1B

DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
fec0:0:0:ffff::2%1
fec0:0:0:ffff::3%1
NetBIOS over Tcpip. . . . . . . . : Enabled

all the lights seem to be flashing so it does not look like it is broken.... or is it?

dippies:
Autoconfiguration IPv4 Address. . : 168.254.14.132(Preferred)

Now it is obvious that you do not understand how networks work. PC normally does not work as a DHCP server. PC acts as a DHCP client. Arduino acts as a DHCP client. Connect PC and Arduino together means that both are waiting for the DHCP server. And wait forever.

You'd have to set a fixed IP for the PC (for example, 192.168.1.1) and a fixed IP for Arduino (for example, 192.168.1.2) and both set to the same network mask (for example, 255.255.255.0). Otherwise it will never work.

totally agree, I know very little more than some basic trouble shooting on networks, nor did I know that the arduino is a client to. thanks I'll give it a go tomorrow or later tonight!
apologies for my lack o network knowledge... :cold_sweat:

Nobody is a scholar fallen from the sky, and this can be learned. Try to study and understand what is IPv4 IP address and subnet mask and how to set mode "I always have the same fixed IP address" and mode "I get an IP address from the nearest DHCP server" (two variants: always the same IP and always different IP).

(I apologize for my Grammar. I never learned English at school.)

Yeah, did some reading and got it all working now.

thanks all!

Damn Proxies....

Hey how did you finally got working ?
Can you give details ?

Thanks in advance.

Would yo be able to run me through how you give them fixed ip addresses so the pc becomes the dchp server?