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 ESP8622 and M0-based boards: https://github.com/adafruit/circuitpython/releases
- 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.
-
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. Can be 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, or DATA_RATE_LOWPOWER_5KHZ.
-
range
¶ The range of the accelerometer. Can be RANGE_2_G, RANGE_4_G, RANGE_8_G, or 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 (default 10).
- time_latency (int) – TIME_LATENCY register value (default 20).
- time_window (int) – TIME_WINDOW register value (default 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 – 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. (Default 30)
- avg_count – The number of readings taken and used for the average acceleration. (Default 10)
- total_delay – The total time in seconds it takes to obtain avg_count readings from acceleration. (Default 0.1)
-
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
i2c
and specifies the interrupt pin:import adafruit_lis3dh import digitalio i2c = busio.I2C(board.SCL, 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
-