Arduino doesn't get ip

Hi, this is my first time posting and I am fairly new with Arduino.

I have code running on the Arduino Ethernet to act as an ethernet client. At first it worked perfectly, (well not perfectly but that is a different problem) and got an IP address whether static or through DHCP. However, now, without having made any changes to the code since it last worked I get this problem:

When I try to initialize ethernet using DHCP Serial monitor just doesn't print anything. When I try assigning a static IP, Serial monitor shows the Arduino connect, but says it's IP is 0.0.0.0 and the sketch continues to run/display but obviously with that IP the network connection doesn't work.

I really don't know what could have happened, and would really appreciate an answer as soon as possible as I am working with a deadline.

I am including my code anyway, but since as I said I didn't change anything I think it is probably more related to Arduino set up/issue.

My code is on github here: https://github.com/andrewmh20/Tweet-a-Watt-Arduino/tree/783aae51d0dd7b24e4abc398cfecd89a2f275bfa/Tweet_a_Watt_Arduino_v1_0

Thanks!

Hey there, i think your problem is here

if (Ethernet.begin(mac) == 0) {
      Serial.println("DHCP FAILED");
      //Use a fixed IP address, as determined above
      Ethernet.begin(mac, ip);
  }

remove the if ( Ethernet. begin(mac)==0) statement
and just use Ethernet.begin(mac,ip);
so your void setup must look like this

void setup() {
    //Start Hardware Serial
    Serial.begin(9600);
    //Start SoftwareSerial Xbee communications
    xbee.begin(9600);

  //Start the Ethernet connection
  Ethernet.begin(mac, ip);
  
  
  //Print the obtained IP address (for debugging)
  Serial.print("Client is at ");
  Serial.println(Ethernet.localIP());
    
    pinMode(5, OUTPUT);
    pinMode(3, OUTPUT);
    digitalWrite(5, HIGH);
    digitalWrite(3, LOW);
//tx 7
//5v 5
//gnd 3
  wdt_enable(WDTO_8S);

}

hope it works.

Thanks for your reply; I have the if statement there just to try DHCP before using the static IP. When I do what you suggested (which I have tried) I get the problem I described where it shows an IP of 0.0.0.0.

One thing to check is whether your DHCP server is configured to only give out IP addresses for machines whose network address was recorded. You would need to check out the web site for the DHCP server to see what its configuration is. Or perhaps, the Arduino needs to send in more information to the DHCP server. You might check the logs of your server.

I'll try to find out... But again, this worked fine before with the same network setup.

How does one access logs of a router?

andrewmh20:
I'll try to find out... But again, this worked fine before with the same network setup.

How does one access logs of a router?

It depends on the router, and whether you've ever accessed the admin panel. On mine, I log into the router via the web, and go into the advanced menu screen. I suspect most people never do that. One thing you might try is power cycling the router. Maybe it isn't giving out new IP addresses, and your current machines just don't notice.

There is no menu to see a log of, just settings to change. There isa list of who it has given IP's to and my arduino is not there. This problem has happened on multiple routers.

I just narrowed it down to not being my code because when I run this example code from the PING library I get the same results.

/*
  Ping Example
 
 This example repeatedly sends ICMP pings and sends the result over the serial port.
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 30 Sep 2010
 by Blake Foster
 
 */

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

byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x27, 0x80}; // max address for ethernet shield
byte ip[] = {10,10,5,105}; // ip address for ethernet shield
byte pingAddr[] = {10,10,5,1}; // ip address to ping

SOCKET pingSocket = 0;

char buffer [256];

void setup() 
{
  // start Ethernet
  Ethernet.begin(mac);
  Serial.begin(9600);
Serial.println(Ethernet.localIP());
}

void loop()
{
  ICMPPing ping(pingSocket);
  ping(4, pingAddr, buffer);
  Serial.println(buffer);
  delay(500);
}

P.S. I won't be able to respond until Sunday.

Router reset didn't help. It's not my code, or my network setup.

Router reset didn't help. It's not my code, or my network setup.

If every thing was working, and now it isn't, then most likely have a lose wire or some other mechanical issue. Yesterday I was testing some previously good code that then failed when a pin was set high. The problem was a bare ended test wire in the pin hole had moved and was touching another wire, causing the arduino to freeze when the pin was set high.

That's what I would suspect, I just don't know what it could be since I have tried with nothing attached except the Arduino itself.

Tomorrow I will attach it directly to my PC with a crossover cable, and watch it through WireShark to see if any MAC level packets are even being sent. If not, then I guess I have a problem with the actual Wiznet chip or network interface/adapter.

All I see that could possibly be the Arduino are some ICMP packets (even when I do not have a PING sketch running) from IP 0.0.0.0 and a mac address of all 0's.

Any ideas?

Do you have a microSD slot on the ethernet shield? Is there a microSD card in the slot?

Yes and Yes. It is the actual Ethernet Board, not the shield though.

Then this thread will save me some typing. Here is where this is now:

The startup code to avoid that is in reply #8.

I did say I have an SD card in there, but I haven't actually been using it.

Just for the heck of it I tried it with the SD card taken out and get the same issue still.

It does not matter if you are "not using it". If it is inserted into the slot, it connects to the SPI bus. That causes severe problems with the w5100, especially UDP. DHCP and NTP I have found fail if the SD card is not removed, disabled, or initialized.

Are you using IDE v1.0.1? IDE v1.0 and earlier had some issues with that. Just checking...

Okay, that's good to know, but right now it is not in the slot.

Yes, 1.0.1

I recommend leaving the SD card out until the ethernet stuff is ok.

Have you tried the DhcpAddressPrinter in the ethernet examples? I've compiled it on both Windows and Ubuntu, and it works fine. It may take a minute or so to time out if there is a problem with the dhcp server, or the connection to it. If it doesn't timeout in a couple minutes, you may have a hardware issue.

Well, nothing has happened or timed out. As I said earlier, it probably is hardware, because it used to work fine with the same code.

Is there any way to diagnose/troubleshoot/possibly fix hardware issues? Or is it definite that I need a new board now?

(To be sure I can test my code on another one tomorrow, but as the examples aren't working either I am pretty sure it is hardware.)

Sorry to hear that. Hope it was not damage due to the w5100 and the SD card fighting over the SPI bus. I'm not sure which device would win that one.