Failed to configure Ethernet using DHCP

Hi,

I am in trouble because with the ethernet shield the serial monitor reply always "Failed to configure Ethernet using DHCP"
The ide is the 1.01 and the router id a d-link.

the sketch:

/*
  DHCP-based IP printer
 
 This sketch uses the DHCP extensions to the Ethernet library
 to get an IP address via DHCP and print the address obtained.
 using an Arduino Wiznet Ethernet shield. 
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 12 April 2011
 modified 9 Apr 2012
 by Tom Igoe
 
 */

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

}

Some test code to try:

//zoomkat 2-13-12
//DNS and DHCP-based web client test code
//for use with IDE 1.0
//open serial monitor and send an e to test
//and to see test result
//for use with W5100 based ethernet shields
//browser equivelant URL: 
// http://web.comporium.net/~shb/arduino.txt
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 

#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(){
  Serial.begin(9600); 
  Serial.println("DNS and DHCP-based web client test 2/13/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
  // 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:
    while(true);
  }
  // print your local IP address:
  Serial.print("Arduino 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();
  Serial.println();
}

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.0"); //download text
    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

}

Do you have a memory card in the microSD slot? If so, power down the Arduino and remove the memory card, then try it again.

zoomkat:
Some test code to try:

//zoomkat 2-13-12

//DNS and DHCP-based web client test code
//for use with IDE 1.0
//open serial monitor and send an e to test
//and to see test result
//for use with W5100 based ethernet shields
//browser equivelant URL:
// http://web.comporium.net/~shb/arduino.txt
//note that the below bug fix may be required
// Google Code Archive - Long-term storage for Google Code Project Hosting.

#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(){
  Serial.begin(9600);
  Serial.println("DNS and DHCP-based web client test 2/13/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
  // 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:
    while(true);
  }
  // print your local IP address:
  Serial.print("Arduino 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();
  Serial.println();
}

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.0"); //download text
    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

}

Thanks for help!!
I tried this sketch but the serial monitor replies:

DNS and DHCP-based web client test 2/13/12
Send an e in serial monitor to test
Failed to configure Ethernet using DHCP

About the shield ethernet , it doesn't include a micro sd slot.

No microSD slot? Does the ethernet shield have a w5100 or enc28j60 processor? Maybe a link to that shield would help.

SurferTim:
No microSD slot? Does the ethernet shield have a w5100 or enc28j60 processor? Maybe a link to that shield would help.

Yes mate, it's enc28j60 processor.Thanks I know about it now. So I downlaoded the library ErtherCard from GitHub - njh/EtherCard: EtherCard is an IPv4 driver for the ENC28J60 chip, compatible with Arduino IDE ,but IT doesn't work too :frowning:

I loaded this sketch:

// Ping a remote server, also uses DHCP and DNS.
// 2011-06-12 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <EtherCard.h>

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[700];
static uint32_t timer;

// called when a ping comes in (replies to it are automatic)
static void gotPinged (byte* ptr) {
  ether.printIp(">>> ping from: ", ptr);
}

void setup () {
  Serial.begin(9600);
  Serial.println("\n[pings]");
  
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);

#if 1
  // use DNS to locate the IP address we want to ping
  if (!ether.dnsLookup(PSTR("www.google.com")))
    Serial.println("DNS failed");
#else
  ether.parseIp(ether.hisip, "74.125.77.99");
#endif
  ether.printIp("SRV: ", ether.hisip);
    
  // call this to report others pinging us
  ether.registerPingCallback(gotPinged);
  
  timer = -9999999; // start timing out right away
  Serial.println();
}

void loop () {
  word len = ether.packetReceive(); // go receive new packets
  word pos = ether.packetLoop(len); // respond to incoming pings
  
  // report whenever a reply to our outgoing ping comes back
  if (len > 0 && ether.packetLoopIcmpCheckReply(ether.hisip)) {
    Serial.print("  ");
    Serial.print((micros() - timer) * 0.001, 3);
    Serial.println(" ms");
  }
  
  // ping a remote server once every few seconds
  if (micros() - timer >= 5000000) {
    ether.printIp("Pinging: ", ether.hisip);
    timer = micros();
    ether.clientIcmpRequest(ether.hisip);
  }
}

