2014-04-25 4 views
2

Arduino 메가 r3와 이더넷 실드 조합을 사용합니다. DhcpAddressPrinter 예제를 사용할 때 어떤 결과도 얻을 수 없습니다. 나는 어떤 코드도 바꾸지 않았다. 다음과 같이Arduino 예제의 DhcpAddressPrinter가 작동하지 않습니다.

#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[] = { 
    0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 }; 

// 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() { 

} 

그 후, 나는 코드의 일부 "에 println"를 추가 : 사용법 #include 사용법 #include

// Enter a MAC address for your controller below. 
// Newer Ethernet shields have a MAC address printed on a sticker on the shield 
byte mac[] = { 
    0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 }; 

// 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: 
    Serial.println("1"); 
    while (!Serial) { 
    ; // wait for serial port to connect. Needed for Leonardo only 
    } 
    Serial.println("2"); 
    // start the Ethernet connection: 
    if (Ethernet.begin(mac) == 0) { 
    Serial.println("3"); 
    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() { 

} 

나는 시리얼 모니터의 결과 (1)과 (2)를 얻을 수 있지만, 3를받을 수 없습니다 ; 그래서 Ethernet.begin (mac) 함수가 계속 실행되고 있는지, 그리고 그 이유를 모르는지는 의심 스럽습니다. 다른 사람에게 MAC 주소를 변경했지만 동일한 결과가 나타납니다.

답변

0

같은 시간에 microSD를 사용하고 있습니까? 때로는 이더넷 실드의 DHCP 문제가 발생할 수 있습니다.

관련 문제