Description
The example code here: https://www.arduino.cc/en/Tutorial/Files needs pin 10 set high before you call SD.begin(4) or else initialization fails.
This code works:
// while (!Serial) {
// ; // wait for serial port to connect. Needed for Leonardo only
// }
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
This code does not:
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");