adafruit / Adafruit_LIS3DH

Arduino Library for Adafruit LIS3DH breakout board
Other
72 stars 57 forks source link

Library prevents usage of 1.25kHz Normal Power Mode #21

Closed erichiggins closed 3 months ago

erichiggins commented 4 years ago

According to Table 26 in the LIS3DH datasheet, there is a 1.25 kHz sample rate available using Normal Power mode. The settings for ODR0 - ODR3 are identical to those for 5kHz low-power mode, which is an optional sample rate provided by this library. However, low-power mode sacrifices resolution according to section 3.2.1 of the datasheet.

LIS3DH provides two different operating modes respectively reported as normal mode and low power mode. While normal mode guarantees high resolution, low power mode reduces further the current consumption.

I was able to work around this by making writeRegister8 a public method so the necessary settings could be changed. Here's my code to set configure the sensor:

  lis.setRange(LIS3DH_RANGE_8_G);
  lis.setDataRate(LIS3DH_DATARATE_LOWPOWER_5KHZ);
  // Disable LPen bit (for Normal power mode)
  lis.writeRegister8(LIS3DH_REG_CTRL1, 0b10010111);
  // Enable HR bit (for Normal power mode)
  lis.writeRegister8(LIS3DH_REG_CTRL4, 0b10100000);

Since this library does not provide any other way to access the low-power or high-res settings, this was the simplest approach.

tyeth commented 3 months ago

There is now a PR to add a setPerformanceMode call, allowing low power/normal/high resolution. See #50