Hi, I have a GPS system that is installed in a vehicle. That means it can be turned off without warning.
I am sometimes getting garbage written to an SD card file, my guess is it was shut down before closing the file.
I am trying to keep the time between opening the file and closing it as short as possible. Is there some way to make an entire "string" to print before opening then do it in one action?
The caveat is that I am desperately low on Flash (409-Bytes) so need to make any concatenating as memory-lean as possible. I am thinking that if I can have one complete string, "03/29/2017,12:24:33,49.12345,-149.12345,..." then an Open, a single Print-line and Close, might lessen the risk at engine shut downs..
gpsFile = SD.open(fname,FILE_WRITE);
if (gpsFile) {
sprintf(gpsDT,"%02d/%02d/%02d",gpsMonth,gpsDay,gpsYear);
gpsFile.print(gpsDT);
gpsFile.print(F(","));
sprintf(gpsDT,"%02d:%02d:%02d",gpsHour,gpsMinute,gpsSecond);
gpsFile.print(gpsDT);
gpsFile.print(F(","));
gpsFile.print(gps.location.lat(),10);
gpsFile.print(F(","));
gpsFile.print(gps.location.lng(),10);
gpsFile.print(F(","));
gpsFile.print(gps.speed.mph(),2);
gpsFile.print(F(","));
gpsFile.print(gpsCourse());
gpsFile.print(F(","));
gpsFile.print(gps.altitude.feet(),2);
gpsFile.print(F(","));
gpsFile.print(gps.satellites.value());
gpsFile.println();
gpsFile.close();
} else {
Serial.println(F("Failed to open file"));
} // gpsFile
I found this, but not sure if it helps or not.
http://forum.arduino.cc/index.php?topic=96299.0