#include // Using SPI1 const int _SCK = 10; const int _MISO = 12; const int _MOSI = 11; const int _CS = 13; File sd_file; void setup_sd() { Serial.print("Initializing SD card..."); // Ensure the SPI pinout the SD card is connected to is configured properly SPI1.setRX(_MISO); SPI1.setTX(_MOSI); SPI1.setSCK(_SCK); // see if the card is present and can be initialized: while (!SD.begin(_CS, SPI1)) { Serial.println("Card failed, or not present"); // don't do anything more: delay(1000); } Serial.println("card initialized."); } void sd_write(String filename, String gps_data) { File sd_file = SD.open(filename, FILE_WRITE); if (sd_file) { //if the file is available, write to it: sd_file.println(gps_data); sd_file.close(); // print to the serial port too: Serial.print("Writing to SD: "); Serial.println(gps_data); } else { // if the file isn't open, pop up an error: Serial.println("error opening the GPX file for writing"); } } void sd_read(String filename){ // re-open the file for reading: File sd_file = SD.open(filename); if (sd_file) { Serial.print("Reading file "); Serial.println(filename); // read from the file until there's nothing else in it: while (sd_file.available()) { Serial.write(sd_file.read()); } Serial.println("End of file"); // close the file: sd_file.close(); } else { // if the file didn't open, print an error: Serial.println("error opening ride.gpx"); } }