MEGA 2560 R3 + Ethernet Shield w5100 with SD, PING ok, localip not

I have the following problem. I have got a new MEGA 2560 Rev.3 Board with a new Ethernet Shield w5100 with ICSP Interface. I stacked them together and I can access the SD-Card on the Ethernet Shield, but I can not set an IP address (not manually and not via DHCP). I always get 0.0.0.0 when I call Ethernet.localIP(); In case of setting IP via DHCP (only MAC address submitted to DHCP Server) the sketch hangs up forever. In case of manually configure the IP, I can ping the board correctly, if i insert a SD card. How can the board do that, when Ethernet.localIP() ever responses 0.0.0.0? Sounds really strange to me.

So my questions are:
Is there someone out there, who has the same problem as i have and did you solve it?
I think, i don´t need any jumper cables on that board to work with Ethernet. It that correct?
Maybe i need a specific Ethernet library to work with the new Ethernet Shield? I don´t think so, but maybe there is one.

Here is a short breakout of my sketch:

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

byte mac = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192,168,73,230);
const byte EthernetPin = 10;
const byte SDPin = 4;

EthernetServer server(80);
Sd2Card card;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);

pinMode(53, OUTPUT);
delay(1000);

Serial.print(“Initializing SD card…”);
if (!card.init(SPI_HALF_SPEED, SDPin)) {
Serial.println(“initialization failed. Things to check:”);
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
//return;
} else {
Serial.println(“Wiring is correct and a card is present.”);
}
Serial.println(“initialization done.”);

pinMode(SDPin, OUTPUT);
digitalWrite(SDPin, HIGH); //Disable SD card
pinMode(EthernetPin, OUTPUT);
digitalWrite(EthernetPin, LOW); //Enable Ethernet
delay(1000);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}

void loop() {
}

And here is my output from serial monitor, if no SD card inserted:

Initializing SD card…initialization failed. Things to check:

  • is a card is inserted?
  • Is your wiring correct?
  • did you change the chipSelect pin to match your shield or module?
    initialization done.
    server is at 0.0.0.0

ping 192.168.73.230
Ping wird ausgeführt für 192.168.73.230 mit 32 Bytes Daten:
Antwort von 192.168.73.230: Bytes=32 Zeit<1ms TTL=128
Antwort von 192.168.73.230: Bytes=32 Zeit<1ms TTL=128

And here the output from serial monitor with SD card inserted:

Initializing SD card…Wiring is correct and a card is present.
initialization done.
server is at 0.0.0.0

ping 192.168.73.230
Ping wird ausgeführt für 192.168.73.230 mit 32 Bytes Daten:
Antwort von 192.168.73.20: Zielhost nicht erreichbar. ( 192.168.73.20: Destination host unreachable.)
Antwort von 192.168.73.20: Zielhost nicht erreichbar.

Any suggestions? Oh another thing i did, i replaced the ethernet shield with a new one without any changes of behavior.
I appreciate your help!
Thx

I checked it agains my own sketch, and found a few differences.

After setting SS pin 53 to output, I have added : digitalWrite( 53, HIGH); So any device on the SS pin will be disabled.

The Ethernet uses pin 10, I also set that pin high to disable the ethernet. Only after that I use the SD library. You have: digitalWrite(EthernetPin, LOW); //Enable Ethernet That is not correct, since the Ethernet library takes over the EthernetPin.

Please make a test sketch without the SD code, and move the pin setting of 53 and 10 (set both to OUTPUT and HIGH) to the begin of setup().

Try this setup function. Does it do any better?

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  
  // disable w5100 while starting SD
  pinMode(10,OUTPUT); 
  digitalWrite(*10,HIGH);

  Serial.print("Initializing SD card...");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");
  
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}

Hello SurferTim,

i´ve tried your sketch. But of course, I´ve removed the multiply sign from digitalWrite(*10,HIGH);

The result without SD Card was:
The ping works, but the ip is still 0.0.0.0
Initializing SD card…failed
server is at 0.0.0.0

ping 192.168.73.230
Ping wird ausgeführt für 192.168.73.230 mit 32 Bytes Daten:
Antwort von 192.168.73.230: Bytes=32 Zeit<1ms TTL=128
Antwort von 192.168.73.230: Bytes=32 Zeit<1ms TTL=128

With SD Card inserted, the ping doesn´t work. The ip is also 0.0.0.0
Initializing SD card…failed
server is at 0.0.0.0

ping 192.168.73.230
Ping wird ausgeführt für 192.168.73.230 mit 32 Bytes Daten:
Antwort von 192.168.73.20: Zielhost nicht erreichbar.
Antwort von 192.168.73.20: Zielhost nicht erreichbar.

You see, in both cases the SD Card was not detected and the local ip was still 0.0.0.0
Any ideas?

Hello Caltoa,

i´ve tried your suggestions. You can see the sketch below.
The output of serial monitor is still:
server is at 0.0.0.0

but ping is working:
ping 192.168.73.230
Ping wird ausgeführt für 192.168.73.230 mit 32 Bytes Daten:
Antwort von 192.168.73.230: Bytes=32 Zeit<1ms TTL=128
Antwort von 192.168.73.230: Bytes=32 Zeit<1ms TTL=128

Here is the edited sketch
#include <SPI.h>
#include <Ethernet.h>

byte mac = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192,168,73,230);

EthernetServer server(80);

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);

pinMode(53,OUTPUT);
digitalWrite(53,HIGH); //any device on the SS pin will be disabled
// disable w5100 while starting SD
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}

void loop() {
}

You have Arduino version 1.0.5 ?
There might be a library problem. You could install a fresh Arduino IDE in a different folder.

Are you sure there is no other Arduino running with the same mac address ?
You are using the common DEAD BEEF FEED mac address.

I made a few changes to the code, can you try it ?
Now DHCP is used and also the SD is disabled.

// not tested example.

#include <SPI.h>
#include <Ethernet.h>
 
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192,168,73,230);
 
EthernetServer server(80);
 
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  // SS must be output and disable any device using SS
  pinMode(53,OUTPUT);
  digitalWrite(53,HIGH); //any device on the SS pin will be disabled

  // disable w5100
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);   // disable W5100

  // disable SD
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);  // disable SD

  // start the Ethernet connection and the server:
  // Try DHCP first, if that fails, try fixed ip.
  if (Ethernet.begin(mac) == 0)
  {
    Serial.println(F("DHCP failed"));
    Ethernet.begin(mac,ip);
  }

  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}

void loop() {
}

If that doesn’t work, then is something else wrong. Perhaps the ethernetshield is broken. Or there is a communication problem between the Ethernet shield and the router. Can you try another router ? Try a router with direct connection to the Ethernet shield without wifi in between.

Check the ethernet shield connection to the Mega. The ICSP pins are important. Insure the Mega ICSP pins are firmly seated into the ethernet shield connector. I suspect it is the MISO line that is not working or not connected.

Hello Caltoa,

fyi, what I´ve done so far:

I´ve already used 1.05 IDE If I use this sketch with DHCP, i do not get an answer. I do not get an answer after minutes of waiting for. There is no timeout. I think, the sketch hangs up. I´m also sure, that there is no other device with this MAC address. I´ve connected the arduino directly with my router via LAN, unfortunately with no changes in behaviour. I´ve thought, the ethernetshield is broken, so i exchanged it with another one. The same.

Now the only thing that i can do, is to exchange the Arduino Board itself. Unfortunately I don´t have another one to check it. But if so, why can I successfully connect to the SD-Card? That means, that die SPI works and the ICSP Connector is connected as well. The next thing is, why can I ping the Ethernetnet Shield successfully, if the board is broken? I can´t believe this, but i can´t check it either.

Therefore I assume, it has to be another problem. Maybe a library problem, clock settings etc. Did you have an Arduino 2560 R3 with new ethernet shield up and running?

I´ve doublechecked this. The connections from Arduino Board PIN 50-52 to ICSP and ICSP to Wiznet5100 are good.
PIN53 seems not to be directly connected to WIZNET5100 (I don´t get a beep), but I think that is correct.

SurferTim:
Check the ethernet shield connection to the Mega. The ICSP pins are important. Insure the Mega ICSP pins are firmly seated into the ethernet shield connector. I suspect it is the MISO line that is not working or not connected.

If the w5100 responds to a ping on the assigned ip, but reports the ip as 0.0.0.0, and the SD card fails to initialize, then the MISO line has failed on either the shield or the Mega.

We have solved the problem - Thank you!!!

The problem exists on the Arduino Board not on the Ethernet Shield. It was not correct solded. There was a little tiny bridge between PIN 22 (MISO) and PIN 23 (OC2A) on the ATMEGA 2560. I did seperate this 2 pins and here it is. All problems are gone.

Well done. And very good diagnoses SurferTim.

//Add code in function setup(), i'm success. pinMode(11,INPUT); pinMode(12,INPUT); pinMode(13,INPUT);

bruceleeliya: //Add code in function setup(), i'm success. pinMode(11,INPUT); pinMode(12,INPUT); pinMode(13,INPUT);

What effect would that have on a Mega 2560? Those aren't SPI lines.

Hi Jogile, I have same this issue. How to seperate the 2 pins (IN 22 (MISO) and PIN 23 (OC2A) on the ATMEGA 2560) ? Thank you.

Jogile: We have solved the problem - Thank you!!!

The problem exists on the Arduino Board not on the Ethernet Shield. It was not correct solded. There was a little tiny bridge between PIN 22 (MISO) and PIN 23 (OC2A) on the ATMEGA 2560. I did seperate this 2 pins and here it is. All problems are gone.

Hi,

i have the same issue with arduino mega 2560 and i found my own solution. My card is a chinese clone. Ethernet Shield is also. I connected them together and i got same results as your's. Arduino answers the ping but no ip address with dhcp. Then i detected that pins (communication pins) which are located near the reset button of arduino mega 2560 are not straight. Card was new. Ethernet shield is also. Probably this is a factory fault and there are many Arduino Mega 2560 clones around like that (chinese ones) While i trying to connect them the solder of pins were damaged (very very little .. as an hairline damage..i saw it with a magnifier ) I resolder these 6 pins at the back side of Arduino Mega 2560 with using flux for better result. Then... bingo... problem solved.. My new arduino mega 2560 and ethernet shield takes ip from my DHCP server without any problem :)

I think that your problem is same. While you were trying to plug your ethernet shield to your mega you destroyed your mega' s communication pins. But do not worry. Because solution is so easy. Resolder these 6 pins from the back side of your Arduino. That' s all.

Good Luck.

i have project with arduino mega2560 + ethernet shield w5100 any one is here to help me ? my english language is too bad !

please check this page and help me http://www.instructables.com/id/Arduino-attendence-logger/?ALLSTEPS

please send true code to my email address ;

mojitaba72@gmail.com

please sent picture from Hardware setup

please !!!!!!!!!!!!!!!!!!!!