Ethernet Shield Seems Sketchy

Firstly, here is the ethernet shield I am using. Supposedly it is fully compatible with the Uno

The instant that I insert an ethernet cable into the RJ45 socket the link, 100M, and fulld lights illuminate. This certainly makes it seem as though the board is not dead. I also have an LED in digital pin 13 and ground which supposedly is the ethernet chip's clock.

19 times out of 20 when I issue a Ethernet.begin(mac) command, code execution hangs for 90 seconds and an LED inserted between digital pin 13 and GND stays solidly lit. For whatever reason, some random bits of new code will work just fine, instantly establish a DHCP connection and send and receive data. Below is some troubleshooting code that ran perfectly the first time I tried it and has failed every time since then:

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0x11, 0xBB, 0xBB, 0xCC, 0xDE, 0x05 };
char serverName[] = "www.google.com";

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  Serial.begin(9600);
  delay(500);
  // start the Ethernet connection:
  Serial.println("Attempting 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);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  
  if (client.connect(serverName, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
}

Can anyone suggest anything to help stabilize things for me? I know the shield isnt' dead since I've had it send data but it is extraordinarily unreliable.

Do you have a uSD memory card in the ethernet shield slot? That can cause the symptoms you describe. You can use them together easily, but they must be initialized correctly, or eventually you will have troubles like this.

Just checking...

Thanks for your reply Tim. No, no card in the slot.

Oddly, I had a bit of luck making the shield respond to pings by setting pin 10 to output. That shook something loose and allowed the shield to respond to ping requests from my laptop, but setting that pin has not worked again since that first attempt.

Try this code. You can change the network settings to yours if you want to try a ping.

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

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEB };
IPAddress ip(192,168,2,2);

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

  Serial.println("Starting w5100");
  Ethernet.begin(mac,ip);
  Serial.println(Ethernet.localIP());
}

void loop() {
}

If the serial monitor shows 192.168.2.2 (or your ip), then the SPI and w5100 are communicating on the SPI bus. If it shows anything else, like 0.0.0.0, then something is wrong with the hardware.

Insure the ICSP connector is connected fully. That is how the SPI bus gets to the shield.

Tim, thanks for your help. This is what came back:

S?ÉWËëw5100Cá0.0.0.0

A second attempt yielded this. Not sure if this is any help at all:

StaÑ¥ëw5100
255.255.255.0

Odd, a different mask comes back every time:

StÉÑ¥¹w5100
255.0.255.0

EDIT: I mashed the heck out of the shield and by keeping the serial monitor open and using the reset button this is what I now get:

Starting w5100
192.168.11.8
Starting w5100
192.168.11.8
Starting w5100
192.168.11.8

Sounds like you have/had a bad connection on one of the pins. If you used 192.168.11.8 as the ip, you should be good to go as far as the SPI is concerned. Now, can you ping it?

Wow, so apparently the problem was the LED going from digital pin 13 to GND! With that removed your code and all the other internet code works fine. Thanks so much for your help. I knew somehow the problem was me and not the hardware!

You must leave D10-D13 alone when using the SPI bus on an Uno. The Uno has a small LED on D13, but you can't use it when you are using the SPI. It is the clock line.

The Mega uses different pins for SPI.