some problems:

  1. the original sketch has 57600 baud rate , but with this value the serial monitor shows odd characters.
    so I changed 57600 to 9600 (only this one works).

2)Mostly the sketch(on the serial monitor) breaks with the first print "Ping"

  1. sometimes (one time so far) it written
    Failed to access Ethernet controller,
    etc,,
    with all values at 0.0.0.0 , clearly.

So I am in trouble again :frowning:

I build a homemade board with a 328 and the ENC and is working great.

But some examples from ethercard are not working, all most some function at the library are missing.

The example that I can't compile is this:

GetDHCPandDNS

The function that I can't found is this:

ether.dhcpExpired()

Other thing is use the reset pin from the ENC before do the DHCP procedure.

Best Regards
Frank

So, how does one use both the Ethernet connection on DHCP and use a card in the microSD slot? I'd like to connect to a server and write some data from that server to the card. It sounds like the microSD card makes the DHCP address assignment fail. I'm seeing this behavior on my Arduino UNO. Does anyone have any examples of code using both simultaneously?

DHCP and "server" may not play well together. You generally need to assign an IP address to the server so a client will have a knowm IP address to connect to. The below discussion has some server and SD card code.

http://arduino.cc/forum/index.php/topic,144675.0.html

You must disable one to start the other. See if this code starts the SD and w5100 ok for you.

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

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

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

  // disable w5100 SPI while starting SD
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);

  Serial.print(F("Starting SD..."));
  if(!SD.begin(4)) Serial.println(F("failed"));
  else Serial.println(F("ok"));

  Serial.print(F("Starting ethernet..."));
  if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  else Serial.println(Ethernet.localIP());
  digitalWrite(10, HIGH);
}

void loop() {
}

I used the F() function to keep the static strings in program memory.

Hi,

I have the same problem and tested all the codes you mentioned above. Besides, I connected my shield to PC and read the MAC add because I thought maybe wrong MAc add will give the DHCP config error. I have no SD card and these LEDs are on:
LINK
100M
FULLD
I always get theis error:
Failed to configure Ethernet using DHCP
What should I do?
The code I test:

#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, 0x06, 0x4F, 0x0D, 0xAC, 0xA9 };

// 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() {
  // start the serial library:
  Serial.begin(9600);
  // 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:
  Serial.println(Ethernet.localIP());

}

void loop() {

}

Hi. I am new to arduino and had decided to build a automated door lock using an ethernet shield. Initially everything worked perfectly, my ethernet shield was working and I could control an led using an app over the ethernet. However, when I made the connections for my door lock, which involves inputting a 12V-1A power supply to the door lock(I used a diode to protect my circuit), initially the shield worked but in a few seconds it lost internet connection and was giving 255.255.255.255 as an output to the command
Serial.println(Ethernet.localIP());

I had by mistake used the pin 10 as a general I/O pin to control my door lock. Also, I realized later that my circuit was faulty however I don't think that caused the problem since the arduino UNO is working properly.
So now my ethernet shield returns "Failed to configure Ethernet using DHCP" whenever I run the DhcpAddressPrinter example. The state of the LEDs are:
pwr-RED
LINK-Yellow
100M-Yellow
FULLD-yellow
Coll-none
The RX blinks whenever I upload a sketch. Also, my shield is not being listed on my routers DHCP client list which it was earlier.
My doubts are:

  1. Does using pin 10 as a general I/O destroy the shield permanently?
  2. If not, then what is the solution to this?

The problem is:

you´re trying to load the code to your arduino with the ethernet shield connected on it.
First, load the code just to arduino board, without the shield plugged.
After the code is loaded, you connect the shield.

bernardocaioBR:
The problem is:

you´re trying to load the code to your arduino with the ethernet shield connected on it.
First, load the code just to arduino board, without the shield plugged.
After the code is loaded, you connect the shield.

I don't need to do that. Mine works fine with the ethernet shield connected.

What micro-controller are you using? I had the same issue but found out that mine doesnt come with the ISP pins required to connect to the Ethernet shield. It has the slots for the ISP header but doesnt have the pins. I simply soldered pins into the ISP slots and connected directly to the associated pins on the Ethernet shield. This would be located in the back of both the Ethernet shield and the Microcontroller you are using. The connector for the pins is located on the bottom middle of the Ethernet shield. My Micro-controller is a Redboard which is basically an Arduino Uno so the ISP slots were located in the back middle part of the board labeled ISP next to the ON LED.

hi,
i am using arduino uno r3 and ethernet shield w5100 in my project.
i want connect this shield to internet using laptop, modem and switch. my code looks like this
/*
DHCP Chat Server

A simple server that distributes any incoming messages to all
connected clients. To use telnet to your device's IP address and type.
You can see the client's input in the serial monitor as well.
Using an Arduino Wiznet Ethernet shield.

THis version attempts to get an IP address using DHCP

Circuit:

  • Ethernet shield attached to pins 10, 11, 12, 13

created 21 May 2011
modified 9 Apr 2012
by Tom Igoe
Based on ChatServer example by David A. Mellis

*/

#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.
// gateway and subnet are optional:
byte mac[] = {
0x09, 0xBA, 0xCB, 0xFC, 0xDE, 0x05
};
IPAddress ip(192, 168, 0, 105);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);

// telnet defaults to port 23
EthernetServer server(23);
boolean gotAMessage = false; // whether or not you got a message from the client yet

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:
Serial.println("Trying to get an IP address using DHCP");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// initialize the ethernet device not using DHCP:
Ethernet.begin(mac, ip, gateway, subnet);
}
// print your local IP address:
Serial.print("My IP address: ");
ip = Ethernet.localIP();
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(ip[thisByte], DEC);
Serial.print(".");
}
Serial.println();
// start listening for clients
server.begin();

}

void loop() {
// wait for a new client:
EthernetClient client = server.available();

// when the client sends the first byte, say hello:
if (client) {
if (!gotAMessage) {
Serial.println("We have a new client");
client.println("Hello, client!");
gotAMessage = true;
}

// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to the client:
server.write(thisChar);
// echo the bytes to the server as well:
Serial.print(thisChar);
}
}

in the serial print it is displaying,
Trying to get an IP address using DHCP
Failed to configure Ethernet using DHCP
My IP address:192.168.0.105

only this much it is displaying. please can any help me to sort out this

djberzerk:
What micro-controller are you using? I had the same issue but found out that mine doesnt come with the ISP pins required to connect to the Ethernet shield. It has the slots for the ISP header but doesnt have the pins. I simply soldered pins into the ISP slots and connected directly to the associated pins on the Ethernet shield. This would be located in the back of both the Ethernet shield and the Microcontroller you are using. The connector for the pins is located on the bottom middle of the Ethernet shield. My Micro-controller is a Redboard which is basically an Arduino Uno so the ISP slots were located in the back middle part of the board labeled ISP next to the ON LED.

I have the same issue and I am using aurduino uno R3 below is the link of purchase:

ethernetshield w5100 but I didn.t get any mac address with it may be seller forgot to provide it .below is the link for device

Kindly help me how to overcome with the issue ''failed to connect using DHCP" while using example sketch of addresss printer

Which shield are you using? Are you certain it is a w5100 controller?

I have same problem "Failed to configure Ethernet using DHCP".... Your all answers are so different... any one tell me, what can i do???

Scaurus:
Hi,

I am in trouble because with the ethernet shield the serial monitor reply always "Failed to configure Ethernet using DHCP"
The ide is the 1.01 and the router id a d-link.

the sketch:

/*

DHCP-based IP printer

This sketch uses the DHCP extensions to the Ethernet library
to get an IP address via DHCP and print the address obtained.
using an Arduino Wiznet Ethernet shield.

Circuit:

  • Ethernet shield attached to pins 10, 11, 12, 13

created 12 April 2011
modified 9 Apr 2012
by Tom Igoe

*/

#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() {

}

You can confirm the ethernet shield has a w5100 controller. Some have w5200, w5500, or enc28j60 controllers.