Go Down

Topic: SD Card - Auto Index File Name to next available file (Read 214 times) previous topic - next topic

cyotani

Sep 27, 2014, 05:59 am Last Edit: Sep 27, 2014, 06:08 am by cyotani Reason: 1
I am trying to auto index an SD card file name by using the next available. I want to start with "1.csv" and if that already exists use "2.csv" and so on until I find the next unused file name. Then use that file name in my write to SD data logger. I am getting an error with the code bellow. It looks like I can not use a variable as a parameter.

Error is:
"no matching function for call to 'SDClass::exists(String&)'"

Any suggestions on how to accomplish this? Thanks!

Code: [Select]

#include <i2cmaster.h>
#include <SD.h>

//Set by default for the SD Card Library
//MOSI = Pin 11
//MISO = Pin 12
//SCLK = PIN 13
//We always need to set the CS Pin
int CS_pin = 10;
int pow_pin = 8;
unsigned long time;
int file = 0;
String fileString;

void setup()
{
Serial.begin(9600);
Serial.println("Setup...");

       //CS Pin is an output
       pinMode(CS_pin, OUTPUT);
       
       if (!SD.begin(CS_pin))
       {
         Serial.println("Card Failure");
         return;
       }
       Serial.println("Card Ready");
       
       
      fileString = (String(file) +".csv");
       while (SD.exists(fileString));
       {
         file = file + 1;
         fileString = (String(file) +".csv");
       }
     

cyotani

I finally got it to work! I found some older example in the forum and was able to adapt them to work. Here is my code for reference.

PS: please excuse my sloppy coding. I am new to text based coding.


Code: [Select]
#include <i2cmaster.h>
#include <SD.h>

//Set by default for the SD Card Library
//MOSI = Pin 11
//MISO = Pin 12
//SCLK = PIN 13
//We always need to set the CS Pin
int CS_pin = 10;
int pow_pin = 8;
//float refresh_rate = 0.0;
unsigned long time;
int file = 0;
char fileString[12];


void setup()
{
Serial.begin(9600);
Serial.println("Setup...");

        //CS Pin is an output
        pinMode(CS_pin, OUTPUT);
       
        if (!SD.begin(CS_pin))
        {
          Serial.println("Card Failure");
          return;
        }
        Serial.println("Card Ready");
       
       
       
       
     sprintf(fileString, "%02d.csv", file);
   
      do
        {
         file = file + 1;
         sprintf(fileString, "%02d.csv", file);
        } while (SD.exists(fileString));
       
      Serial.println(fileString);
         

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy