2013-05-21 125 views
1

我一直非常想在我的Arduino uno上運行以太網> DHCPAddressPrinter示例,但是沒有效果,每次運行它都會返回錯誤不能分配MAC地址給Arduino uno以太網盾

無法使用DHCP

我已經嘗試了各種各樣的事情,那是禁用防火牆,重置板/屏蔽配置的以太網,在啓動它給了我一個IP,但是這是唯一的一次,我關掉了路由器,當我打開它以後,我就無法將MAC和IP分配給以太網場。

有誰知道如何解決這個問題?

這裏是草圖即時試圖運行

/* 
    DHCP-based IP printer 

This sketch uses the DHCP extensions to the Ethernet library 
to get an IP address via DHCP and print the address obtained. 
using an Arduino Wiznet Ethernet shield. 

Circuit: 
* Ethernet shield attached to pins 10, 11, 12, 13 

created 12 April 2011 
modified 9 Apr 2012 
by Tom Igoe 

*/ 

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

// Enter a MAC address for your controller below. 
// Newer Ethernet shields have a MAC address printed on a sticker on the shield 
byte mac[] = { 
    0xDE, 0xAD, 0xBD, 0xEF, 0xFE, 0xED 
}; 

// Initialize the Ethernet client library 
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP): 
EthernetClient client; 

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

    // start the Ethernet connection: 
    if (Ethernet.begin(mac) == 0) { 
    Serial.println("Failed to configure Ethernet using DHCP"); 
    // no point in carrying on, so do nothing forevermore: 
    for(;;) 
     ; 
    } 
    // print your local IP address: 
    Serial.print("My IP address: "); 
    for (byte thisByte = 0; thisByte < 4; thisByte++) { 
    // print the value of each byte of the IP address: 
    Serial.print(Ethernet.localIP()[thisByte], DEC); 
    Serial.print("."); 
    } 
    Serial.println(); 
} 

void loop() { 

} 

回答

2

是否要連接到在其上具有DHCP服務器的網絡,通常路由器設置爲一。如果沒有,你必須分配一個靜態IP給你的arduino。

這可以像這樣使用以太網libray

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
IPAddress ip(192,168,0,177); // make sure this is in the subnet of your network 
EthernetClient client; 
Ethernet.begin(mac, ip); 

它看起來像你只需要打印的知識產權不能得到每個字節來完成。從Ethernet.localIp()文檔

// print your local IP address: 
    Serial.println(Ethernet.localIP()); 

也可以嘗試在webServer例子。然後看看你是否可以瀏覽到被在瀏覽器中打印出來的IP(但願不是0.0.0.0)

+0

我想這碼早些時候它顯示'0.0.0.0'的IP地址,我也通過啓用和禁用DHCP服務器 – dakait

+0

試過你嘗試使用不同的MAC地址? –

+0

是的,我把它拿到了IP一次,但是當我用相同的MAC再次拔掉它,它pluffed它沒有獲得IP從那時起,可能是我的盾牌被打破 – dakait

2

如果你的以太網卡有SD卡插槽,請確保在它裏面沒有SD卡,或跟隨建議在這個博客:http://startingelectronics.com/tutorials/arduino/ethernet-shield-web-server-tutorial/basic-web-server/

pinMode(4, OUTPUT); 
    digitalWrite(4, HIGH); 
+0

啊現在已經很長時間了,但是沒有SD插槽,我嘗試了所有的修正,但最後在接近TNN的時候做了一些改變,爲您的時間 – dakait

+0

爲我解決了它,我有它的SD卡,補給它!多謝,夥計 – CatalinBerta

0

對於Seeed工作室V2.4,一定要使用這裏找到庫:https://github.com/Seeed-Studio/Ethernet_Shield_W5200

我看到了這個同樣的問題。我的Seeed Studios Ethernet Shield v2.4報告的IP地址不正確。我看到了0.0.0.0和其他奇數值。我認爲有趣的是,使用標準/默認Arduino以太網盾庫爲另一家公司的盾牌提供了任何結果,更不用說IP地址格式正確的數字。我通過下載適用於我的型號和版本的Ethernet Shield的正確庫(見上面的鏈接)來解決這個問題。

我希望這有助於... 邁克

相關問題