Data Logger - Prevent Multiple Files

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
daveatbluebarrel
 
Posts: 1
Joined: Fri Sep 02, 2011 5:48 am

Data Logger - Prevent Multiple Files

Post by daveatbluebarrel »

I followed the directions for the Data Logger tutorial and everything went as planned. My only issue is that every time I check the contents of the SD card there is multiple files. Is there a way to make the Data Logger create only one file per active session. In other words, once I turn the Arduino on and/or upload my sketch and then I turn the Arduino off I want there to be only one file instead of multiple files.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Data Logger - Prevent Multiple Files

Post by adafruit_support_bill »

The sketch creates one file every time you upload or reset your Arduino. This code looks for a file name that hasn't been used yet. If you want to always log to the same file, just eliminate the for loop and open the file.

Code: Select all

  // create a new file
  char filename[] = "LOGGER00.CSV";
  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 = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }
  }

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”