Data logging to a SD card

Hi!

I'm currently working out to log all my data to a SD card and so far I have come up with the trouble of creating a new log file instead of writing to the same log after a system reset. (I'm a newbie) Can any of you guys help me out?

Creating the first log was easy as,

 myfile = SD.open("Test.txt", FILE_WRITE);

Thanks!

I leave data logging to a separate controller. See this: http://forum.arduino.cc/index.php?topic=281091.0

.

LarryD: I leave data logging to a separate controller. See this: http://forum.arduino.cc/index.php?topic=281091.0 .

Thanks LarryD, My data logging function isn't that much of a complex one. Just I have already set everything up. Only thing I need to do is creating a new log file at every system reset. I'm just bad with coding.

Use current date or time as the filename?

Do you really need to get a new filename at reset anyway?

Nick_Pyner: Use current date or time as the filename?

Do you really need to get a new filename at reset anyway?

But I have no such battery to keep up the system alive in order to record the correct time. Even if I use time library, it is useless as it sets to it's default at each reset.

By a new log at each reset would make it easier for the reference as I have thought.

Not sure of the exact code (I don’t have an SD reader)

// global variable to hold filename
char fileName[13];
void setup()
{
  // number to create unique filename
  byte fileNumber = 1;

  ...
  ...


  do
  {
    // check if we've used all filenumbers; if so, display message and halt forever
    if(fileNumber == 255)
    {
      Serial.println("Out of file numbers");
      for(;;);
    }

    // create a file name logNNN.txt
    sprintf(fileName,"log%03d.txt", fileNumber++);

    // and check
  } while(SD.exists(fileName));
}

fileName is global so can be used in any other function (e.g. loop())

sterretje: Not sure of the exact code (I don't have an SD reader)

This could work, thanks! I'll check it. Did you write the code?

sterretje: Not sure of the exact code

Thanks sterretje! And it worked. With a few modifications, I could make it work the exact way I wanted.