Question

I have been desesperately trying to run the Ethernet > DHCPAddressPrinter example on my Arduino uno mounted with an Ethernet Shield but to no effect, every time I run it it returns me the error

Failed to configure Ethernet using DHCP

I have tried all sorts of things, that are disabling the firewalls, resetting the board/shield, in start it gave me an ip but that was the only one time, i switched off the router and when i turned it on since then i cannot assign a MAC and IP to the Ethernet shield.

Does anybody know how to solve this problem?

Here is the sketch im trying to run

/*
  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[] = {  
  0xDE, 0xAD, 0xBD, 0xEF, 0xFE, 0xED 
};

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

}
Was it helpful?

Solution

Does the network you are connecting to have a dhcp server on it, usually routers are set up to be one. If not you must assign a static ip to your arduino.

this can be done like so using the Ethernet libray

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,177); // make sure this is in the subnet of your network
EthernetClient client;
Ethernet.begin(mac, ip);

it looks like you just need to print the ip not get every byte. From Ethernet.localIp() documentation

// print your local IP address:
   Serial.println(Ethernet.localIP());

Also can you try the webServer example. And then see if you can navigate to the ip that gets printed out in your browser (hopefully not 0.0.0.0)

OTHER TIPS

If your Ethernet card has a SD slot, make sure there is no SD card in it, or follow the advise on this blog: http://startingelectronics.com/tutorials/arduino/ethernet-shield-web-server-tutorial/basic-web-server/

    pinMode(4, OUTPUT);
    digitalWrite(4, HIGH);

For the Seeed Studio V2.4, be sure to use the library found here: https://github.com/Seeed-Studio/Ethernet_Shield_W5200

I was seeing this same problem. My Seeed Studios Ethernet Shield v2.4 was reporting incorrect IP addresses. I saw 0.0.0.0 and other odd values. I thought it interesting that using the standard/default Arduino Ethernet Shield library for another company's shield gave any results, let alone numbers in the correct format for an IP address. I fixed this by downloading the correct library for my model and revision of Ethernet Shield (see link above).

I hope this helps... Mike

MAC addresses are not arbitrary. The two least significant bits of the 1st byte of the MAC address that are important - what I think of as the 7th and 8th bit:

??????XY:????????:???????? ????????:????????:????????

where ? represents any bit in the mac address, and X is the "U/L bit" and Y is the Uni/multi cast bit

If the the eighth bit of a MAC address is 1, devices may have trouble getting IP addresses using DHCP. If the eighth bit of a MAC address is 0, you may have more luck.

The 7th and 8th bit of MAC addresses are special: Bit 8 == 0 for unicast Bit 8 == 1 for multicast

Bit 7 is also special - 0 = globally unique (assigned to a manufacturer to use) and 1 = locally administered (we should use these addresses!)

This Wikipedia article explains: MAC Adresses Wikipedia

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top