I'm trying to build a data logger with a sample rate of ~700-1000Hz.
My hardware is as follows:
Arduino UNO
5V to 3.3V logic level converter
Standard size SD card module
SanDisk SDHC 16GB class 4
LCD screen + assorted buttons, switches, and LEDs
The data logging portion of my code is below:
void LogData() {
int sensorValue = analogRead(A0);
RecordSwitch = digitalRead(7);
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
// SD.open will take either a string or a char* as its input. In this case, FileName is a string.
File dataFile = SD.open(FileName, O_CREAT | O_WRITE);
// if the file is available, write to it:
// if file is not available, something has gone terribly wrong. Display an error to warn them!
if (dataFile) {
if ( q == 0 ) {
digitalWrite(pin, HIGH); //turns on the LED
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Recording..."); //prints "Recording" onto the lcd
q = 1;
}
elapsedtime = millis() - Starttime; //Starts tracking the elapsed time
dataFile.print(elapsedtime); //prints elapsed time in one column
dataFile.print(", "); //seperates data by column
dataFile.print(sensorValue); //prints sensor data in the second column
dataFile.println();
dataFile.close(); //closes the file
}
else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Error Opening");
lcd.setCursor(0, 1);
lcd.print("File");
}
}
The LogData function is called in a while loop in the main part of the code. While the record switch is high, log data. I could include my entire code. This is just what I thought was relevant.
When I run this code, I am getting a sample rate of around 80Hz. I want to identify my limiting factor.
The SD card should have a minimum write speed of 4mb/s. That seems like it should be more than enough.
I'm using the SD.h library, and I understand it is notoriously slow, but 80Hz seems VERY slow to me. Would switching to the sdfat library increase the speed that much?
Is the processor on the UNO not fast enough to crank through the SD formatting? Would switching to a DUE (or something else) be the best option?
Thanks for taking the time to read this. I appreciate any feedback!