Hello. I'd like to ask if the community has any insights into what could be causing files which are written to my SD card from an Arduino Uno to become corrupted.
As you can see in the attached image, the filenames are slight variants of the specified filename "DATA001.TXT". Unfortunately I can't open the majority of them to piece together the data based on the timestamp.
Here is the data logging segment of my code for reference. I noticed that the files did not get corrupted when this function was the only one in my program, and it was running at a slower rate. This leads me to think that it can't keep up with the speed or somehow the other functions running in the loop are interfering with the recording. Are either of these hypotheses valid?
void write_to_SD() {
currentTime = millis(); // get current time
myFile = SD.open("DATA001.TXT", FILE_WRITE); // open and write to DATA001.TXT
Serial.print(myFile);
// if the file opened okay, write to it:
if (myFile) {
Serial.println("Writing to file...");
// Write to file
myFile.print(currentTime);
myFile.print("\t");
myFile.print(accelX);
//etc...
myFile.close(); // close the file
}
// if the file didn't open, print an error:
else {
Serial.println("Error opening file");
}
}
Please let me know if I can specify the problem more fully. There are a number of other details which I would be happy to provide but at this stage don't seem like candidates for a root cause (such as the power supply, other components in the system, etc.).
Thanks in advance for your help.