I'd like to ask how to store sensor data on the sd card

Hello

I use Arduino Mega, mpu6050, and sd card.
I'm going to store the mpu6050 data on the sd card, but it has to have a speed of 500 Hz or higher.
At first, I saved it as .txt, but it's very slow. And I heard that it's good to store data as a binary.
So I referred to "Low Latency Logger MPU6050", an example of SdFat.h.
If I save the data as a binary, it's much faster, but I can't open this file directly on my PC. (It takes too long to convert to .csv according to the example, so I'd like to convert the binary file into a text file myself.)

May I know how to convert this binary file into text? I've used several 'binary to text' online, but all the characters are broken.
Or is it possible to store data as fast as binary while using text files rather than binary files? (Previously, mpu6050 raw data was stored as text, but the storage speed was much lower than 500 Hz.

Thank you.

mpuraw05.bin.zip (35.0 KB)

Binary storage is faster because ASCII base 10 data representation uses up more bytes. For example a 16 bit reading with value of 50000 takes up 5 bytes instead of 2, and then you need separators as you don’t have fixed width data. So you easily triple or quadruple the size of the file when using a human readable format .

What you could do when acquisition is done, before you extract the SD card to read on your PC, would be to have a small piece of code reading the binary file and generating the text CSV file.

Alternatively you could write a small program on your computer that would read the binary and generate the CSV. It’s not difficult when you know the exact binary format (including byte order (endianness) and byte size representation like how many bytes for an int, a double etc…)

I've been doing similar with a Mega 2560 and a Seeed sd breakout and an Adafruit LSM6DS33 sensor. I can read and store 3-axis gyro and accelerometer at 250Hz. Tired 400hz but SD-Fat Datalogger indicated that the Mega was too slow for this speed. YMMV

I store the data in binary: a 32 byte record. My data only requires 24 bytes but the data logger requires data records of length 2/4/8/16/32... After I complete the test, I use the builtin binary2csv feature to convert the data. Most of my test runs are around 30 seconds to 1 minute so I'm looking at 8k to 15k records. It can take the Mega a minute or two to convert to CSV. PITA! but it works and your time investment is low,

FYI, there is a Teensy data logger which will log at a higher data rate for longer period but I haven't tried it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.