Pages: [1] 2   Go Down
Author Topic: Ethernet Shield Not taking address  (Read 7411 times)
0 Members and 1 Guest are viewing this topic.
Atlanta
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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("<!DOCTYPE HTML>");
          client.println("<html>");
                    // 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("<br />");       
          }
          client.println("</html>");
          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
Logged

Stephen Bavington
sbavington@mac.com

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4755
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Atlanta
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Stephen Bavington
sbavington@mac.com

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4755
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Atlanta
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the fast response.

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

S


* P1070069.JPG (3283.46 KB, 3648x2736 - viewed 277 times.)
Logged

Stephen Bavington
sbavington@mac.com

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4755
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Atlanta
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Updated to 1.0.1 this morning.


Thanks
Logged

Stephen Bavington
sbavington@mac.com

Atlanta
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Stephen Bavington
sbavington@mac.com

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4755
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Atlanta
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Stephen Bavington
sbavington@mac.com

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4755
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Atlanta
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Stephen Bavington
sbavington@mac.com

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this:
Code:
#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?
Logged

Atlanta
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SD fail
server is at 0.0.0.0
Logged

Stephen Bavington
sbavington@mac.com

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1] 2   Go Up
Jump to: