sdcard data logging wearing down the sdcard

hello people,

probably a question that comes around a lot, but i have searched and not found the right answer.

i'm logging every ten seconds a temperature. along with the temp i also write time and date.

after 2360 logs, i end up with 90kb of data.

i wonder: 1)does writing that many times the file hurt the sdcard ? i use this code; data is a string with all data in it aquired via the sprintf command.

File logFile = SD.open("LOG.txt if (logFile) { logFile.println(data) logFile.close(); Serial.println(data);

2)if it is not good for the sd card; i would like to keep 2kb at the ram, and write very 4 minutes or so. is that a better option ?

could somebody point me in the direction how to safe to the ram, and then pump it to the sd card ?

thanks

Yes, the SD card will wear out. No, with writing every 10 seconds, you don't have to worry.

There is so much to say about this, but it depends on the SD card. Today the MLC (Multi Level Cell) could have a shorter lifespan, but then again that depends on the quality. The SD card is not just a memory chip but has also a controller inside. That controller uses wear leveling. It might even replace bad memory with some spare memory. The rule of thumb was that a SD card could be written 10000 times, but with a intelligent controller inside, it is impossible to say how long it will last. You may find some tests online.

Yes, the SD card will wear out.

You will never wear out an SD card with an Arduino logging data using print.

Modern SD cards have excellent wear leveling. A virtual to physical mapping is maintained in the card. Unchanging data is even moved so all flash is equally used. MLC is good for 1,000 - 10,000 write cycles.

You can write at least 1,000 times the size of the SD card. So with a 4 GB card, you can log 4 GB of data per day for three years. You can’t write data that fast with an Uno using print.

thanks people for this usefull information.

i guess i could stop worrying

wel for the sake of develpment (of my own skills). i would like te store 2kb in the ram, and every time this happens (probably you can count the bits... but i would store someting like 50 measurements and then write them to SD card). how on earth is that done ? i'm not asking a any code, just some tips on what to do. do i need the append every measurment to a string that grows... and then write it on the sd card ?

thanks

The String object allocates memory, that could easily cause memory fragmentation. http://arduino.cc/en/Reference/StringObject

You could create a simple buffer of 'char' or 'byte' and write that to a file when it is filled: char buffer[128]; A buffer for reading or writing a file could be used to speed up the SD usage. I have for example a website on the SD card, and I use a buffer of 128 bytes, so I read 128 bytes from a file and transfer that to the Ethernet shield.

For you, I suggest not to use a buffer. Focus on the reliability of your project. When everything is working you can try to add a buffer and see what it does. I use a define called "ENABLE_..." to test new code. I use comments to disable the define and use the old code: // #define ENABLE_...

#define ENABLE_BUFFER
...
#ifdef ENABLE_BUFFER
  // here the new code to test
#else
  // here the old code that was working okay.
#endif

fillemon: i would like te store 2kb in the ram, and every time this happens (probably you can count the bits... but i would store someting like 50 measurements and then write them to SD card). how on earth is that done ? i'm not asking a any code, just some tips on what to do. do i need the append every measurment to a string that grows... and then write it on the sd card ?

You don't need to do your own buffering like this because the SD library reportedly does it for you internally. If you do want to ensure the data is written to the card after every 50 measurements, you can call file.flush() at that point. If you don't call 'flush' then the file does data may not be stored to the card until you call file.close(), depending on how much data you generate and how big the SD class's internal buffers are.

On the other hand, if you want to ensure that no data is written to the card until you have the whole 50 samples, then you would need to do your own buffering. There's a lot of different ways to implement this kind of buffering. One would be to build the string internally, like you said. Another would be to keep a list of sample data (as integers, say) and then write the samples with file.println(...) when you have 50 of them collected.