Arduino Mega 2560 + Ethernet Shield W5100 does not works

Hello guys,,

I'm a little frustrated trying to connect an Arduino mega with an Ethernet Shield W5100,,

First, i'm using mac osx, IDE 1.5.6-r2, and the shield has "Mega compatible",, i'm using the sketch "WebServer",

The Ethernet Shield works fine with my arduino uno, i can use the Ethernet and i can read a micro-sd card.

so far as i know, the ethernet shield use ICSP to connect to arduino board, i was reading and i have to put pin 53 in OUTPUT,,

For SD, the SS use pin 4, and for ETH the SS use pin 10,,

If i'm i correct, into void setup, i should put:

   pinMode(53, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(10, OUTPUT); 
    digitalWrite(4, HIGH);
    digitalWrite(10, LOW);

Correct?

any way.. i tried so many times, but something is wrong,

Here is the complete code:

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


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte gateway[] = { 192, 168, 0, 1 };
IPAddress ip(192, 168, 0, 17);
EthernetServer server(8081);



void setup() {
  

    pinMode(53, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(10, OUTPUT); 
    digitalWrite(4, HIGH);
    digitalWrite(10, LOW);
    
    
  
  Serial.begin(9600);
  Ethernet.begin(mac, ip, gateway);
  server.begin();
  

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


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("
");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

Does anyone help me?

Thanks a lot guys!!

These should be the first lines in your setup. Set D10 HIGH also.

    pinMode(53, OUTPUT);
    pinMode(4, OUTPUT);
    digitalWrite(4, HIGH);
    pinMode(10, OUTPUT); 
    digitalWrite(10, HIGH);

Does the serial monitor display "server is at 192.168.0.17"?

Hello SurferTim,,

i tried with your suggestion, but the serial monitor still showing server is at 0.0.0.0

Any idea?

Thanks

That usually means the SPI data lines are not working. Insure the ethernet shield pins are firmly seated into the Mega. Check the ICSP pins on the Mega to insure they are inserted properly into the shield's 2x3 pin socket.

This is a little embarrassing to me,, but you were right, i only press i little more the shield, and done!

i feel like a fool... sorry to waste your time.

Thanks a lot for your support SurferTim.

Don't feel bad. You are certainly not the first person who experienced this problem. If it helped you, it was not a waste of time.

you can try like this , i'm success.

void setup {
// Add code to here
pinMode(11,INPUT);
pinMode(12,INPUT);
pinMode(13,INPUT);
}