2.2k
Recently I had problems getting my Arduino and ethernet shield working correctly, I found the following code which basically reports via the serial monitor whether the SD card is available and then will attempt to report the IP address assigned to the ethernet shield.
[codesyntax lang=”c”]
#include <SPI.h> #include <Ethernet.h> #include <SD.h> byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; void setup() { Serial.begin(9600); pinMode(10, OUTPUT); digitalWrite(10, HIGH); Serial.print(F("Starting SD...")); if(!SD.begin(4)) { Serial.println(F("failed")); } else { Serial.println(F("ok")); } Serial.print(F("Starting ethernet...")); if(!Ethernet.begin(mac)) { Serial.println(F("failed")); } else { Serial.println(Ethernet.localIP()); } digitalWrite(10, HIGH); } void loop() { }
[/codesyntax]