Create sequential folders in SD card

Hi everyone!

I'm using Arduino Due to acquire data from a sensor. So far it can acquire signals with a fine resolution and store it in an SD card (each signal is stored in a .txt file).
When I first turn the Arduino on, it creates a file (sig_1.txt) in the root folder of the SD card in the first loop. In the second loop it creates another file (sig_2.txt) also in the root and so on.

The problem that ran into is: every time I turn the Arduino on it'll continue to write the same files that were previously created (seg_1.txt. sig_2.txt etc). The arduino won't overwrite the data but still this can lead to errors when analyzing the results.

Therefore, I would like to change my code in a way that every time I turn on the arduino, it'll create another folder to store the data files with the same names (sig_1.txt, sig_2.txt etc). In this way I'd be able to store different data files in sequential folders.

Could anyone please help me??

Best regards,
Daniel

The mkdir() method would appear to do what you want to create directories.
Perhaps store the name of the current directory in EEPROM, then, when the Arduino reboots, read the directory name from EEPROM, update it, save it back to EEPROM and use the new directory when saving files.

UKHeliBob, thanks for your reply.

Just checking: In order to use Arduino's (due) EEPROM, I'll have to use 3rd-party libraries, right?

Do you know a good one?

Best regards,
Daniel

Hello,

Try this library: GitHub - sebnil/DueFlashStorage: DueFlashStorage saves non-volatile data for Arduino Due. The library is made to be similar to the EEPROM library.

Or, you could write the last used folder name in a file on the SD card... :slight_smile: