I’m working on a project where I would need to store data very faster. My goal would be to store 7 float variables, 1 long and 1 boolean (which would equal to 33 bits if I understand it right). I’m currently using an Arduino Pro Mini (ATMEGA328 328p 5V 16MHz), a “standard” microSD card adapter module (I got from Banggood) and a Samsung 32Gb micro SD card. The microSD card adapter is connected to the Arduino using SPI.
I use the following code to store the data on the SD card and to calculate how it take to store the data (using the standard Arduino SD library):
void SD_Card() {
current_Time = micros();
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
myFile.print(current_Time); myFile.print(",");
myFile.print(raw_ax); myFile.print(",");
myFile.print(raw_ay); myFile.print(",");
myFile.print(raw_az); myFile.print(",");
myFile.print(raw_gx); myFile.print(",");
myFile.print(raw_gy); myFile.print(",");
myFile.print(raw_gz); myFile.print(",");
myFile.print(altitude);myFile.print(",");
myFile.println(max_Altitude);
myFile.close(); // close the file
}
// if the file didn't open, print an error:
else {
Serial.println("error opening test.txt");
}
long interval = micros() - current_Time;
Serial.println(interval);
}
Here you can see how long it takes to store the data in microseconds (about 17’000 to 20000 microseconds):
17852
20328
16380
17760
20456
20404
20444
16300
17704
20288
16420
17684
20380
16312
17748
20256
16224
I read that using a different library, in this case the “SdFat-master”, could give better result, which it did as it took less time to store the data (about 8’200 to 15’000 microseconds):
12336
8200
9640
12496
8156
9724
12376
8356
9748
12192
8248
15444
8300
9796
12256
8300
I would need to store the date in maximum 5000 microseconds (5 milliseconds), ideally even faster, is there a way to speed it up ? Is there something I could change in the setup section to increase the speed ? Is there a way to store the data differently, for example by merging the data in one single string, so I would need to print only one time instead of 9 times?
An other option would be to store the data in a different way (using eeeprom, flash, or anything else) and then to transfer the data to the SD card ? If so what type of memory should I use ?
Is the Arduino the issue ? Could I store the data faster I would use a faster micro-controller like the Teensy 3.5 ?
Any help appreciated. Thanks.