Hi all,
I'm currently working on a university project.
We want to log data from several sensors (connected by I2C Bus) to a micro SD card using SPI and the sdfat-lib on an arduino Uno (SD Card Reader Catalex from ebay).
In this context I would like to kind of dig out this post:
http://forum.arduino.cc/index.php?topic=49649.0
We used the procedure of "controlling the flush call" as described in the post above to get a high sample rate (50/s would be great, but is not mandatory).
We also used a class 10 card and benchmarked it with the "bench-code" (write speed: 249kb/s, max latency 24451µs, avg latency 2049µs)
Thereby we managed to increase our sample rate to about 20-25/s (already quite good), thanks for that first of all ;)!
We will store about 20 values in a cvs file as float with 5 digits after decimal point (e.g.: 6216.00000;1014.87750;23.04688; .... ). Currently we call a flush every 1000 measurement rows and it works quite good (see code fragment for details)
We use a pushbutton to start/stop the measurement and open/close the sd file on the event. We will log the data for about 5min.
#define DATA_LENGTH 20
#define FLUSH_RATE 1000
//[...]
file.open(FILENAME, O_CREAT | O_WRITE | O_APPEND) //Open the sd file when button is pushed
//[...]
// Write Sensor Values
for (uint8_t i = 0; i < DATA_LENGTH; i++)
{
file.print(DatatoSD[i],5); // Write the data array to the SD Card Controller(?)
file.write(';'); //separator after each value
}
file.println(); // one row of the data array is ready, so make a new line
if(count%FLUSH_RATE==0) //count just counts the measurement rows logged
{
file.flush();
}
We don't really care about data loss in case of e.g. power failure because we can simply perform the measurement again. Hence flushing only every 1000 measurement rows would not be an issue for us.
My questions, since I would like to explain it correctly in my thesis:
1)
It was mentioned that the sdfat-lib has a internal buffer of 512bytes. As we obviously now put more than 512bytes "somewhere" with the print- (and write) method:
Where does the data go? Is it already going to the SD card? What is the max. amout of data we can put "there" before we have to call the flush again not risking an "overwrite" or something like that? Is there official documentation which explains how SD card work on hardware level?
- In order to possibly increase the sample rate to about 50/s? Is that possible for a beginner without using very sophisticated coding?
Thanks a lot upfront, sorry for the long post and all the best
Tim