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)
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[] = "checkip.dyndns.com"; // 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:
while(true);
}
Serial.begin(9600);
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
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 / HTTP/1.1"); //download text
client.println("Host: checkip.dyndns.com");
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
readString += c; //places captured byte in readString
}
//Serial.println();
client.stop(); //stop client
Serial.println("client disconnected.");
Serial.println("Data from server captured in readString:");
Serial.println();
Serial.print(readString); //prints readString to serial monitor
Serial.println();
Serial.println();
Serial.println("End of readString");
Serial.println("==================");
Serial.println();
readString=""; //clear readString variable
}
@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..."
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 arduino.org company makes. We kinda got it to work by switching to their IDE.
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.
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.