#include "SPI.h"
#include "Ethernet.h"
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte server[] = { 173,194,126,119 }; // www.google.co.th
EthernetClient client;
void setup()
{
Serial.begin(9600);
if(Ethernet.begin(mac) == 0) { // start ethernet using mac & DHCP
Serial.println("Failed to configure Ethernet using DHCP");
while(true) // no point in carrying on, so stay in endless loop:
;
}
delay(1000); // give the Ethernet shield a second to initialize
Serial.print("This IP address: ");
IPAddress myIPAddress = Ethernet.localIP();
Serial.print(myIPAddress);
if(client.connect(server, 80)>0) {
Serial.println(" connected");
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
// uncomment the next line to show all the received characters
// Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
}
อัพโคดตามนี้แล้วSerial Monitorขึ้นว่า Failed to configure Ethernet using DHCP แก้ไงยังไงครับ
กดแล้วครับผม พอกดบางครั้งจะขึ้น Failed to configure Ethernet using DHCP เลยบางครั้งต้องรอสักพักถึงจะขึ้นครับ
กรณ๊นี้ ผมไม่แน่ใจเหมือนกันครับ อาการได้บ้างไม่ได้บางมีหลายสาเหตุ อาจจะลองเขียนโคด delay ตอนเริ่ม boot ดูครับ
ต่อขา spi ถูกหรือเปล่าครับ
ตำแหน่งขาของ uno กับ mega จะไม่ตรงกัน
ขอบคุณครับ
บางทีอาจเป็น auto reset ตามนี้ครับ
http://forum.arduino.cc/index.php?topic=163548.0