API Reference
adafruit_lis331
A library for the ST LIS331 family of high-g 3-axis accelerometers
Author(s): Bryan Siepert
Implementation Notes
Hardware:
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
Adafruit’s Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
- class adafruit_lis331.LIS331(i2c_bus: I2C, address: int = 24)
Base class for the LIS331 family of 3-axis accelerometers. Cannot be instantiated directly
- param ~busio.I2C i2c_bus:
The I2C bus the LIS331 is connected to.
- param address:
The I2C device address. Defaults to
0x18
- property hpf_reference: int
The reference value to offset measurements when using the High-pass filter. To use,
use_referencemust be set to true when enabling the high-pass filter. The value is a signed 8-bit number from -128 to 127. The value of each increment of 1 depends on the currently set measurement range and is approximate:Range
Incremental value (LSB value)
LIS331HHRange.RANGE_6GorH3LIS331Range.RANGE_100G~16mg
LIS331HHRange.RANGE_12GorH3LIS331Range.RANGE_200G~31mg
LIS331HHRange.RANGE_24GorH3LIS331Range.RANGE_400G~63mg
- zero_hpf() None
When the high-pass filter is enabled with
use_reference=False, callingzero_hpf()will set all measurements to zero immediately, avoiding the normal settling time seen when using the high-pass filter without ahpf_reference()
- enable_hpf(enabled: bool = True, cutoff: int = 0, use_reference: bool = False) None
Enable or disable the high-pass filter.
- Parameters:
enabled – Enable or disable the filter. Default is
Trueto enablecutoff (RateDivisor) – A
RateDivisorto set the high-pass cutoff frequency. Default isRateDivisor.ODR_DIV_50. SeeRateDivisorfor more informationuse_reference – Determines if the filtered measurements are offset by a reference value. Default is false.
See section 4 of the LIS331DLH application note for more information LIS331DLH application note for more information
- property data_rate: float
Select the rate at which the accelerometer takes measurements. Must be a
Rate
- property mode: int
The
Modepower mode that the sensor is set to, as determined by the currentdata_rate. To set the mode, usedata_rateand the appropriateRate
- class adafruit_lis331.LIS331HH(i2c_bus: I2C, address: int = 24)
Driver for the LIS331HH 3-axis high-g accelerometer.
- Parameters:
i2c_bus (I2C) – The I2C bus the LIS331 is connected to.
address – The I2C device address. Defaults to
0x18
Quickstart: Importing and using the device
Here is an example of using the
LIS331class. First you will need to import the libraries to use the sensorimport board import adafruit_lis331
Once this is done you can define your
board.I2Cobject and define your sensor objecti2c = board.I2C() # uses board.SCL and board.SDA lis = adafruit_lis331.LIS331HH(i2c)
Now you have access to the
accelerationattributeacceleration = lis.acceleration
- class adafruit_lis331.H3LIS331(i2c_bus: I2C, address: int = 24)
Driver for the H3LIS331 3-axis high-g accelerometer.
- Parameters:
i2c_bus (I2C) – The I2C bus the LIS331 is connected to.
address – The I2C slave address of the sensor. Defaults to
0x18
Quickstart: Importing and using the device
Here is an example of using the
LIS331class. First you will need to import the libraries to use the sensorimport board import adafruit_lis331
Once this is done you can define your
board.I2Cobject and define your sensor objecti2c = board.I2C() # uses board.SCL and board.SDA lis = adafruit_lis331.H3LIS331(i2c)
Now you have access to the
accelerationattributeacceleration = lis.acceleration