I am storing the data of mpu6050 in the sd card.
I want to store at least 500 pieces of data per second on the sd card. Outputting raw data from sensors comes out quickly and well, but using sd cards, the data output rate is too slow, about 50 per second.
Is there a way to speed up the data storage of the sd card?
This is my code.
#include <basicMPU6050.h>
#include <SPI.h>
#include <SD.h>
#define LED_PIN 13
// Create instance
basicMPU6050<> imu;
File myFile;
bool blinkState = false;
void setup() {
// Start console
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
while (!Serial);
Serial.println("wait...");
delay(2000);
// Set registers - Always required
Serial.println("Initializing I2C devices...");
imu.setup();
// sd card init
if (!SD.begin(4)) {
Serial.println("SD Card initialization failed!");
while (1);
}
Serial.println("SD Card initialization done.");
}
int count;
int isTimerStart = 0;
void loop() {
// 시간 (00:00:00.xxx)
unsigned long millisTime = millis();
myFile = SD.open("asdf.txt", FILE_WRITE);
if (myFile) {
myFile.print(millisTime);
myFile.print(" ");
myFile.print( imu.rawAx() );
myFile.print(" ");
myFile.print( imu.rawAy() );
myFile.print(" ");
myFile.print( imu.rawAz() );
myFile.print(" ");
myFile.print( imu.rawGx() );
myFile.print(" ");
myFile.print( imu.rawGy() );
myFile.print(" ");
myFile.println( imu.rawGz() );
Serial.println(imu.rawAx());
count++;
Serial.print("Count: ");
Serial.println(count);
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
myFile.close();
Serial.println("Done");
}
}