Ethernet Shield R3 + Mega, can't get it to work

Hi. I got a Mega R3 and Ethernet shield R3, and I am trying to host a web server. It worked on the UNO but when I upgrade to the mega everything stopped working. When I go to 192.168.2.22 it just keep on loading. Does anyone know what's likely to be the problem? Thank a lot!


I tried a couple of configurations:
#1)

#2) Remove all the wires
#3) Same as #1 but bended the 4 pins (10,11,12,13 on the Ethernet Shield) then change chipSelect_W5100 from 53 to 10

Here is my ipconfig & code:

#include <SD.h>
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
const int chipSelect_SD = 4;
const int chipSelect_W5100 = 53;
const byte MY_ADDRESS = 22;
byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x45, 0x13};
byte ip[] = {192,168,2,22};
EthernetServer server(80);

void setup(){
  Serial.begin(9600);
  Wire.begin(MY_ADDRESS);
  pinMode(chipSelect_W5100, OUTPUT);
  pinMode(chipSelect_SD, OUTPUT);
  SD.begin(chipSelect_SD);
  Ethernet.begin(mac,ip);
  server.begin();
}

void loop(){
  EthernetClient client=server.available();
  if(client){
    boolean currentLineIsBlank = true;
    while (client.connected()){
      if (client.available()){
        char c = client.read();
        if(c == '\n' && currentLineIsBlank){
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();
          File webFile = SD.open("main.htm");
          if (webFile){
            while(webFile.available()){
              client.write(webFile.read());
            }
            webFile.close();
          }
          break;
        }
        if (c == '\n'){
          currentLineIsBlank = true;
        } 
        else if (c != '\r'){
          currentLineIsBlank = false;
        }
      }
    }
    delay(1);
    client.stop();
  }
}

If the top picture is the underside of the ethernet shield, no wires or pin bending were necessary.

You have Serial.begin(), but there is nary a Serial.print() in sight. Why not?

When I go to 192.168.2.22 it just keep on loading.

What just keeps loading? What is "it" loading"? How do you know that "it" is doing anything?

Does it work if the whole web site is not on the SD card?

Hi. Thanks for your speedy response. "It" refers to the browser, and I think the browser was attempting to locate 192.168.2.22.

Right now I am just using the sample WebServer code. The only modification I made is the IP address. I removed all the wires as suggested, and here is what happened:

Any idea? I have also observed that the onbaord LED light is on at all time. Is it normal? It doesn't happen when I use the 4 wires configuration. Thanks...

Make sure the Ethernet shield pins are inserted in the correct mega holes and not miss aligned.

Previous post you might want to review. My Ethernet shield worked on my mega without any mods. Pin bending may make things worse.

https://www.google.com/search?num=100&lr=&hl=en&as_qdr=all&q=mega+ethernet+site%3Ahttp%3A%2F%2Farduino.cc%2Fforum&oq=mega+ethernet+site%3Ahttp%3A%2F%2Farduino.cc%2Fforum&gs_l=serp.12...21431.21431.0.24834.1.1.0.0.0.0.54.54.1.1.0...0.0...1c.1.9.serp.2LUaGt7ywgc

Simple client code you can try.

//zoomkat 2-13-12
//DNS and DHCP-based web client test code
//for use with IDE 1.0
//open serial monitor and send an e to test
//and to see test result
//for use with W5100 based ethernet shields
//browser equivelant URL: 
// http://web.comporium.net/~shb/arduino.txt
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 

#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); 
  Serial.println("DNS and DHCP-based web client test 2/13/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }
  // print your local IP address:
  Serial.print("Arduino IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print("."); 
  }
  Serial.println();
  Serial.println();
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

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

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

If I am going to use the w5100 and SD together, this is the best way to get both started.

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

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

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

  Serial.print(F("Starting W5100..."));
  Ethernet.begin(mac,ip);
  Serial.println(Ethernet.localIP());
  server.begin();
}

Here is a link to my server code. It works good for me.
http://playground.arduino.cc/Code/WebServerST