No More then 7 files on SD Card

Hi All,

I build a logprogram which write data to a file. Each day a new file is created. But after 7 files it stops creating files and also the last file is empty. First I thought, maybe I need to close the old file yet, but addind this does not seem to make any difference. Does anyone know what the problem might be.
Underneath the part of the code code which creates the files.

void getFileName(){
//Filename op basis van datum
if (! SD.exists(filename)) {

DateTime now =;
filename[0] = + '0'; //To get 1st digit from day()
filename[1] = + '0'; //To get 2nd digit from day()
filename[2] = now.month()/10 + '0'; //To get 1st digit from month()
filename[3] = now.month()%10 + '0'; //To get 2nd digit from month()
filename[4] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()
filename[5] = now.year()%10 + '0'; //To get 4th digit from year()
Day_old =;
Serial.println (filename);
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i / 10 + '0';
filename[7] = i % 10 + '0';
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile =, FILE_WRITE);
break; // leave the loop!
if (! logfile) {
error("couldnt create file");
Serial.print("Logging to: ");

// prints the data to logfile and echoos to Serial is ECHO_TO_SERIAL is set
void logData(DateTime now, uint32_t m) {

Serial.print(m); // milliseconds since start
Serial.print(", ");
#endif // ECHO_TO_SERIAL

//iedere 2 minuten naar de logfile schrijven
//if (Min_old >=58){Min_old = 0;}

if (!= Day_old) {
logfile.println("millis,stamp,date,time,aanvoertemp , retourtemp, warmwater, buitentemp");

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

1 Like

By posting snippets of your code, it doesn't make helping any easier.
For example: What type of array is "filename[ ]".

What prints on the line " Serial.println(filename); " each day?

RV - mineirin

Maybe that should be:

  if (logfile) {

The code is mostly verbose and/or redundant. You should need no more than these snippets

#include <SD.h>
char filename[] = "000000.CSV";

void setup() {
    today = day; // flag for later midnight check

void loop() {  
  if (today != day)
   today = day;

void getFileName(){
sprintf(filename, "%02d%02d%02d.csv", year, month, day);

While it may not be a part of the immediate problem, closing the file in the flow of the programmes unnecessary, bad practice, and is pretty certain to cause you grief eventually.

What's the "GetClock" ? Do I need a library for that ?

Pardon my crypticism. As is evident by the way it is written


`"GetClock" is simply a subroutine that returns the variable "day" by whatever means, the most common of which is by use of an RTC - as you are probably already doing.

That variable has two uses:

  1. as a flag that it is midnight and time to change the filename
  2. as part of the filename char

No library need be involved here. If you are using a library to get the time, you might as well stick with it, but it is not essential.
bildr » Do You Have The Time? DS1307 RT Clock + Arduino

Thanks, did did the job, now the logging continues

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.