Write the filename to the serial monitor, so you know what filename will be used. The filename must be in 8.3 format. That is the old FAT format for filenames.
If the filename is longer, it is not accepted.
You probably are running into a problem with lack of ram.
It is not a good idea to use the String class at all because it tends to use a lot of ram. Get rid of it completely - use character arrays/strings instead.
You are essentially doing the same as me, and your code looks like a date-as-filename snippet. I guess yoiur only problem is falling into the string trap. Here is a working version.
RTC_DS1307 RTC;
char filename[] = "00000000.CSV";
File myFile;
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()
}
void createFileName(){
myFile = SD.open(filename, FILE_WRITE);
myFile.close();
}
Nick_Pyner:
You are essentially doing the same as me, and your code looks like a date-as-filename snippet. I guess yoiur only problem is falling into the string trap. Here is a working version.
RTC_DS1307 RTC;
char filename[] = "00000000.CSV";
File myFile;
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()
I have had similar problems and traced it to the lack of memory. The UNO has only 2k so in researching the problem, I discovered that the SD library uses over 600 bytes, SoftwareSerial uses about 100 bytes, and the SD requires another 392 locations to perform the list files example.
You are looking in the wrong place. The Uno has about 32k of memory for your programmes and the data in question is simply passed through to the SD card anyway. The size of the programme is shown at the bottom of the window when you compile it. The Uno may not actually be the best choice for data logging, but data storage is usually the least of its problems.