LSM6DSOX Simple test

Ensure your LSM6DSOX device works with this simple test.

examples/lsm6ds_lsm6dsox_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4import time
 5import board
 6from adafruit_lsm6ds.lsm6dsox import LSM6DSOX
 7
 8i2c = board.I2C()  # uses board.SCL and board.SDA
 9sensor = LSM6DSOX(i2c)
10
11while True:
12    print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration))
13    print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro))
14    print("")
15    time.sleep(0.5)

LSM6DSO32 Simple test

Ensure your LSM6DSO32 device works with this simple test.

examples/lsm6ds_lsm6dso32_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4import time
 5import board
 6from adafruit_lsm6ds.lsm6dso32 import LSM6DSO32
 7
 8i2c = board.I2C()  # uses board.SCL and board.SDA
 9sensor = LSM6DSO32(i2c)
10
11while True:
12    print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration))
13    print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro))
14    print("")
15    time.sleep(0.5)

LSM6DS Simple test

Ensure your LSM6DS device works with this simple test.

examples/lsm6ds_lsm6ds33_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4import time
 5import board
 6from adafruit_lsm6ds.lsm6ds33 import LSM6DS33
 7
 8i2c = board.I2C()  # uses board.SCL and board.SDA
 9sensor = LSM6DS33(i2c)
10
11while True:
12    print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration))
13    print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro))
14    print("")
15    time.sleep(0.5)

ISM330DHCX Simple test

Ensure your ISM330DHCX device works with this simple test.

examples/lsm6ds_ism330dhcx_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4import time
 5import board
 6from adafruit_lsm6ds.ism330dhcx import ISM330DHCX
 7
 8i2c = board.I2C()  # uses board.SCL and board.SDA
 9sensor = ISM330DHCX(i2c)
10
11while True:
12    print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration))
13    print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro))
14    print("")
15    time.sleep(0.5)

LSM6DS Full test

LSM6DS Full tests

examples/lsm6ds_full_test.py
 1# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4import time
 5import board
 6
 7# pylint:disable=no-member
 8from adafruit_lsm6ds import Rate, AccelRange, GyroRange
 9
10from adafruit_lsm6ds.lsm6dsox import LSM6DSOX as LSM6DS
11
12# from adafruit_lsm6ds.lsm6ds33 import LSM6DS33 as LSM6DS
13# from adafruit_lsm6ds.lsm6dso32 import LSM6DSO32 as LSM6DS
14# from adafruit_lsm6ds.ism330dhcx import ISM330DHCX as LSM6DS
15
16i2c = board.I2C()  # uses board.SCL and board.SDA
17sensor = LSM6DS(i2c)
18
19sensor.accelerometer_range = AccelRange.RANGE_8G
20print(
21    "Accelerometer range set to: %d G" % AccelRange.string[sensor.accelerometer_range]
22)
23
24sensor.gyro_range = GyroRange.RANGE_2000_DPS
25print("Gyro range set to: %d DPS" % GyroRange.string[sensor.gyro_range])
26
27sensor.accelerometer_data_rate = Rate.RATE_1_66K_HZ
28# sensor.accelerometer_data_rate = Rate.RATE_12_5_HZ
29print("Accelerometer rate set to: %d HZ" % Rate.string[sensor.accelerometer_data_rate])
30
31sensor.gyro_data_rate = Rate.RATE_1_66K_HZ
32print("Gyro rate set to: %d HZ" % Rate.string[sensor.gyro_data_rate])
33
34while True:
35    print(
36        "Accel X:%.2f Y:%.2f Z:%.2f ms^2 Gyro X:%.2f Y:%.2f Z:%.2f radians/s"
37        % (sensor.acceleration + sensor.gyro)
38    )
39    time.sleep(0.05)

Pedometer Example

Example showing how to use the device as a pedometer

examples/lsm6ds_pedometer.py
 1# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4""" This example shows off how to use the step counter built
 5into the ST LSM6DS series IMUs. The steps are calculated in
 6the chip so you don't have to do any calculations!"""
 7
 8import time
 9import board
10
11# pylint:disable=no-member
12from adafruit_lsm6ds.lsm6ds33 import LSM6DS33
13from adafruit_lsm6ds import Rate, AccelRange
14
15i2c = board.I2C()  # uses board.SCL and board.SDA
16sensor = LSM6DS33(i2c)
17
18# enable accelerometer sensor @ 2G and 26 Hz
19sensor.accelerometer_range = AccelRange.RANGE_2G
20sensor.accelerometer_data_rate = Rate.RATE_26_HZ
21# no gyro used for step detection
22sensor.gyro_data_rate = Rate.RATE_SHUTDOWN
23
24# enable the pedometer
25sensor.pedometer_enable = True
26
27while True:
28    print("Steps: ", sensor.pedometer_steps)
29    time.sleep(1)

Rate test

Example showing a Rate test

examples/lsm6ds_rate_test.py
 1# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4import board
 5
 6# pylint:disable=no-member,unused-import
 7from adafruit_lsm6ds import Rate
 8from adafruit_lsm6ds.lsm6dsox import LSM6DSOX as LSM6DS
 9
10# from adafruit_lsm6ds.lsm6ds33 import LSM6DS33 as LSM6DS
11# from adafruit_lsm6ds.lsm6dso32 import LSM6DSO32 as LSM6DS
12# from adafruit_lsm6ds.ism330dhcx import ISM330DHCX as LSM6DS
13
14i2c = board.I2C()  # uses board.SCL and board.SDA
15sensor = LSM6DS(i2c)
16
17while True:
18    sensor.accelerometer_data_rate = Rate.RATE_12_5_HZ
19    sensor.gyro_data_rate = Rate.RATE_12_5_HZ
20    for i in range(100):
21        print(
22            "(%.2f, %.2f, %.2f, %.2f, %.2f, %.2f" % (sensor.acceleration + sensor.gyro)
23        )
24    print()
25
26    sensor.accelerometer_data_rate = Rate.RATE_52_HZ
27    sensor.gyro_data_rate = Rate.RATE_52_HZ
28    for i in range(100):
29        print(
30            "(%.2f, %.2f, %.2f, %.2f, %.2f, %.2f" % (sensor.acceleration + sensor.gyro)
31        )
32    print()
33
34    sensor.accelerometer_data_rate = Rate.RATE_416_HZ
35    sensor.gyro_data_rate = Rate.RATE_416_HZ
36    for i in range(100):
37        print(
38            "(%.2f, %.2f, %.2f, %.2f, %.2f, %.2f" % (sensor.acceleration + sensor.gyro)
39        )
40    print()