I am using an Arduino and microSD card to create a new file in a directory every time the Arduino powers on.
My code is as follows:
if (SDDetect) {
//// Count the amount of Files in the LogFiles Directory ////
countFile = SD.open("LogFiles/");
while (true) {
File entry = countFile.openNextFile();
if (! entry) {
break;
}
fileCount++;
}
fileCount++; //Add one to fileCount to creat the next file
//// Create a new file ////
String FileName = String("LogFiles/Log0") + fileCount + String(".csv");
logFile = SD.open(FileName, FILE_WRITE);
logFile.println("Header1, Header2, Header3, Header4, Header5, Header6, Header7, Header8");
}
This code works great the first time I run the code! Creates the file Log01.csv in the LogFiles directory, and writes the header to the CSV. I turn the Arudino off and turn it back on, and it creates another file Log02.csv and writes the header.
The issue is when I create a 3rd file. It creates Log03.csv and then freezes. I open up the SD card on my computer and it creates the file but did not write the header. If I delete the files in the directory and start again the same thing happens. Works great the first two times and then freezes on the 3rd. Any ideas as to why this is happening? Or is there any easier way to do what I am trying to achieve?