Simple test

Ensure your device works with this simple test.

examples/lsm6dsox_simpletest.py
import time
from machine import Pin, I2C
from micropython_lsm6dsox import LSM6DSOX

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
lsm = LSM6DSOX(i2c)

while True:
    accx, accy, accz = lsm.acceleration
    print(f"x:{accx:.2f}m/s2, y:{accy:.2f}m/s2, z{accz:.2f}m/s2")
    gyrox, gyroy, gyroz = lsm.gyro
    print(f"x:{gyrox:.2f}°/s, y:{gyroy:.2f}°/s, z{gyroz:.2f}°/s")
    print("")
    time.sleep(0.5)

Acceleration data rate settings

Example showing the Acceleration data rate setting

examples/lsm6dsox_acceleration_data_rate.py
import time
from machine import Pin, I2C
from micropython_lsm6dsox import lsm6dsox

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
lsm = lsm6dsox.LSM6DSOX(i2c)

# The sensor seems to return strange values doing this example
# Not sure why. Work left for the reader


data_rate_values = (
    lsm6dsox.RATE_104_HZ,
    lsm6dsox.RATE_208_HZ,
    lsm6dsox.RATE_416_HZ,
    lsm6dsox.RATE_833_HZ,
    lsm6dsox.RATE_1_66K_HZ,
    lsm6dsox.RATE_3_33K_HZ,
    lsm6dsox.RATE_6_66K_HZ,
)

lsm.acceleration_data_rate = lsm6dsox.RATE_104_HZ


while True:
    for acceleration_data_rate in data_rate_values:
        print("Current Acceleration data rate setting: ", lsm.acceleration_data_rate)
        for _ in range(3):
            accx, accy, accz = lsm.acceleration
            print(f"x:{accx:.2f}m/s2, y:{accy:.2f}m/s2, z{accz:.2f}m/s2")
            print()
            time.sleep(0.5)
        lsm.acceleration_data_rate = acceleration_data_rate

Gyro data rate settings

Example showing the Gyro data rate setting

examples/lsm6dsox_gyro_data_rate.py
import time
from machine import Pin, I2C
from micropython_lsm6dsox import lsm6dsox

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
lsm = lsm6dsox.LSM6DSOX(i2c)

lsm.gyro_data_rate = lsm6dsox.RATE_104_HZ

while True:
    for gyro_data_rate in lsm6dsox.data_rate_values:
        print("Current Gyro data rate setting: ", lsm.gyro_data_rate)
        for _ in range(3):
            gyrox, gyroy, gyroz = lsm.gyro
            print(f"x:{gyrox:.2f}°/s, y:{gyroy:.2f}°/s, z{gyroz:.2f}°/s")
            print("")
            time.sleep(0.5)
        lsm.gyro_data_rate = gyro_data_rate

Acceleration range settings

Example showing the Acceleration range setting

examples/lsm6dsox_acceleration_range.py
import time
from machine import Pin, I2C
from micropython_lsm6dsox import lsm6dsox

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
lsm = lsm6dsox.LSM6DSOX(i2c)

lsm.acceleration_range = lsm6dsox.RANGE_8G

while True:
    for acceleration_range in lsm6dsox.acceleration_range_values:
        print("Current Acceleration range setting: ", lsm.acceleration_range)
        for _ in range(3):
            accx, accy, accz = lsm.acceleration
            print(f"x:{accx:.2f}m/s2, y:{accy:.2f}m/s2, z{accz:.2f}m/s2")
            print()
            time.sleep(0.5)
        lsm.acceleration_range = acceleration_range

Gyro range settings

Example showing the Gyro range setting

examples/lsm6dsox_gyro_range.py
import time
from machine import Pin, I2C
from micropython_lsm6dsox import lsm6dsox

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
lsm = lsm6dsox.LSM6DSOX(i2c)

lsm.gyro_range = lsm6dsox.RANGE_2000_DPS

while True:
    for gyro_range in lsm6dsox.gyro_range_values:
        print("Current Gyro range setting: ", lsm.gyro_range)
        for _ in range(3):
            gyrox, gyroy, gyroz = lsm.gyro
            print(f"x:{gyrox:.2f}°/s, y:{gyroy:.2f}°/s, z{gyroz:.2f}°/s")
            print("")
            time.sleep(0.5)
        lsm.gyro_range = gyro_range

High pass filter settings

Example showing the High pass filter setting

examples/lsm6dsox_high_pass_filter.py
import time
from machine import Pin, I2C
from micropython_lsm6dsox import lsm6dsox

i2c = I2C(1, sda=Pin(2), scl=Pin(3))  # Correct I2C pins for RP2040
lsm = lsm6dsox.LSM6DSOX(i2c)

lsm.high_pass_filter = lsm6dsox.HPF_DIV400

while True:
    for high_pass_filter in lsm6dsox.high_pass_filter_values:
        print("Current High pass filter setting: ", lsm.high_pass_filter)
        for _ in range(10):
            accx, accy, accz = lsm.acceleration
            print(f"x:{accx:.2f}m/s2, y:{accy:.2f}m/s2, z{accz:.2f}m/s2")
            print()
            time.sleep(0.5)
        lsm.high_pass_filter = high_pass_filter