Simple test

Ensure your device works with this simple test.

examples/lis3dh_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya

import time
from machine import Pin, I2C
from micropython_lis3dh import lis3dh

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

for _ in range(10):
    accx, accy, accz = lis.acceleration
    print(f"x: {accx}m/s^2, y: {accy}m/s^2, z: {accz}m/s^2")
    print()
    time.sleep(1)

Data Range

Example showing how to change the Data range

examples/lis3dg_data_range.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya

import time
from machine import Pin, I2C
from micropython_lis3dh import lis3dh

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

# Getting information about the current Accelerometers Data Range
print("Accelerometer Data Range: ", lis.data_range)
for _ in range(3):
    accx, accy, accz = lis.acceleration
    print(f"x: {accx}m/s^2, y: {accy}m/s^2, z: {accz}m/s^2")
    print()
    time.sleep(1)

# Changing Data Range of the accelerometer
lis.data_range = lis3dh.DATARANGE_8
print("Accelerometer Changed Data Range: ", lis.data_range)
for _ in range(3):
    accx, accy, accz = lis.acceleration
    print(f"x: {accx}m/s^2, y: {accy}m/s^2, z: {accz}m/s^2")
    print()
    time.sleep(1)

Data Rate

Example showing how to change the Data rate

examples/lis3dh_data_rate.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya

import time
from machine import Pin, I2C
from micropython_lis3dh import lis3dh

i2c = I2C(sda=Pin(8), scl=Pin(9))
lis = lis3dh.LIS3DH(i2c)

# Getting information about the current Accelerometers Data Rate
print("Accelerometer Data Rate: ", lis.data_rate)
for _ in range(3):
    accx, accy, accz = lis.acceleration
    print(f"x: {accx}m/s^2, y: {accy}m/s^2, z: {accz}m/s^2")
    print()
    time.sleep(1)

# Changing Data Rate of the accelerometer
lis.data_rate = lis3dh.DATARATE_200
print("Accelerometer Changed Data Rate: ", lis.data_rate)
for _ in range(3):
    accx, accy, accz = lis.acceleration
    print(f"x: {accx}m/s^2, y: {accy}m/s^2, z: {accz}m/s^2")
    print()
    time.sleep(1)