Pages: [1]   Go Down
Author Topic: SD card: automatic creation of new files in the program  (Read 846 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

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:
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
         myFile.close();
       }
    else
       {
         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
« Last Edit: May 24, 2011, 03:28:24 pm by Maax » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 633
Posts: 50188
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 221
Posts: 13848
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,
Rob

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

 

Logged

Rob Tillaart

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

Pages: [1]   Go Up
Jump to: