Cant write to SD Card from Arduino Mega

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");
}

}

I connected pin 8 on the SD card to pin 53 on the Mega and am running the following code.

i dont see you using pin 53 anywhere

pinMode(10, OUTPUT);

and maybe this is not correct because i also dont see you use pin 10 anywhere

Figured it out after exhaustive research. Here is the solution: Pasted from another forum. special thanks to adafruit.

FOR MEGA ARDUINOS edit the SD/utility/Sd2Card.h file after installing and uncomment the line that says #define MEGA_SOFT_SPI 1 to allow the Mega to use the same pinout for SD cards as the Classic Arduinos

the RTC i2c lines are not the same, search the forum for how to adapt the shield for the mega

Bottom line follow these steps:

  1. Edit /Applications/Arduino.app/Contents/Resources/Java/libraries/SD/utility/Sd2Card.h
    // change line to read
    #define MEGA_SOFT_SPI 1 // was 0