Ethernet.begin(mac) freezes the arduino

I recently purchased my first arduino (Arduino Leonardo Eth) and have made great progress on my project for ultrasonically reading the level of the water in my rain water collection pit. I succeeded in reading the distance and displaying it on the tft screen I purchased.

The goal of the project is to be able to read the water level through the ethernet port.

I'm having trouble running the sample programs (eg. DhcpAddressPrinter). It fails on the command Ethernet.begin(mac).

The code runs up to the command Ethernet.begin, and then freezes the arduino.

I have tried quite a few things, but have come to the point where I don't know where to look further.

I have found the sources of the ethernet library and would like to start debugging to find at which point it freezes

Is there a way debug the Ethernet library source code? (such as Serial.println)

Many thanks in advance for your time!


Sounds like the Arduino is having trouble reaching to the DHCP server. What router do you have the Arduino connected to?

I'm using a us robotics router for dhcp. it has served my home network for many years, and I never had any problems with dhcp...

Do you have a SD card in the slot? That can cause the Ethernet.begin(mac) call to never return. If the dhcp part is failing, it will return a fail in about 2 minutes.

Simple client test code you might try to see if you can get a response from the server. Note that the Leonardo has a different serial start protocol.

//zoomkat 11-04-13
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test client GET
//for use with W5100 based ethernet shields
//remove SD card if inserted
//data from myIP server captured in readString 

#include <SPI.h>
#include <Ethernet.h>
String readString;

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

char serverName[] = ""; // myIP server 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:

  Serial.println("client readString test 11/04/13"); // 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 =; //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
    client.println("GET / HTTP/1.1"); //download text
    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

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c =; //gets byte from ethernet buffer
    readString += c; //places captured byte in readString

  client.stop(); //stop client
  Serial.println("client disconnected.");
  Serial.println("Data from server captured in readString:");
  Serial.print(readString); //prints readString to serial monitor 
  Serial.println("End of readString");
  readString=""; //clear readString variable


@SurferTim - I don't have a sd card in the slot.

@Zoomkat - I will try the code this evening, but from previous tests I assume it will fail in the setup routine, print the "Send an e in...." on the serial monitor, and then stop without printing the "Failed to..." or the "Arduino Ip address..."

I'll let you know

Remember if dhcp fails, it will take about 2 minutes to display the "Failed to configure Ethernet using DHCP" message.

What Ethernet shield do you have? I just saw this exact same issue with one of my coworkers when they bought an "Ethernet Shield 2" which the company makes. We kinda got it to work by switching to their IDE.

Azdle is correct. The Leonardo ETH uses a w5500 ethernet controller. The standard ethernet library will fail.

edit: You must use the IDE provided by for the updated ethernet library.

That's very usefull information. It caused me to do some reading and I now understand some of the difference between and

I was using arduino 1.6.4.

I see on that they mention arduino studio and arduino IDE 1.7.6

I guess I will have to try with one of them. Do you know which one your colleague used? What do you mean by "kind of got it working"?

I have tried all the suggestions, but have had no luck so far.

I tried the ardiuno ide 1.7.6 from, with the source code provided by zoomkat. The output to the serial monitor after +2 minutes is still

DNS and DHCP-based no-ip web client test 3/16/13
Send an e in serial monitor to test

So it never arrives at

Serial.println("Failed to configure Ethernet using DHCP");


 Serial.print("Arduino IP address: ");

Does anyone have any further tips on how to debug this?

Many thanks!


Did you ever figure this out? I'm having the same problem with an ethernet shield 2. Never gets an IP.

I'm not sure, but I use the Leonardo ethernet with a tft shield. I believe it is a conflict between the two.

I have ordered a new leonardo which has arrived yesterday. I'll try to do some testing with the example programs tomorrow.

Unfortunately I had no success with my second leonardo ethernet either. It seems it has nothing to do with the tft screen.

Most likely there is something about the w5500 ethernet chip that is not supported yet.

There are a couple Ethernet libraries that allow the W5500 to be used with the IDE although I haven’t tested them with the Leonardo:

For the Leonardo ETH try using

#include <Ethernet2.h>

instead of

#include <Ethernet.h>

also use the newest version of the IDE on

I can get the Leonardo ETH to quite happily work with the following code

#include <SPI.h>
#include <Ethernet2.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x11, 0x11, 0x11 };
byte ip[] = { 192, 168, 1, 111 };

void setup()
  Ethernet.begin(mac, ip);

void loop()

Great Success!

I had tried to use the Ethernet 2 library but probably used an old version, which I manually installed.
Version 1.7.7 of the ide seems to come with the ethernet2 library included, and this one worked perfectly.

If you have any trouble I can advise to remove the entire ide, remove the folders, both under users and program files, and start with a clean install.

Thanks for tht help.

Kind Regards,


no worries!

Do not use Win XP environment to compile sketch ! I have MEGA2560 and W5100. Sketch compiled in Windows XP stop at Ethernet.begin(my_mac, my_ip); But compiled in Windows 8.1 enviroment works. I solve the problem. That should not have an impact but still have. I tray ide 1.6.13 and 1.7.11. In windows XP is maybe problems when sketch use serial.print for debug because of use USB port and drivers. Tray to no use serial! I also tray new atmel driver-atmel-bundle-7.0.888.exe without succes.