adafruit_lsm303_accel
¶
CircuitPython driver for the accelerometer in LSM303 sensors.
- Author(s): Dave Astels, Bryan Siepert
Implementation Notes¶
Hardware:
- Adafruit Triple-axis Accelerometer+Magnetometer (Compass) Board - LSM303 (Product ID: 1120)
- Adafruit FLORA Accelerometer/Compass Sensor - LSM303 - v1.0 (Product ID: 1247)
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
-
class
adafruit_lsm303_accel.
LSM303_Accel
(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 sensorimport board import adafruit_lsm303_accel
Once this is done you can define your
board.I2C
object and define your sensor objecti2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_lsm303_accel.LSM303_Accel(i2c)
Now you have access to the
acceleration
attributeacc_x, acc_y, acc_z = sensor.acceleration
-
acceleration
¶ The measured accelerometer sensor values. A 3-tuple of X, Y, Z axis values in m/s^2 squared that are signed floats.
-
mode
¶ 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
-
range
¶ 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, threshold, *, time_limit=10, time_latency=20, time_window=255, tap_cfg=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
-