Faster data logging with SdFat and a RTOS

SD cards can have occasional write delays of up to 200 milliseconds. This due to erasing large flash blocks and remapping bad spots.

These delays can cause data points to be lost at rates over a few points per second.

A real-time kernel can be used to solve this problem. Data is captured in a high priority task and queued for a lower priority task to write to an SD card.

I have posted several sketches for faster data logging using special tricks but a real-time kernel is a more general way to solve this type problem.

I have ported two real-time kernels to the Arduino, FreeRTOS and ChibiOS/RT, and developed fast data logging sketches that use these kernels. The kernels are easy to use Arduino libraries so no modification of the core Arduino files or IDE is required.

The examples are here Google Code Archive - Long-term storage for Google Code Project Hosting. in files ChibiOS20111027.zip and FreeRTOS20111031.zip.

On a 328 Arduino it is possible to log up to 976 points per second (one point every 1024 microseconds) to an CSV file where each point is the value from two analog pins.

On a Mega, with more buffering, values from four analog pins can be logged at the above rate to a CSV file.

More about the ChibiOS/RT port is here http://arduino.cc/forum/index.php/topic,76932.0.html.

The FreeRTOS port is described here http://arduino.cc/forum/index.php/topic,77362.0.html.

I've used duinos and it seems to work very well. I just need to port it to 2560 now :stuck_out_tongue:

Both libraries and the examples should work on the 2560.

I have a program that calculates RPM, speed, fuel from different sensors (2 digital 2 analog) and outputs the info through serial3 (arduino mega2560) onto an LCD screen. I'm trying to implement data acquisition too. What would be the easiest way to record some buffered CSV to a file?
Right now i'm thinking of something like

obufstream bout(buf, sizeof(buf));
bout<<i<<','<<j<<','<<k<<','<<endl;
logfile<<buf<<flush;

but this doesn't do any buffering except creating a string for all the values together. Any tips?