adafruit_lis3dh
¶
CircuitPython driver for the LIS3DH accelerometer.
See examples in the examples directory.
- Author(s): Tony DiCola
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_lis3dh.
AccelerationTuple
¶ alias of
adafruit_lis3dh.acceleration
-
class
adafruit_lis3dh.
LIS3DH
(int1=None, int2=None)[source]¶ Driver base for the LIS3DH accelerometer.
:param digitalio.DigitalInOut int1. pin on the sensor that would act as an in interrupt :param digitalio.DigitalInOut int2. pin on the sensor that would act as an in interrupt
-
acceleration
¶ The x, y, z acceleration values returned in a 3-tuple and are in \(m / s ^ 2\)
-
data_rate
¶ The data rate of the accelerometer.
Could have the following values:
- DATA_RATE_400_HZ
- DATA_RATE_200_HZ
- DATA_RATE_100_HZ
- DATA_RATE_50_HZ
- DATA_RATE_25_HZ
- DATA_RATE_10_HZ
- DATA_RATE_1_HZ
- DATA_RATE_POWERDOWN
- DATA_RATE_LOWPOWER_1K6HZ
- DATA_RATE_LOWPOWER_5KHZ.
-
range
¶ The range of the accelerometer.
Could have the following values:
- RANGE_2_G
- RANGE_4_G
- RANGE_8_G
- RANGE_16_G.
-
read_adc_mV
(adc)[source]¶ Read the specified analog to digital converter value in millivolts. ADC must be a value 1, 2, or 3. NOTE the ADC can only measure voltages in the range of ~900-1200mV!
-
read_adc_raw
(adc)[source]¶ Retrieve the raw analog to digital converter value. ADC must be a value 1, 2, or 3.
-
set_tap
(tap, threshold, *, time_limit=10, time_latency=20, time_window=255, click_cfg=None)[source]¶ The tap detection parameters.
Note
Tap related registers are called
CLICK_
in the datasheet.Parameters: - tap (int) – 0 to disable tap detection, 1 to detect only single taps, and 2 to detect only double taps.
- threshold (int) – A threshold for the tap detection. The higher the value the less sensitive the detection. This changes based on the accelerometer range. Good values are 5-10 for 16G, 10-20 for 8G, 20-40 for 4G, and 40-80 for 2G.
- time_limit (int) – TIME_LIMIT register value. Defaults to
10
- time_latency (int) – TIME_LATENCY register value. Defaults to
20
- time_window (int) – TIME_WINDOW register value. Defaults to
255
- click_cfg (int) – CLICK_CFG register value.
-
shake
(shake_threshold=30, avg_count=10, total_delay=0.1)[source]¶ Detect when the accelerometer is shaken. Optional parameters:
Parameters: - shake_threshold (int) – Increase or decrease to change shake sensitivity.
This requires a minimum value of 10.
10 is the total acceleration if the board is not
moving, therefore anything less than
10 will erroneously report a constant shake detected.
Defaults to
30
- avg_count (int) – The number of readings taken and used for the average
acceleration. Default to
10
- total_delay (float) – The total time in seconds it takes to obtain avg_count
readings from acceleration. Defaults to
0.1
- shake_threshold (int) – Increase or decrease to change shake sensitivity.
This requires a minimum value of 10.
10 is the total acceleration if the board is not
moving, therefore anything less than
10 will erroneously report a constant shake detected.
Defaults to
-
tapped
¶ True if a tap was detected recently. Whether its a single tap or double tap is determined by the tap param on
set_tap
.tapped
may be True over multiple reads even if only a single tap or single double tap occurred if the interrupt (int) pin is not specified.The following example uses
board.I2C
and specifies the interrupt pin:import adafruit_lis3dh import digitalio import board i2c = board.I2C() # uses board.SCL and board.SDA int1 = digitalio.DigitalInOut(board.D11) # pin connected to interrupt lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1) lis3dh.range = adafruit_lis3dh.RANGE_8_G
-
-
class
adafruit_lis3dh.
LIS3DH_I2C
(i2c, *, address=24, int1=None, int2=None)[source]¶ Driver for the LIS3DH accelerometer connected over I2C.
Parameters: - i2c (I2C) – The I2C bus the LIS3DH is connected to.
- address – The I2C device address. Defaults to
0x18
Quickstart: Importing and using the device
Here is an example of using the
LIS3DH_I2C
class. First you will need to import the libraries to use the sensorimport board import adafruit_lis3dh
Once this is done you can define your
board.I2C
object and define your sensor objecti2c = board.I2C() # uses board.SCL and board.SDA lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c)
Now you have access to the
acceleration
attributeacc_x, acc_y, acc_z = lis3dh.acceleration
-
class
adafruit_lis3dh.
LIS3DH_SPI
(spi, cs, *, baudrate=100000, int1=None, int2=None)[source]¶ Driver for the LIS3DH accelerometer connected over SPI.
Parameters: - i2c (I2C) – The I2C bus the LIS3DH is connected to.
- address – The I2C device address. Defaults to
0x18
Quickstart: Importing and using the device
Here is an example of using the
LIS3DH_SPI
class. First you will need to import the libraries to use the sensorimport board import adafruit_lis3dh
Once this is done you can define your
board.SPI
object and define your sensor objecti2c = board.SPI() lis3dh = adafruit_lis3dh.LIS3DH_SPI(spi)
Now you have access to the
acceleration
attributeacc_x, acc_y, acc_z = lis3dh.acceleration