Go Down

Topic: SDfat.h Writing Speed (Read 28 times) previous topic - next topic

funkbert

May 29, 2015, 02:18 pm Last Edit: May 29, 2015, 02:18 pm by funkbert
Hi guys,

i have already used the search but i am still strugeling with a problem of mine, so i´m hoping for some good hints.
I am using an Mega 2560 r3 to access three sensors via analogRead and logging the values via Adafruit SD shield on a normal Sandisk 1gb SD card (Fat16). I have to make a lot of mesuarements in a very short time (about 50 in 20 ms or as much as possible) and thus i changed from the SD.h to the SDfat.h library. I got it working after some minor problems but only to notice that there isn´t an inprovement in writing speed at all. Sd.h provided me with about one mesuarement every 1.1 ms and it hasn´t become any faster.
Even changing SPI_HALF_SPEED to FULL didn´t make any difference, so i am guessing that i did make a mistake while setting the whole thing up.

I would be really glad if someone would provide me with some help :)


#include <SPI.h>
#include <SdFat.h>

SdFat sd;
SdFile myFile;

const int chipSelect = 10;


void setup() {
  Serial.begin(9600);
  while (!Serial){}
  Serial.println ("Serial communication available");
 
  delay (1000);
 
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)){
    sd.initErrorHalt();
    }
   
  if (!myFile.open("test2.txt", O_RDWR | O_CREAT | O_AT_END)){
    sd.errorHalt ("Failed to open file");
    }
   
  Serial.println("File initialized");
  Serial.println("Ready for logging");
 
  }
 
void loop(){
   
   for (int i = 0 ; i < 10 ; i++){
   myFile.print(micros());
   myFile.print("  ,   ");
   myFile.print(analogRead(A0));
   myFile.print("  ,   ");
   myFile.print(analogRead(A8));
   myFile.print("  ,   ");
   myFile.println(analogRead(A15));
   }
   myFile.flush();

 
 
  }


fat16lib

Your problem is the time required to format data and the slow speed of print.

You need to log binary data and write full 512 bytes blocks.

Look at these SdFat examples.

AnalogBinLogger - log analog pins at the fastest possible rate.

LowLatencyLogger - log data records from sensors at up to 500 Hz.

First try the unmodified examples.  You will need to modify these examples for your application.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy