Micropython LISD3H library

lis3dh

LIS3DH MicroPython Driver

  • Author(s): Jose D. Montoya

class micropython_lis3dh.lis3dh.LIS3DH(i2c, address=0x18)[source]

Main class for the Sensor

Parameters:
i2c : I2C

The I2C bus the LIS3DH is connected to.

address : int

The I2C device address. Defaults to 0x18

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

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

from machine import Pin, I2C
from micropython_lis3dh import lis3dh

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

i2c = I2C(sda=Pin(8), scl=Pin(9))  # Correct I2C pins for UM FeatherS2
lis = lis3dh.LIS3DH(i2c)

Now you have access to the acceleration attribute

acc_x, acc_y, acc_z = lis3dh.acceleration
property acceleration

The x, y, z acceleration values returned in a 3-tuple and are in \(m/s^2\)

property axes_enabled

The data rate of the accelerometer. you could selected different axes to be on. Take a look at the table to select the Aces that you are interested in.

Mode

Value

lis3dh.AXES_X

0b001

lis3dh.AXES_Y

0b010

lis3dh.AXES_X_Y

0b011

lis3dh.AXES_Z

0b100

lis3dh.AXES_Z_X

0b101

lis3dh.AXES_Z_Y

0b110

lis3dh.AXES_Z_Y_X

0b111

property data_range

The range of the accelerometer. The LIS3DH has dynamically user selectable full scales of ±2g/±4g/±8g/±16g and it is capable of measuring accelerations with output data rates from 1 Hz to 5 kHz.

Mode

Value

lis3dh.DATARANGE_2

0b00

lis3dh.DATARANGE_4

0b01

lis3dh.DATARANGE_8

0b10

lis3dh.DATARANGE_16

0b11

property data_rate

The data rate of the accelerometer ODR <3:0> is used to set power mode and ODR selection. In the following table are reported all frequency resulting in combination of ODR<3:0>

Mode

Value

lis3dh.DATARATE_1

0b0001

lis3dh.DATARATE_10

0b0010

lis3dh.DATARATE_25

0b0011

lis3dh.DATARATE_50

0b0100

lis3dh.DATARATE_100

0b0101

lis3dh.DATARATE_200

0b0110

lis3dh.DATARATE_400

0b0111

lis3dh.DATARATE_1344

0b1001

lis3dh.DATARATE_POWERDOWN

0b0000

lis3dh.DATARATE_LOWPOWER_1600

0b1000

lis3dh.DATARATE_LOWPOWER_5000

0b1001