My Arduino Mega recently decided that it will no longer write to SD cards. I can't figure out what's going wrong.
I connected pin 8 on the SD card to pin 53 on the Mega and am running the following code.
Any ideas?
// Include libraries. Someone else wrote code that we can reuse
#include <SD.h>
// SDCARD Variables
File myFile;
const int chipSelect = 8;
void setup()
{
Serial.begin(115200);
///////// SD CARD SETUP ////////////////
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) { // ERROR is HERE!
Serial.println("Card failed, or not present"); // don't do anything more:
return;
}
else {
Serial.println("SD card initialized.");
}
///////// SETUP CSV FILE ////////////////
// Write File Header
myFile = SD.open("HEROCKET.CSV", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.println("Writing CSV Header Data");
myFile.println("Time, TempC, TempF, PSI, Sats, Lat(deg), Lon(deg), Alt(m), Course, Speed(mph), Dir");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening HEROCKET.CSV");
}
}