Ethernetshield IP problem

Hi all,

I need your help with a Ethernetshield problem.
The last couple of days I am struggling with some strange behaviour of my Mega 2560 with Ethernetshield.
I want the IP address of my project to be 192.168.0.220. My router is set to provide DHCP only from 192.168.0.100 to ~ 200.
The code I use is written below.

Very ofther the ethernetshield says its IP address is 0.0.0.0

What van be wrong?

Thanks, Bert

byte mac = { 0x90, 0xA2, 0xDA, 0x0C, 0x00, 0x65 };
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);
IPAddress ip(192,168,0,220);
EthernetServer server(80);

void EtherStart() {
delay(500);
Ethernet.begin(mac, ip, gateway, subnet);
delay(1000);
server.begin();
delay(500);
Serial.print("server is at ");
Serial.println(Ethernet.localIP());

}

This is the way to initialize the w5100 in IDE v1.0.1. A dns server ip is required if 3 or more parameters are passed to Ethernet.begin(). You can use the gateway ip as the dns server if you do not plan on using domain names.

  Ethernet.begin(mac, ip, gateway, gateway, subnet);

Insure you do not have a memory card in the microSD slot for the test.

Hi SurferTim. Thanks for the reply. I am not sure I understand. Do I need to mention gateway twice? If yes which is which one? If not what is the difference with my invocation?

What i forgot to mention is: i do use an sd card and once 0.0.0.0 is the ip address the only way to get it right is to take off the power.

i do use an sd card and once 0.0.0.0 is the ip address the only way to get it right is to take off the power.

That is about right if you have a sd card in the slot. If you plan on using the sd card, then use this setup routine.

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

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

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

  Serial.print("Starting w5100..");
  EtherStart();
  Serial.println("Setup done");
}

Thank you for this explanation. I think I understand what's going on. Will test it later today.

I've had trouble setting a Static IP on my official Ethernet Shield too. I've subscribed to this thread and hope you'll post your final solution when you have it. Thanks.

@BlueJakester: Do you have a memory card in the microSD slot? Are you using IDE v1.0.1?

Hi Tim,

Yes, I have the SD card installed. After reading this thread I'm thinking that may be the issue.

My Arduino Ethernet Shield is attached to an Arduino Uno R3 smd, and I'm using IDE 1.0.1. I haven't had time to test anything on it tonight, hopefully I'll get to it tomorrow.

It works fine with DHCP, but last time I tried to set a Static IP I was unsuccessful.

Jake

BlueJakester: Yes, I have the SD card installed. After reading this thread I'm thinking that may be the issue.

Testing with the SD card removed might provide useful info.

It's been over a month since I had the Ethernet Shield attached. I connected it this morning, with the SD card installed. I loaded a sketch that uses static IP, logs temp to the SD, and serves up data as a web server. Everything worked perfectly. Apparently I overcame whatever issue I was having with static IPs a couple of months ago. :blush:

If you do not either remove the sd card, disable it, or initialize it, you are in for more trouble. If I do not do one of those things, my static ip assignment “works”, but it doesn’t. It returns from the begin() routine, but malfunctions with any UDP function, like DHCP and NTP.

Here is a sample of the setup function I use to initialize both devices.

edit: This applies to all the ethernet and SD examples in the IDE. AFAIK, none take into account the other device that may be present on the SPI bus.

^^^ Yes indeed, my Ethernet Shield was working fine and then it wasn't. The SD card was in the shield, but not initialized.

I was using DHCP and the project I was working on had me disconnecting/connecting the Uno frequently. I reconnected it for something like the 5th time and it wouldn't acquire an address with DHCP. After messing around with it for a few minutes I removed the SD card and tried again. It acquired an address and connected right up!

Thanks for the advice Tim. I've saved your code for future reference.

Regards, Jake

I finally found time to test things and yes, your sample worked Tim. There is still something that puzzles me quite a bit. I cannot find a clear answer as to what pin on the Arduino MEGA 2560 comes in place of pin 10 on the Arduino Uno. Due to a lack of memory I had to migrate to the MEGA. In the documentation I read that the Ethernet SS actualy is pin 10 on the uno, but 53 on the Mega? However, the shield does not have a connection on 53. Or is it pin 10 on the Mega as well? Do I have to tell the board to make 53 output en set it high, or should that be done with pin 10 or both?

Regards, Bert

The default Slave Select pin is digital pin 53 for the Mega, but that does not change the SS pin for the ethernet shield. On both the Uno and Mega, the w5100 SS is digital pin 10 and the SD SS is digital pin 4.

edit: The SPI library will take care of the default SS setting in both the Uno and Mega. You only need to set digital pin 10 to OUTPUT and HIGH. The code I posted was tested on a Mega2560.