Mega 2560 and Ethernet dose not work. Please help me.

Hi I am using Mega 2560 R3 and Ethernet Shield R3,just plug together them. try to run the sample webclientrepeating when I run it, the Serial will show My IP address:

then get nothing more I connect the device to my router and my computer can ping the device what does it mean? please heip me.Thanks.

code just as follows.

// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = { 
  0x90, 0xA2, 0xDA, 0x0F, 0x1A, 0x8D};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(192,168,1,111);

// fill in your Domain Name Server address here:
IPAddress myDns(84,246,88,10);

// initialize the library instance:
EthernetClient client;

char server[] = "";

unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
boolean lastConnected = false;                 // state of the connection last time through the main loop
const unsigned long postingInterval = 60*1000;  // delay between updates, in milliseconds

void setup() {
  // start serial port:
  // give the ethernet module time to boot up:
    pinMode (4, OUTPUT);                  //disable SD card slot on ethernet shield, due to SPI bus
  digitalWrite (4, HIGH);
  // start the Ethernet connection using a fixed IP address and DNS server:
  // print the Ethernet board/shield's IP address:
  Serial.print("My IP address: ");

void loop() {
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available()) {
    char c =;

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {

  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();

koden dis sier IP .111, mens du sier du kan pinge .102. Det er nok din egen PC som har denne IP'en ? (sjekk med ipconfig)

Hej, I just declare it 111. but I did not use it in the code follows. Thank you.

If the code above is what you are running, then it will do nothing after the dhcp assignment. You need to connect to a server and send a request, then read the response.

Here is my client code in the playground.

Hi?thanks , I am using your code now. I works, but When change into my server. It seems the same problem with the sample above. the program never get chance to get into this part.

if(thisMillis - lastMillis > delayMillis)
lastMillis = thisMillis;

and the sample on the above is the same problem. Why did you said. It do noting but DHCP?
Thank you very much.

Is it your server, or do you have a web hosting company host it for you?

Hi It works with your code. Thanks a lot. I can connect my server now. I want to download a 36k file. why It will stop at the same position every time. and disconneted and when I print through Serial what I have received I can tell It will stop a little while (maybe 2 sec) between some position of the data stream of serial. Serial output like this. Thanks

 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84,
   0x08, 0x49, 0x0a, 0x14, 0x28, 0xf2, 0xa0, 0xdb, 0xa8, 0xd4, 0xd2, 0x40,
   0x84, 0x22, 0xa4, 0x84, 0x5a, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0xa2, 0xaa, 0xa0,
   0xa0, 0xc2, 0xec, 0x64, 0xb5, 0x42, 0xba, 0x28, 0x4a, 0x51, 0x84, 0x10,
   0xaa, 0xb6, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x80, 0x2b, 0x04, 0x9a, 0x00, 0x05, 0x88, 0xf8,
   0x64, 0xa5, 0x
Pass 1
HTTP/1.1 200 OK
Server: EasyWebServer/1.9
Content-Type: application/octet-stream
Last-Modified: Thu, 27 Mar 2014 15:34:14 GMT
Connection: close
Content-Length: 36298

My server is a easy one build on my PC. just for testing and I can download the file by UNO + WIFI I want to transplant into 2560 and Ethernet.

I can download the file by UNO + WIFI I want to transplant into 2560 and Ethernet.

Perhaps you should post the uno/wifi code that works so it can be studied to see what makes it work.

If the serial output shows "disconnecting" without a "Timeout" message, that means the server closed the connection.

If you are downloading a large file or a lot of data, and want to display it on the serial monitor, I suggest increasing the speed of the serial connection. I normally use 115200 instead of 9600.

Hi SurferTim Thanks very much for your patience. It works finally. It was my server's problem. I have some doubts now. Would you please explain a bit more. 1 why you write like this if(!Ethernet.begin(mac)) Serial.println(F("failed")); else Serial.println(F("ok")); digitalWrite(10,HIGH); this mean disable the Ethernet? It seems does not matter if I the comment this line. 2 when I download my 36k file and show through the Serial. I can feel that the print of serial stop 3-5 seconds every 4K. and continue again. It means 36K was divide into nearly 10 parts. It is harmless for my work. I am just curious why? It is because of the library have 4K as a packet. and why it is so obviously to tell the interval. 3 would you please give me some advise or link about how to download this file and save into SD card. Do I have to change the CS frequently. when I choose the SD card. Does it affact the data coming through the Ethernet?

1) That disables the SPI interface on the w5100. The Ethernet.begin() call has a bug that leaves the w5100 slave select LOW (active) when the function is complete. If you try to use any other SPI device, that would cause problems. If you read or write to the w5100 first, those functions leave the w5100 SPI disabled like they should.

2) Sounds like the delay is caused by your server.

3) Open an SD file and write the response to it the same way you write it to the serial monitor.