SD Card: dynamic file name

MaxG:
Thank you for your reply!

Hmm, at first I thought: darn, have I been caught out again with this nasty mistake; but the 8.3 file name is 12 chars long plus \0 = 13.

123456789012

20170702.csv




I have done further testing by using the standard examples; list file, readwrite, card info... they all work fine.
So it must be something in my code.

I have also deleted a file, after that, the directory (on Windows) looks like this -- see attachment...

I have no further news at present, but will try the SDfat library... and report back.

You're right, I cannot count 8 + 4 =12 +1 = 13.

Somehow my brain was seeing a reference to filename[13], which is actually the 14th character.

Sorry,

Now, on a closer inspection, I have concerns on your DS3231 library. You reference DS3231.h, who's library are you using?

the reason I ask is that this function call:

strcat(fileName, clock.dateFormat("Ymd", dt));

Has me really concerned. I found a github library GitHub - jarzebski/Arduino-DS3231: DS3231 Real-Time-Clock that seems equivalent.

Looking at it's dateFormat() function causes shivers up my spine.

Basically their code is like this:

char * dateFormat(const char *formatstring, RTCDateTime td){
char buffer[256]

//fill buffer according to formatstring[]

return buffer;
}

First,they are allocating a large buffer 256 bytes, 1/8th of the UNO's Ram. UNO's only have 2048 total bytes of RAM.

Second, they return a pointer to a buffer that no longer exists? they hope that nothing else has disturbed the stack before you use this formatted value?

Your weird random behavior may be a result of someone's poor programming habits.

Add this function to your sketch, call it and display the results. It will give you a instantaneous free memory count in bytes. see if you are running out of RAM.
Code from AdaFruit: Measuring Memory Usage

int freeRam () 
{
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}

Chuck.