2013-05-21 83 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的正确库(见上面的链接)来解决这个问题。

我希望这有助于... 迈克

相关问题