Ethernet Shield Not taking address

I'm pretty new to Arduino. I'v been going through the examples and find that most everything works except the Ethernet shield is not accepting IP Addresses. It always comes back 0.0.0.0 on the serial monitor.

My code looks like this:

/*
Web Server

A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.

Circuit:

  • Ethernet shield attached to pins 10, 11, 12, 13
  • Analog inputs attached to pins A0 through A5 (optional)

created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe

*/

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10,10,0, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(19200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
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("Connnection: close");
client.println();
client.println("");
client.println("");
// add a meta refresh tag, so the browser pulls again every 5 seconds:
client.println("<meta http-equiv="refresh" content="5">");
// 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("");
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 disonnected");
}
}

The serial Monitor gives me:

server is at 0.0.0.0

I have been surfing the forums for a day or so and tried many ideas with the same result.

The Arduino board is : Atmega328 Duemilanove
The Ethernet Shield is : HanRun HR911105A 10/49

I have link indications at both the Ethernet Shield and on my network switch. I also see traffic when i pin the broadcast so the layer 1 is working.

Any help appreciated

HanRun HR911105A is just the RJ45 connector. This is used for several shields with different chips. Which one do you use?

Does w5100 make sense? I'm really new too this as you can tell. :slight_smile:

Do you have something else connected to your Arduino or just the Ethernet shield? Looks like their is a hardware problem, maybe a pin is used twice.

Thanks for the fast response.

I think you're right but there is only the Arduino and the Ethernet Shield as shown.

S

Just to eliminate possible error sources: you're using the latest IDE version (1.0.1)?

Updated to 1.0.1 this morning.

Thanks

So I decided to try reading the SD card on the Ethernet Shield and see that it's not working either:

/*
SD card test

This example shows how use the utility libraries on which the'
SD library is based in order to get info about your SD card.
Very useful for testing a card when you're not sure whether its working or not.

The circuit:

  • SD card attached to SPI bus as follows:
    ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
    ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
    ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
    ** CS - depends on your SD card shield or module.
    Pin 4 used here for consistency with other Arduino examples

created 28 Mar 2011
by Limor Fried
modified 9 Apr 2012
by Tom Igoe
*/
// include the SD library:
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

Serial.print("\nInitializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT); // change this to 53 on a mega

// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}

// print the type of card
Serial.print("\nCard type: ");
switch(card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}

// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
return;
}

// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(volume.fatType(), DEC);
Serial.println();

volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
Serial.print("Volume size (bytes): ");
Serial.println(volumesize);
Serial.print("Volume size (Kbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.print("Volume size (Mbytes): ");
volumesize /= 1024;
Serial.println(volumesize);

Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);

// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) {

}

Serial output:

Initializing SD card...initialization failed. Things to check:

  • is a card is inserted?
  • Is your wiring correct?
  • did you change the chipSelect pin to match your shield or module?

Looks like it might be something in the hardware.

What to try next?

S

Have you tried powering the Arduino from a wall adapter? The Ethernet shield is consuming much more power than the Arduino itself and if your PC is not supplying enough power (many notebook on the market are not conforming to the standard in this regard) this may cause strange errors like the one you describe. Power it from a 9V wall power adapter and try again.

No joy there. Tried the Webserver and SD programs after powering from a wall brick. Same result :frowning:

Sorry to say that but sounds to me like a hardware defect. Either the Arduino or the Ethernet shield may have a damage. If you have a second Arduino, try the shield there. Almost identical setup works for me.

Sorry to hear that. I bought these too for this project and it never worked. I think I'll try another platform before buying possibly two more and finding out they don't work for some other reason. I'm also not going to buy into something that fails on the first try and can't be fixed.

I had high hopes for this.

thanks for you help.

Try this:

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

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

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

   // disable w5100 while setting up SD
   pinMode(10,OUTPUT);
   digitalWrite(10,HIGH);

   if(SD.begin(4) == 0) Serial.println("SD fail");
   else Serial.println("SD ok");

   Ethernet.begin(mac,ip);
   digitalWrite(10,HIGH);

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

void loop() {

}

What are the messages displayed on the serial monitor?

SD fail
server is at 0.0.0.0

Sounds like the ethernet shield is bad. If it is new, you should be able to get an exchange on it if the dealer is reputable. If not, it might be helpful to let us know who it is so we don't make the mistake of buying from that dealer.

I ordered through Amazon from Powoot as it turns out. It looks like my 30 day window expired so i'll see about a new one.

Love the web...

I had a long fight getting an Arduino Ethernet to work; in the end it was both
a broken compiler and broken libraries, which are fixed in 1.0.1

The sketch below is pretty minimal, and it might be worth trying to see if the
shield will respond - it finally ran on my Arduino Ethernet, which I think is
electrically pretty much identical.

// Test of Arduino using Telnet server.

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

// Undefine this to get a working program.
#define TELNET

// the media access control (ethernet hardware) address for the Arduino:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x92, 0x34 };

// network configuration - all except mac are optional.
// If the actual values aren't supplied, the default
// is the local_ip with last octet 1.
// void EthernetClass::begin(uint8_t *mac, IPAddress local_ip,
//   IPAddress dns_server, IPAddress gateway, IPAddress subnet)

// The default Arduino board address:
byte ip[] = { 192, 168, 1, 20 };
// The DNS server address:
byte dnss[] = { 192, 168, 1, 1 };
// the gateway router address:
byte gateway[] = { 192, 168, 1, 1 };
// the subnet mask:
byte subnet[] = { 255, 255, 255, 0 };

// telnet defaults to port 23
EthernetServer server(23);

void setup()
{
  // Initialise the serial device.
  Serial.begin(9600);
  delay(2000);
  Serial.println("setup()");

  // Disable SD SPI
  // Is this needed ???
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);

  // attempt a DHCP connection:
  Serial.println("Attempting to get an IP address using DHCP");
  // This requires the DHCP server to be x.x.x.1
  if (Ethernet.begin(mac) == 0) {
    // if DHCP fails, start with a hard-coded address:
    Serial.println("failed to get an IP address using DHCP, trying manually");
    Ethernet.begin(mac, ip); // function returns void
    //Ethernet.begin(mac, ip, gateway, gateway, subnet); // function returns void
  }
  else
    Serial.println("got an IP address using DHCP");

  // Start listening for clients.
  server.begin();
  // Say who we think we are.
  Serial.println(Ethernet.localIP());
}

void loop()
{
  Serial.println("loop()");

  // Initialise the client each pass ???
  EthernetClient client = server.available();

  // Read bytes from the incoming client and write them back
  // to any clients connected to the server.
#ifdef TELNET
  if ( client ) {
    char c = client.read();
    server.write(c);
  }
#endif

  // Can help debugging.
  delay(2000);
}

// eof

As you can see, the code is full of debugging odds and ends, but it's
what finally got my board working.

Good luck - Will

sbavington:
Thanks for the fast response.

I think you're right but there is only the Arduino and the Ethernet Shield as shown.

...

(3283.46 KB, 3648x2736 - viewed 6 times.)

Go easy on these 3 megabyte photos please. That takes a while to download, and then is too big to view in the web browser. A quick resize in your photo program will save everyone some effort.

I see from your photo that the shield does not appear to be plugged in properly. Those pins normally slide all the way into the sockets underneath. It looks to me like that are just touching. Maybe it has extra long pins, but you might want to check that by firmly pushing down on it.

Sorry about the picture. No problem to shrink.

As for the pins, they bottom out, but the pins on the Adurino seem shorter.

I cut 1/8" off all the pins and guess what?

server is at 10.10.0.177
new client
GET / HTTP/1.1
Host: 10.10.0.177
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive

client disonnected
new client
GET /favicon.ico HTTP/1.1
Host: 10.10.0.177
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
Accept: /
Referer: http://10.10.0.177/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive

client disonnected
new client
GET / HTTP/1.1
Host: 10.10.0.177
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Referer: http://10.10.0.177/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive

client disonnected
new client
GET / HTTP/1.1
Host: 10.10.0.177
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Referer: http://10.10.0.177/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive

client disonnected
new client
GET / HTTP/1.1
Host: 10.10.0.177
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Referer: http://10.10.0.177/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive

client disonnected

Are you saying it's working now?