The
datalogger example of the SD library has a bug. that makes the sketch not work with a Mega board and an Ethernet shield. It leaves the Ethernet chip selected, and this disrupts operations on the SPI port. (The same bug appears in the other SD example sketches.)
For Mega boards, you can add a line to the
setup() function to make sure that the Wiznet chip is not selected.
Open the
datalogger sketch and put a
digitalWrite(10, HIGH); statement right after the pinMode statement:
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
// For Mega boards with an Ethernet shield, make sure the Wiznet
// chip is not selected:
pinMode(10, OUTPUT);
digitalWrite(10, HIGH); // davekw7x: If it's low, the Wiznet chip corrupts the SPI bus
// 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.");
}
Note that this change does not affect operation of '328 boards. The pinMode and digitalWrite statements are both unnecessary, but do not cause any problems.
Note, finally, that you do not (that's
not) have to reformat your FAT32 cards. The Arduino SD library is a "wrapper" for the very excellent SdFat library. The SdFat library works perfectly for me for my smallest FAT16 card (8 Megabytes) to my largest FAT32 card (8 Gigabytes). It's true that FAT12 cards
do have to be reformatted to FAT16, but that's not a very big deal (in my opinion).
Regards,
Dave
Footnote:I do not have a Mega2560 board. My tests were carried out with a Mega1280 and the new Ethernet Shield. I don't know why the Arduino developers chose not to include more of the SdFat library examples. For me, SdFatInfo has been the single most helpful debugging tool for testing different hardware designs.. The others SdFat example sketches are extremely helpful in understanding basic operations on SD cards and their files.