I have the Arduino Ethernet (
http://arduino.cc/en/Main/ArduinoBoardEthernet) and am having brain death on getting the ethernet and sd card to work at the same time. On their own they both work but as soon as I add the SD.h file things go wrong and I have to power off the Arduino before I can get anything working again. Anybody have any working code or an idea what I am doing wrong ?
This is my basic stripped down code.
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Time.h>
//#include <MemoryFree.h>
#include <SD.h>
byte mac[] = {
0x90, 0xA2, 0xDA, 0x00, 0xF2, 0x1E };
EthernetClient client;
EthernetUDP Udp;
byte SNTP_server_IP[] = { 192, 43, 244, 18}; // time.nist.gov
const long timeZoneOffset = 0L; // set this to the offset in seconds to your local time;
/* sd card */
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 4;
void setup() {
Serial.begin(9600);
//pinMode(10, OUTPUT);
Serial.println("Starting...");
pinMode(6, OUTPUT);
digitalWrite(6, HIGH);
/* Check SD Card */
Serial.println("Initializing SD card...");
//digitalWrite(10, HIGH); // If it's low, the Wiznet chip corrupts the SPI bus
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
}
else {
Serial.println("Wiring is correct and a card is present.");
// print the type of card
Serial.print("\nCard type: ");
switch(card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
}
/* Get DHCP Address */
//digitalWrite(10, HIGH);
Serial.println("Requesting DHCP Address.");
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("IP Address assigned: ");
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();
Udp.begin(4343);
delay(500);
Serial.println("Waiting for NTP time sync");
setSyncProvider(getNtpTime);
while(timeStatus() == timeNotSet)
; // wait until the time is set
//connectToServer();
//digitalWrite(10, LOW);
}