Go Down

Topic: SD card: automatic creation of new files in the program (Read 1 time) previous topic - next topic


May 24, 2011, 11:34 am Last Edit: May 24, 2011, 10:28 pm by Maax Reason: 1

When my ethernet connection is failled, my program creates a new file in the SD card and saves the value of the analog pin 0, while ethernet is disconnecting it creates a new file each second.I want that each new file take to name the time and date of my counter but it is not to have time, it is for there are not 2 files with the same name. When i retrieve the name for a file I use the function SD.open to create and open a new file with this name. But i have a problems of parameters.

Here is my code :
Code: [Select]

String  name=day+hour+minute;  // name= number of day, hour and minute of my counter
   myFile = SD.open(name, FILE_WRITE); // the problem is here, this function don't accept a String
   if (myFile)
        Serial.println("fichier ouvert"); // serial print "file open"
        myFile.println(data); // print the value of pin A0
        Serial.println("Impossible d'ouvrir le fichier"); // serial print "Can't open file"

I don't know how to solve the problem.

thanks you in advence

PS: I'm very sorry for my bad English


I don't know how to solve the problem.

Posting the same incomplete snippet of code under a new thread is NOT the way to do it. Stay with the existing threads you have, and answer the questions asked there.
The art of getting good answers lies in asking good questions.


sorry Pauls,  but I reposted here because before my subject was not in the right category


NOw you're in the right section an answer to your question.

1) you must have a string to build the filename.  You do that except you need to add seconds too.

2) you must check if the file exists e.g. by opening it for reading. If that succeeds the file exists, Close it, delay(a second) and create a new filename [goto step 1]

3) open the file for writing

The parameters can be found by examining the SD library code or examples that came with it.

Hopes this helps,

By the way please modify the first posting , selct the code and press the # button for proper presentation..

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up