Ethernet Sheild Not Finding Connection

I am working with a Seed Studio 1.1 ethernet shield on an Arduino Uno and a set up code out of the Arduino Cookbook.

The code seems to be working. When I go to the serial port it reads connecting ... no connection, disconnecting. I don't know if there is an issue with the IP addresses or the MAC address or if it's something else entirely.

The boards only indicated address is 12A12. I've tried {0x1, 0x2, 0x1, 0x0, 0x1, 0x2}, the original code's address {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}, and the ethernet MAC address as read off my computer ethernet network in system preferences {0xc8, 0xbc, 0xc8, 0x91, 0x49, 0x52}.

I've also tried switching between the Airport IP address and Ethernet IP address. The ethernet IP consistently changes with each new attempt to connect.

I've added the router IP address under one and both dns_server and gateway. I've also used the computers Ping utility to locate a current google IP address.

I am very new to all of this and learning as I go. Can anyone tell me what I should try next to get a connection. Thank you in advance for your patience, time and attention.

Here is the code:

/*

  • Simple Web Client
  • Arduino 1.0 version
    */

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,254,30 }; //AirPort IP
byte server[] = { 74,125,225,148 }; //Google
byte gateway[] = { 192,168,254,254 }; //router

EthernetClient client;

void setup()
{
Serial.begin(9600); //start the serial library
Ethernet.begin(mac,ip,gateway);
delay(1000); //give the ethernet hardware a second to initialize

Serial.println("connecting...");

if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /search?q=arduino HTTP/1.0"); //the HTTP request
client.println();
}
else {
Serial.println("connection failed");
}
}

void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c); //echo all data recieved to the serial monitor
}

if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;:wink:
;
}
}

The code seems to be working. When I go to the serial port it reads connecting ... no connection, disconnecting

That's a pretty strange definition of "working", then. Most people would claim that the code was not working.

and the ethernet MAC address as read off my computer ethernet network in system preferences

Assigning another device on the network the same MAC address is pretty dumb.

I've also tried switching between the Airport IP address and Ethernet IP address. The ethernet IP consistently changes with each new attempt to connect.

Your router needs to assign the Arduino an address that does not change every time. You need to use that address in the code.

Your gateway value is wrong. If you don't know what a gateway is, delete that value and the use of it in the Ethernet.begin() call.

Have you verified that the IP address for google is correct? Google gets tired of being the access address for everyone's test code, and changes addresses regularly to prevent that.

Thank you for your reply. I understand that I am under informed that is why I am asking questions and doing my best to learn. As far as the gateway goes I was following the trouble shooting methods in the book. As per your suggestion PaulS, I've eliminated the gateway and changed the ip to the routers IP address . Still no connection.

As I mentioned earlier, I did Ping googles IP address to get an accurate working IP. If that is an accurate method.
What would you suggest I assign as a MAC address if the board does not have one on it? I have read that I can make one up but that has not worked either. Please let me know if I make any other dumb mistakes. I'd rather fix it, learn from it and move on than continue running into walls.

Changes to the code:

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,254,254 }; //Router IP
byte server[] = { 74,125,225,148 }; //Google

EthernetClient client;

void setup()
{
Serial.begin(9600); //start the serial library
Ethernet.begin(mac,ip);
delay(1000); //give the ethernet hardware a second to initialize

I also just saw the error in the gateway value and tried this change but still no connection.

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,254,30 }; //airport IP
byte server[] = { 74,125,225,148 }; //Google
byte dns_server[] = { 192,168,254,254 }; //router IP

EthernetClient client;

void setup()
{
Serial.begin(9600); //start the serial library
Ethernet.begin(mac,ip,dns_server);
delay(1000); //give the ethernet hardware a second to initialize

Use the router ip for your dns server and gateway. Otherwise, no internet connection.

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress  ip( 192,168,254,30); //airport IP
IPAddress server( 74,125,225,148); //Google
IPAddress gateway( 192,168,254,254); //router IP

EthernetClient client;

void setup()
{
  Serial.begin(9600); //start the serial library
  Ethernet.begin(mac,ip,gateway,gateway);
  // rest of your setup
}

Thanks for your suggestion. I've tried that a couple times. Still no connection. :drooling_face:

connecting...
connection failed

disconnecting.

Heres the changes as you suggested surferTim. (This is probably a stupid question but would the subnet mask be of any use here?)(P.S. The last code I was working with did eventually connect with the sample MAC address and my airport IP.)

/*

  • Simple Web Client
  • Arduino 1.0 version
    */

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

byte mac[] = { 0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF };
byte ip[] = { 192,168,254,30 }; //airport IP
byte server[] = { 74,125,225,51 }; //Google
byte dns_server[] = { 192,168,254,254 }; //router IP
byte gateway[] = { 192,168,254,254}; //router IP

EthernetClient client;

void setup()
{
Serial.begin(9600); //start the serial library
Ethernet.begin(mac,ip,dns_server,gateway);
delay(1000); //give the ethernet hardware a second to initialize

I think you may be using the incorrect network settings. What make and model router are you using? Is it an Airport extreme?

edit:Try this sketch:

#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());
      Serial.println(Ethernet.gatewayIP());
  }
}

void loop() {
}

My Router is made by Net Gear. Model # B90-75504-15, ADSL 2+ Modem Router, distributed through Frontier.

It looks like you might be right?

The code returned "starting ethernet . . . failed."

What should I be looking for setting wise?

Again thank you for your patience and assistance. I just started working with the Arduino and learning about what the internet is this past year, through books and forums. I'm a fabricator and mold maker; a curious shop dog trying to learn some new tricks.

Netgear routers normally use 192.168.0.1 on the localnet interface, but your Arduino should have gotten an ip from the dhcp server in the router. The fact it didn't is not a good sign. Insure the network cable is connected correctly and the router and ethernet shield network lights are lit.

edit: Try this sketch. It tests the SPI bus and SPI side of the w5100. If it doesn't show the ip as 192.168.0.2 (like 0.0.0.0 instead), then the SPI bus or the SPI side of the w5100 is failing. Check to insure the shield is connected firmly on the Arduino, especially the ICSP pins. Those are the SPI data lines.

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

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

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

  // disable SD card if one in the slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

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

  Serial.println(Ethernet.localIP());
}

void loop() {
}

The code returned:

StarStarting w5100
192.168.0.2

I've got lights on in the port, on the board: link going out briefly and at semi-regular intervals while rx comes on at those intervals. Pwr, Spd and Fdx leds are on steady. Routers on, with wireless, dsl, internet, and power indicators on. The internet connection has been functioning normally otherwise.

Then the SPI bus and the SPI side of the w5100 is working.

Can you access the router's setup? That may help you troubleshoot this. The dhcp server function should be working ok unless you have disabled it.

Do you have anything else connected to the Arduino besides the ethernet shield?

The DHCP is still on. No other hardware connected to the arduino. The setup looked just like the attached photo. I'm not sure if I can access the routers settings, just found a how to here: How to Log Into a Router.
Is this what you mean? What should I look for if I can get access?

400px-Ethernet_shield_hard.jpg

Netgear routers should have the setup at 192.168.0.1. Try that in your computer connected to the Netgear router.
http://192.168.0.1
You should get a login page.

Try this

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

byte mac[] = { 0x0A, 0x0B, 0x0C, 0x0D, 0x=0E, 0x0F };  //A unique MAC address (L2)
IPAddress  ip( 192, 168, 254, 111);  //A unique IP Address (L3)
IPAddress dns(8, 8, 8, 8); //Google DNS
IPAddress gateway( 192,168,254,254); //router IP
IPAddress subNetMask(255, 255, 255, 0);  //A typical LAN subnet mask

IPAddress server( 74, 125, 225, 148); //Google

EthernetClient client;

void setup(void) {
  Serial.begin(9600);
  Ethernet.begin(mac, ip, dns, gateway, subNetMask);
  delay(2000);  //do we really need this?

  if( !client.connect(server, 80) ){
    Serial.println("Something bad happened.  Stop.");
    while(1); 
  }
  else {  
     Serial.println("Yay!");
     if(client.connected()) {
        client.stop();
     }
   }
  //etc
}

Any better?

Basic rules of network addressing.

  • The MAC address must be unique on the local network segment, as it identifies the network interface electrically. Do not just copy a MAC from some other device on your network, like a PC or router. A MAC address must be exactly six 8 bit numbers.
  • The IP must be unique on the local subnet, as it identifies the network interface logically. Do not just copy an IP from some other device like your PC or router. The IP address must be within the subnet, which is a bit technical but for most home networks, the first three numbers will be the same as every other device on the subnet and the last number, must be different.
  • The DNS server address is not required, unless you are resolving domain names but Google's DNS server is as good as any.
  • The Gateway address is required, if you hope to route traffic off the local subnet and reach the internet. The gateway address is your routers IP address.
  • The subnet mask, defines the width of the subnet. The rules are a bit technical but for most home networks, 255.255.255.0 will do.

The IP addresses above, may all be retrieved from a DHCP server, by sending a DHCP request. Typically home routers are configured as DHCP servers by default. If the DHCP server has been disabled for some reason, then DHCP will not work. When a DHCP server is enabled, you can still set the IP addresses manually, but the addressing rules MUST be adhered to.

Hi Matt. Only Ethernet.begin(mac) returns an integer value. The static assignments are void return types. This won't work.

  if (!Ethernet.begin(mac, ip, dns, gateway, subNetMask) {
    Serial.println("Something bad happened.  Stop.");
    while(1); 
  }

Thanks. Fixed it, I think. Not in a position to compile at the mo.