adafruit_lsm303_accel

CircuitPython driver for the accelerometer in LSM303 sensors.

  • Author(s): Dave Astels, Bryan Siepert

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_lsm303_accel.LSM303_Accel(i2c: I2C)[source]

Driver for the LSM303’s accelerometer.

Parameters:

i2c (I2C) – The I2C bus the device is connected to.

Quickstart: Importing and using the device

Here is an example of using the LSM303_Accel class. First you will need to import the libraries to use the sensor

import board
import adafruit_lsm303_accel

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA
sensor = adafruit_lsm303_accel.LSM303_Accel(i2c)

Now you have access to the acceleration attribute

acc_x, acc_y, acc_z = sensor.acceleration
property acceleration: Tuple[float, float, float]

The measured accelerometer sensor values. A 3-tuple of X, Y, Z axis values in m/s^2 squared that are signed floats.

property data_rate: int

Select the rate at which the sensor takes measurements. Must be a Rate

property mode: int

Sets the power mode of the sensor. The mode must be a Mode. Note that the mode and range will both affect the accuracy of the sensor

property range: int

Adjusts the range of values that the sensor can measure, from +- 2G to +-16G Note that larger ranges will be less accurate. Must be a Range

set_tap(tap: Literal[0, 1, 2], threshold: int, *, time_limit: int = 10, time_latency: int = 20, time_window: int = 255, tap_cfg: int | None = None) None[source]

The tap detection parameters.

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

  • tap_cfg (int) – CLICK_CFG register value. Defaults to None

property tapped: bool

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.

class adafruit_lsm303_accel.Mode[source]

Options for mode

class adafruit_lsm303_accel.Range[source]

Options for range

class adafruit_lsm303_accel.Rate[source]

Options for data_rate