Is it possible to write data to different files using Arduino?

Hi,

For our project, we want to log every time we press a button in a .csv file.

Format
logid, buttonid, datetime

Example
1,2,12-12-2000 10:10:10
2,2,12-12-2000 10:10:11
3,1,12-12-2000 10:10:12
etc.

Secondly, we want to save the current logid in a .txt file every time a button is pressed. This .txt would only contain a single long/int, which we read when we start up the Arduino. We do not want to parse a potentially big .csv file.

We own a SD shield +SD card, Arduino One and a RTC time chip. The datetime is working and formatted nicely. But we have problems writing to two different files. If we write to one of both files, we get the right result. When we want to write to both, the file written second in the code provides errors. We use file.close() correctly as well as File f = SD.open (filename, FILE_WRITE/FILE_READ) when we either read or write.

Is our solution to achieve our goal smart? (Writing the current logid every time a button is pressed to a .txt on the SD card and reading when we start up the Arduino?)
Is our solution achievable with Arduino? (First reading the .txt at the startup of the Arduino; adding it to our long id variable in our code, rewriting the .txt everytime a button is pressed with the correct current logid, as well as putting our formatted line in the .csv file)?

Thx in advance,

Vib

ViBoNacCi:
Is our solution to achieve our goal smart? (Writing the current logid every time a button is pressed to a .txt on the SD card and reading when we start up the Arduino?)
Is our solution achievable with Arduino? (First reading the .txt at the startup of the Arduino; adding it to our long id variable in our code, rewriting the .txt everytime a button is pressed with the correct current logid, as well as putting our formatted line in the .csv file)?

The answer to your title question is yes.

If I understand your project correctly, what you want is harder than it first appears, but it may also be unwarranted.

Since you already have the card in place, using to store volatile data for future use is a pretty obvious choice. The read is done in the setup, open txt - read - close txt and the writes are done in the loop. This does not explain how the text file data is written, the old data deleted, or any surety that that will actually happen.

It appears that you are only interested in the button data in the CSV file, and are concerned about what happens when the power goes off. The answer to that is nothing. You should not need two files, you just resume logging to the CSV file when the power goes back on.

We do not want to parse a potentially big .csv file.

If you made log id a constant width field, then all the records could be the same length, and finding any given record in the file would be trivial.

Thanks for the responses.

We resolved the problem of not being able to write to two different files. It was low SRAM problems, so we cleaned up the code. Secondly, we found out that Arduino has a 512byte EEPROM, to which we can easily write a long. The contents of the EEPROM memory stay intact after removing power from the Arduino. That seemed like the best solution.

I'm pretty sure a '328P based Arduino has 1Kbyte of EEPROM.
512 words.