I think my ethernet shield is broken?

A friend gave me this piece of code to perform get requests but it doesn’t seem to work, client does not even get connected:

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


EthernetClient client;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {192,168,1,5};

void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac,ip);
  
  Serial.println("Give ethernet time to boot up");
  delay(10000);
  Serial.println("Connecting");
  Serial.println(client.connect("188.166.33.214" , 80));
  //client.connect("exo-stats.com" , 80);//equivalent?
  
  client.println("GET / HTTP/1.1");
  client.println("Host: 188.166.33.214");
  client.println(); 
}

void loop()
{ 
}

Does this work for your ethernet shield and arduino uno?

This will answer part of your question. Try this test sketch. If the serial monitor shows 192.168.2.2, then the SPI end is working. If it shows anything else, like 0.0.0.0, then it isn’t working.

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

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

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

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // Start ethernet
  Serial.print(F("Starting ethernet..."));
  Ethernet.begin(mac, ip);
  Serial.println(Ethernet.localIP());
}

void loop() {
}

It works as expected. What does SPI stand for actually? (and why do I need the sd inside the sd card slot?yes I have inserted one)

This will explain the SPI bus. It is the protocol that the ethernet shield uses.

Try this test sketch. It checks the RJ45 end of the w5100. If your ethernet shield is connected to a router, it should show an IP address if all is ok. If it stalls for a couple minutes and displays failed, then it is not working.

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

byte mac[] = {  0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

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

 // disable SD SPI
 pinMode(4,OUTPUT);
 digitalWrite(4,HIGH);

 Serial.print(F("Starting ethernet..."));
 if(!Ethernet.begin(mac)) Serial.println(F("failed"));
 else Serial.println(Ethernet.localIP());
}

void loop() {
}

A shield is connected to my router. In that shield is connected my pc , the arduino and a raspberry pi.

This sketch prints “Failed” so I guess somethings wrong…perhaps DHCP or i dont know…

Then you seem to have a problem on the ethernet end of the w5100. Are the LEDs on the front of the RJ45 receptacle lit? Are the LEDs on the router for that port lit?

The green light is on all the time

*On the board:

Lights on : PWR , LINK , 100M FULLD, RX/TX some random times blinking ,

You can try setting up a static IP on the shield, but you must know the proper network settings to do that.

I’ve actually tried using Ethernet.begin(ip,mac) and it worked but still the client.connect will not work (on my arduino at least)

When you say it worked, can you ping that IP from your PC or RPi?

Destination host unreachable...

Then you have a problem. If the Arduino is 192.168.1.181, then why is the router (192.168.1.1) getting involved in this ping? What is the IP of the PC? Is it connected to an ethernet port on the router? Or is it wireless?

edit: If the Arduino and the PC are on the same localnet, this should be the result. It should be "Request timed out", not "Destination host unreachable". I pinged 192.168.1.250, which is an IP that no device is using on my localnet. My PC is 192.168.1.254.

C:\Documents and Settings\user>ping 192.168.1.250

Pinging 192.168.1.250 with 32 bytes of data:

Request timed out.

Ping statistics for 192.168.1.250:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
Control-C
^C
C:\Documents and Settings\user>

Here is an example of a ping to a non-existent IP on a different localnet than the PC. Note it is "Destination host unreachable". Also note my router (192.168.1.1) got involved in this ping.

C:\Documents and Settings\user>ping 192.168.2.3

Pinging 192.168.2.3 with 32 bytes of data:

Reply from 192.168.1.1: Destination host unreachable.
Reply from 192.168.1.1: Destination host unreachable.

Ping statistics for 192.168.2.3:
    Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
Control-C
^C
C:\Documents and Settings\user>

The pc is 192.168.1.1

Yes , the arduino is plugged in a shield which is plugged in a router

Then what is the IP of the router? That may be your problem. It is normally 192.168.1.1. Look on your PC for its gateway. Use ipconfig from a command prompt to get that.

Then you need to include all parameters to your Ethernet.begin() call.

IPAddress ip(192,168,1,181);
IPAddress subnet(255,255,255,0);
IPAddress gateway(192,168,1,254);

Ethernet.begin(mac, ip, gateway, gateway, subnet);

Simple client code you can try unmodified to see if you can get returned data from the server.

//zoomkat 3-1-13
//simple client checkip test
//for use with IDE 1.0.1 or later
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields

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

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

char serverName[] = "checkip.dyndns.com"; // test web page server
EthernetClient client;

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

void setup(){

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

  Serial.begin(9600); 
  Serial.println("Better client ip test 3/1/13"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

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 / HTTP/1.0"); //download text
    client.println("Host: checkip.dyndns.com");
    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

}

SurferTim:
Then you need to include all parameters to your Ethernet.begin() call.

IPAddress ip(192,168,1,181);

IPAddress subnet(255,255,255,0);
IPAddress gateway(192,168,1,254);

Ethernet.begin(mac, ip, gateway, gateway, subnet);

YES!! It's working. gateway was wrong i guess? (This may be the reason a secondary router I want to hook up doesn't get a valid IP...) Thanks

Still Screenshot by Lightshot

Zarkopafilis:
Still Screenshot by Lightshot

It appears you are pinging 192.168.1.1 from 192.168.1.1. Why are you not pinging 192.168.1.181?

Is it working or not?