SD logging rate help

My project aims to develop a mobile IMU which logs data to an SD card at 100-200Hz. I am currently using:

  • Adafruit FLORA 9 DOF sensor as the IMU (only communicates with I2C)
  • Adafruit trinket pro + adafruit SD breakout for logging

The IMU and logger work fine (most of the time) but I am not getting the rate that I require. Currently I am only getting 50Hz max, and this is highly variable.

I have adapted SdFat's logging library which was initially for analog data but I am using it with the I2C sensor. I have gone through an characterized the code to try and find out why I seem to be limited to loop times of 20ms minimum (see commented code below). Getting the sensor event takes ~5ms, writing the data to the card takes ~5ms.

Other than further optimizing the SD libraries and IMU code is there anything I could do to increase this rate or may this be a fundamental limit of the SPI interface with the SD card and I2C with the sensor? Does this current rate that I am achieving seem to be near the limits of what may be possible for this hardware or are there other ways in which I can optimize my code?

Any suggestions or help much appreciated!

dataLogger_SdFat_27oct_27novMOD.ino (9.06 KB)

You may get more help if you post your code as explained in the how to use the forum stickies. Many people don't have the IDE on their devices. Many people won't download code for various reasons. Is the I2C speed set to 400KHz?

Most SD cards are optimised for quickly writing large blocks of data (such as an image from a digital camera) rather than a fast transaction speed. The "Class" rating of a card doesn't tell you much about the maximum transaction speed.

This problem affects single board computers such as the Beaglebone (when booting from the SD card) and Raspberry Pi, as they both do lots of small writes.

Do a google search for "sd card speed beaglebone" or "sd card speed raspberry pi".

Cards such as the "Samsung Evo 32GB" are said to be above average in terms of small file write speed.

Buy from a local reputable supplier as fake cards are major problem when buying directly from suppliers in China.