Pages: [1] 2   Go Down
Author Topic: Ethernet shield DHCP/Static IP error  (Read 4323 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm testing the Ethernet Shield with and Arduino Uno and I'm getting a DHCP error just using the example sketch.

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

    byte mac[] = { 0x90, 0xAD, 0xDA, 0x0D, 0x96, 0xFE };
    
    EthernetClient client;
    
    void setup() {
      Serial.begin(9600);
       while (!Serial) {
        ;
      }
    
      // start the Ethernet connection:
      if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        for(;;)
          ;
      }
      Serial.print("My IP address: ");
      for (byte thisByte = 0; thisByte < 4; thisByte++) {
        Serial.print(Ethernet.localIP()[thisByte], DEC);
        Serial.print(".");
      }
      Serial.println();
    }
    
    void loop() {
    
    }

I've opened the router admin and I can see it gave the arduino an IP address (192.168.1.101), associated with the MAC address. I've also tried static IP in the code (Ethernet.begin(mac,ip)) but it won't work as well.

I can't ping the shield IP. Everything is out of the box, the arduino and the shield. I haven't done anything with them, just connected the shield to the arduino and sent the code. It seems everything is working fine, the leds are blinking for both boards. Using arduino IDE 1.0.3

I'm getting the "Failed to configure Ethernet using DHCP"

I guess the problem is not the router, because it always worked fine, I could just plug the cable and some other pc get's internet access, no further configuration needed.
« Last Edit: January 18, 2013, 12:02:52 pm by andrepcg » Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code looks ok. 

Where did that MAC address come from?  Could there be a conflict on the network?

You won't get a ping response from the arduino unless you put code on it to respond to ICMP Ping packets.

-br
Logged

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

there is no conflict with IP's and MAC addresses.

The MAC address in the code came from the Shield sticker in the back of the board
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I removed the unneeded serial port check and the below code works with my netgear 614 router.


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

    byte mac[] = { 0x90, 0xAD, 0xDA, 0x0D, 0x96, 0xFE };
   
    EthernetClient client;
   
    void setup() {
      Serial.begin(9600);
   
      // start the Ethernet connection:
      if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        for(;;)
          ;
      }
      Serial.print("My IP address: ");
      for (byte thisByte = 0; thisByte < 4; thisByte++) {
        Serial.print(Ethernet.localIP()[thisByte], DEC);
        Serial.print(".");
      }
      Serial.println();
    }
   
    void loop() {
   
    }
   
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

Yep, I removed that serial check and it's still not working.

What could be the issue here?
Logged

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

Do you have a microSD card in the slot?

I use this to test the SPI connection. If the serial monitor shows 192.168.2.2, then it is ok. If it shows anything else, like 0.0.0.0, then it failed.
Code:
#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 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() {
}
Logged

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

i did that and it worked! now i'm trying to connect to a webserver, using this tutorial http://bildr.org/2011/06/arduino-ethernet-client/ but I'm getting connection error..

EDIT: defining pin 4 as output and set it to HIGH made it work on the previous example but if I try to do with DHCP and aplying HIGH to pin 4 it will show "DHCP failed"
« Last Edit: January 18, 2013, 01:05:43 pm by andrepcg » Logged

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

Mine works with zoomkat's dhcp code if I remove the SD card, or disable the SD SPI. I use a Mikrotik RB433AH for the gateway/dhcp server.
Logged

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

maybe there's something wrong it my configuration somehow.. i've tested with a lot of different code I found on the internet, including the ones in this post but I can't manage to get this working.

my router is a Thomson TG784n, maybe there's something off but I don't know what... If you guys know something please tell me. Thanks!
Logged

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

Try another router. Works with Cisco stuff too. I checked it with my ISP's router. Got an ip and was pingable.
Logged

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

Try another router. Works with Cisco stuff too. I checked it with my ISP's router. Got an ip and was pingable.


hie, sorry i'm new to the forum and arduino as well, i'm trying to connect my arduino ethernet shield as a web client using DHCP but i dont have a router, is it possible for me to connect it to my pc via ethernet cable. i've tried the DHCP example from http://arduino.cc/en/Reference/EthernetLocalIP but i keep getting the error : Failed to configure Ethernet using DHCP. i'm using arduino uno r3 and a w5100 ethernet shield and arduino 1.0.4 IDE, the LEDs flash if i push the reset button. i would greatly appreciate your help or suggestions
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i dont have a router, is it possible for me to connect it to my pc via ethernet cable.

If you are using a windows machine, you will probably need to use something like internet connection sharing (ICS).
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

thank you for the response smiley-grin
i had to restart my machine, probably to reset the ethernet
and i used this code to test my connection and Woohoo! it worked with my static ip
here's the code i used to test

Quote
//zoomkat 12-08-11
//simple client test
//for use with IDE 1.0
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 

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

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x3E, 0x48 }; //physical mac address
byte ip[] = { 192,168,137, 170 }; // ip in lan assigned to arduino
//byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
//byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
byte myserver[] = { 208, 104, 2, 86 }; // zoomkat web page server IP address
EthernetClient client;
//////////////////////

void setup(){

  Ethernet.begin(mac, ip);
  //Ethernet.begin(mac, ip, subnet, gateway);
  Serial.begin(9600);
  Serial.println("Better client test 12/01/11"); // 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(myserver, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    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

}



thank you once again  smiley-lol
i'd like to know how i can use it to connect it to my local wampserver with mysql so that i can store a cellnumber and serial number remotely.
I'm going to hook up a 4x3 keypad, 20x4 lcd in 4 bit mode, ethernet shield and the arduino uno r3.
any suggestions will be greatly appreciated
Logged

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

Can we please get back to the original topic about andrepcg's problem?  I have the same setup: Aduino Uno + ethernet shield + LCD keypad shield.  There is no SD card inserted in the ethernet shield. 

If I remove the LCD shield DHCP works just fine.  I can even ping my setup without any additional code to handle ICMP ping packets.  However, if I add the LCD shield back onto the stack DHCP works unreliably.  I print the ethernet board's IP address to the LCD screen and I get different addresses everytime or none at all.

Btw, my network setup includes a Linux server acting as a DHCP server where I'm actually assigning a specific IP address to a request from a specific MAC address.  In other words, it is like having a static IP address but one that I can change simply by editing my dhcp.conf file on the server.  I don't have to go to each device to set its IP address.

I suspect a conflict in the pins used by the lcd (8, 9, 4, 5, 6, & 7 in the LCD sample code I'm using) and the pins used by the ethernet shield.  What pins are used by the ethernet shield?  Is it possible to change the pins each of the shields uses to avoid conflicts?
« Last Edit: July 05, 2013, 11:12:19 am by TerryB » Logged

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

Can we please get back to the original topic about andrepcg's problem?  I have the same setup: Aduino Uno + ethernet shield + LCD keypad shield.  There is no SD card inserted in the ethernet shield. 

If I remove the LCD shield DHCP works just fine.  I can even ping my setup without any additional code to handle ICMP ping packets.  However, if I add the LCD shield back onto the stack DHCP works unreliably.  I print the ethernet board's IP address to the LCD screen and I get different addresses everytime or none at all.
Then this is not the same problem and topic as the OP. That part was solved, as it appears it is with your's. Now you have a LCD conflict problem. I recommend starting a new thread with the following info:
Your sketch code.
What LCD shield are you using?
How are you powering all this? The ethernet shield takes a bit of power on its own.
Logged

Pages: [1] 2   Go Up
Jump to: