sparkfun / SparkFun_LIS2DH12_Arduino_Library

Library for I2C communication with ST LIS2DH12 low power accelerometer
Other
15 stars 10 forks source link

Not possible to read acceleration data with a frequency of approx. 5 kHz. #2

Closed mraugit closed 4 years ago

mraugit commented 4 years ago

It is not possible to read acceleration data with a frequency of approx. 5 kHz.

Workbench: Development board: Sparkfun edge Library Version 1.0.0 (Version from Arduino IDE) Powered by USB?

Steps to reproduce: I use the Example: Example1_BasicReadings with the following modifications:

  1. Change Wire to Wire1
  2. Disable temperature
  3. Disable tab detection
  4. Set data rate to LIS2DH12_ODR_5kHz376_LP_1kHz344_NM_HP
  5. Print last read value only every 1000 captured values.

Expected behavior

I expect to get approx. five outputs every second

Actual behavior

The max. frequence is about 500Hz

nseidle commented 4 years ago

Neat. It's probably limited by I2C comm at 1MHz. I just tried it and got up to about 900Hz:

image

The serial buffer is getting corrupt but I can get to ~911Hz. I added example 8 to the lib so you can see what I did:

Oh, and we've got a 1ms delay inside SPARKFUN_LIS2DH12::waitForNewData(). Removing the delay doesn't seem to help. We're polling where if you're really trying to hit 5k, you'd probably need:

mraugit commented 4 years ago

Thank you for checking. I definitely need the 5 kHz sampling rate. However, I fear that my knowledge is not sufficient to extend the library with SPI and interrupt communication.

nseidle commented 4 years ago

We don't plan to support SPI anytime soon but we welcome a PR. It looks like this accel and library are going to be limited to ~1kHz for now.