Pages: [1]   Go Down
Author Topic: Create unique SD filename automatically after reset, without extra hardware  (Read 1208 times)
0 Members and 1 Guest are viewing this topic.
Sydney Australia
Offline Offline
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I use an Arduino temperature and relative humidity logging package where I have to be able to disconnect the Arduino from a 9V power source to record the T and RH in various places. I wanted to be able to reset/restart the Arduino without losing any data already recorded on the SD card, and wanted to be able to do this without removing the SD card, and without using a real time clock hardware add-on or a connection to the outside world. Since I could not find any code to do this within this forum, or elsewhere on the internet, I wrote some filename creation code from scratch. I hope it might be of use to others. The attached zip file is the complete sketch, with plenty of comments.

Introduction within sketch is:

 Arduino temperature and relative humidty (DHT11) datalogger using SD card.
 Each time the Arduino is reset/powered up, a new data log file is created with a
 unique filename, leaving all other data log files intact on the SD card. To create the
 unique filename, no extra hardware such as a real time clock or other connection
 to the outside world is needed.
 The code to create each unique filename does not use C language pointers, keeping
 code easy to understand and adapt for other SD-related uses. The code also avoids using
 any type of random number as the basis for the filename. All files on the SD card are
 sequence numbered and thus are chronological.
 Any suitable SD card can be used - no "initialisation" of a formatted SD card is necessary.
 The hardware:
 Arduino + Ethernet shield with SD card slot
 DHT11 temperature and relative humidity sensor and 4k7 res
      (resistor connected between DHT11 pins 1 (Vcc) and 2 (Data)
 Green and red LEDs and 2x330R res

* (3.82 KB - downloaded 31 times.)

Offline Offline
Faraday Member
Karma: 41
Posts: 3783
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you could use a numbered filename like 000000.txt, and on startup look for the highest numbered file, increment it by one, create and open


Global Moderator
Offline Offline
Shannon Member
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OR, you can have a file (number.txt) in which the first free number is mentioned.

Rob Tillaart

Nederlandse sectie -,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: