I'm a bit of an arduino noob so bear with me... I have an ethernet shield with SD card reader (with my Diecimila). Got it connected to the network fine, but I'm getting problems reading from the SD card. If I use this program:
#include <SD.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
Serial.flush();
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
Serial.flush();
delay(1000);
File f = SD.open("TEST.TXT");
if(f) {
while(f.available()) {
Serial.write(f.read());
}
} else { Serial.println("No open"); }
}
void loop(void) {
}
I get no output whatsoever. If I comment out the SD.open part:
}
Serial.println("card initialized.");
Serial.flush();
delay(1000);
/*File f = SD.open("TEST.TXT");
if(f) {
while(f.available()) {
Serial.write(f.read());
}
} else { Serial.println("No open"); }*/
}
Then I get output on the serial port. So it seems like SD.open hangs my device. How can I resolve this?