Improving SD card logger script

Your files may be just getting too cumbersome. Since you have an on board clock, you can use it to name a series of files. This may fix your problem simply by having smaller files. Even if it doesn't, you may ultimately find it a better way to manage files.

You might find this code useful. I simply call it up once at midnight

#include <SD.h>
#include "RTClib.h"
#include <Wire.h>
#include <string.h>


RTC_DS1307 RTC;

char filename[] = "00000000.CSV";

File myFile;


void setup()

{

Serial.begin(9600);

Wire.begin(); //Important for RTClib.h

RTC.begin();

if (! RTC.isrunning()) {

Serial.println("RTC is NOT running!");

// following line sets the RTC to the date & time this sketch was compiled

// RTC.adjust(DateTime(__DATE__, __TIME__));

return;

}

Serial.print("Initializing SD card...");

// On the Ethernet Shield, CS is pin 4. It's set as an output by default.

// Note that even if it's not used as the CS pin, the hardware SS pin

// (10 on most Arduino boards, 53 on the Mega) must be left as an output

// or the SD library functions will not work.

pinMode(10, OUTPUT);


if (!SD.begin(4)) {

Serial.println("initialization failed!");

return;

}

Serial.println("initialization done.");


}

void loop()
{

getFileName();

createFileName();

delay(3000);

}

void getFileName(){

DateTime now = RTC.now();

filename[0] = (now.year()/1000)%10 + '0'; //To get 1st digit from year()
filename[1] = (now.year()/100)%10 + '0'; //To get 2nd digit from year()
filename[2] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()
filename[3] = now.year()%10 + '0'; //To get 4th digit from year()
filename[4] = now.month()/10 + '0'; //To get 1st digit from month()
filename[5] = now.month()%10 + '0'; //To get 2nd digit from month()
filename[6] = now.day()/10 + '0'; //To get 1st digit from day()
filename[7] = now.day()%10 + '0'; //To get 2nd digit from day()
//filename[8] = filename + ".csv";
}

void createFileName(){
myFile = SD.open(filename, FILE_WRITE);
myFile.close();
}