[SOLVED]Mega 2560 (R3) + ethernet W5100 don't get IP Address

I'm try to use the ethernet shield on arduino mega 2560 (R1), but it's always get the IP 0.0.0.0 or 255.255.255.255.

My pins connection

Mega w5100 53 NC 52 13 51 11 50 12

And code:

http://pastebin.com/2qLmHTcY

i'm not very senior, and i don't use that shield so i'm not totally sure, but are you sure about this ?

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

why would you want to disable something that you're using ??

and what is this supposed to do ?

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

Thank's retronet_RIMBAIZO.

It's the mistake, i put it to test and forget to remove. :astonished: :astonished: :astonished:

FYI: Setting D10 as OUTPUT and HIGH would not make that code fail.

SurferTIm, this setup works for me.

// 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

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

So i can ping the board, but can't access on browser.

If you mean the code you have on pastebin, you are correct. There no server code there. It only starts the w5100 so you can ping it.

I have server code in the playground. You could also search the forum for zoomkat's server code. Here is the link to mine. There is a SD version and a dynamic version (requires less memory than the SD version) below it if all you need is one page. http://playground.arduino.cc/Code/WebServerST

Surfertim,

i try your code, but i have the same problem the ping work's but http://192.168.1.72/mytest.php don't load the page. :0 :0

Are you sure that ip is ok to use? Did you use dhcp or set the ip static? If static: No other device using it? Not in the dhcp server ip pool? Correct for your network?

Yeap, because before i check all connections i can't ping it. My ethernet shield has SD but its not plugged on board. It's a problem for your example???

What make and model is the router? How did you pick that ip?

The router is a technicolor and i set the IP on code.

I can ping the board, but it doesn't appear on router iptable :(

// this must be unique byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEC };

// change to your network settings IPAddress ip( 192,168,1,72 ); IPAddress gateway( 192,168,1,1 ); IPAddress subnet( 255,255,255,0 );

~/ » ping 192.168.1.72 PING 192.168.1.72 (192.168.1.72): 56 data bytes 64 bytes from 192.168.1.72: icmp_seq=0 ttl=128 time=2.429 ms

Are you certain that is the Arduino responding? If you disconnect the Arduino from the router, can you still ping that ip?

i turn off the arduino and try to ping.

rafaelvg$ ping 192.168.1.72
PING 192.168.1.72 (192.168.1.72): 56 data bytes
Request timeout for icmp_seq 0

I try to get ip from DHCP but with no success.

//zoomkat 9-22-12
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//remove SD card if inserted

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

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

char serverName = “web.comporium.net”; // zoomkat’s test web page server
EthernetClient client;

//////////////////////

void setup(){
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

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

if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
// no point in carrying on, so do nothing forevermore:
while(true);
}

These symptoms sounded really familiar. Here is another post with a user who had the same problems. Read this thread, especially reply #10.

edit: A SD card in the slot without setting D4 as OUTPUT and HIGH before starting the w5100 will cause the same symptoms.

I read this thread before, and i tested the continuity of the pins. Now i'll search for scope to see the output of pins.

The line you need to check is the MISO line. Your w5100 is getting the IP address, so it is listening on the MOSI line, but the Mega is not getting the response from the w5100. I would start at the ICSP pins by checking both ends of that pin.

I have done as per the article. It looks like the only thing that resolves the problem is to change the Ethernet Shield. It's major concerning as we have a production line ready to go with 30 Units into the field. The problem seems to be very intermittent I used 4 Ethernet Shields as they only work for a while before they go into IP0.0.0.0. I would really appreciate any help now.

@francoismaritz: If you post your code, maybe I will have time to test it. I have a Mega2560/Ethernet shield here. How long does it normally take for the IP to revert to 0.0.0.0 running your code?

I have stripped my code out.

Here is the Test Code (Just to simplify)

// not tested example.

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

byte mac = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
//IPAddress ip(192,168,73,230);
IPAddress ip(192,168,0,200); // ip in lan
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() {
}

How are you determining the IP changed to 0.0.0.0?

edit: My server runs fine for days on end, even after abusing it with hacking attempts and port scanners. It ran almost all day yesterday, and I started it again this morning. You can access it online if you wish. My server

edit2: Somebody just tried a port scanner on it. My server code has freed up the socket already.