From 1a5fb365b0b67e2a767777370a2c60e121b875ac Mon Sep 17 00:00:00 2001 From: myllyja <43068636+myllyja@users.noreply.github.com> Date: Fri, 25 Feb 2022 20:21:30 +0200 Subject: [PATCH 1/2] Fixed LSM6DS3 to LSM6DS3TR-C This chip has slightly different registers. --- adafruit_lsm6ds/{lsm6ds3.py => lsm6ds3trc.py} | 21 ++++++++++------- examples/lsm6ds_lsm6ds3trc_simpletest.py | 23 +++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) rename adafruit_lsm6ds/{lsm6ds3.py => lsm6ds3trc.py} (55%) create mode 100644 examples/lsm6ds_lsm6ds3trc_simpletest.py diff --git a/adafruit_lsm6ds/lsm6ds3.py b/adafruit_lsm6ds/lsm6ds3trc.py similarity index 55% rename from adafruit_lsm6ds/lsm6ds3.py rename to adafruit_lsm6ds/lsm6ds3trc.py index ad4292e..23a2f62 100644 --- a/adafruit_lsm6ds/lsm6ds3.py +++ b/adafruit_lsm6ds/lsm6ds3trc.py @@ -2,36 +2,37 @@ # # SPDX-License-Identifier: MIT """ -This module provides the `adafruit_lsm6ds.lsm6ds3` subclass of LSM6DS sensors +This module provides the `adafruit_lsm6ds.lsm6ds3trc` subclass of LSM6DS sensors =============================================================================== """ -from . import LSM6DS +from . import LSM6DS, RWBit, const +_LSM6DS_CTRL10_C = const(0x19) -class LSM6DS3(LSM6DS): # pylint: disable=too-many-instance-attributes +class LSM6DS3TRC(LSM6DS): # pylint: disable=too-many-instance-attributes - """Driver for the LSM6DS3 6-axis accelerometer and gyroscope. + """Driver for the LSM6DS3TR-C 6-axis accelerometer and gyroscope. - :param ~busio.I2C i2c_bus: The I2C bus the LSM6DS3 is connected to. + :param ~busio.I2C i2c_bus: The I2C bus the LSM6DS3TR-C is connected to. :param int address: The I2C device address. Defaults to :const:`0x6A` **Quickstart: Importing and using the device** - Here is an example of using the :class:`LSM6DS3` class. + Here is an example of using the :class:`LSM6DS3TRC` class. First you will need to import the libraries to use the sensor .. code-block:: python import board - from adafruit_lsm6ds.lsm6ds3 import LSM6DS3 + from adafruit_lsm6ds.lsm6ds3trc import LSM6DS3TRC Once this is done you can define your `board.I2C` object and define your sensor object .. code-block:: python i2c = board.I2C() # uses board.SCL and board.SDA - sensor = LSM6DS3(i2c) + sensor = LSM6DS3TRC(i2c) Now you have access to the :attr:`acceleration` and :attr:`gyro`: attributes @@ -43,3 +44,7 @@ class LSM6DS3(LSM6DS): # pylint: disable=too-many-instance-attributes """ CHIP_ID = 0x6A + + # This version of the IMU has a different register for enabling the pedometer + # https://www.st.com/resource/en/datasheet/lsm6ds3tr-c.pdf + _ped_enable = RWBit(_LSM6DS_CTRL10_C, 4) diff --git a/examples/lsm6ds_lsm6ds3trc_simpletest.py b/examples/lsm6ds_lsm6ds3trc_simpletest.py new file mode 100644 index 0000000..aeab67a --- /dev/null +++ b/examples/lsm6ds_lsm6ds3trc_simpletest.py @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries +# +# SPDX-License-Identifier: MIT +import time +import board +import digitalio +import busio +from adafruit_lsm6ds.lsm6ds3trc import LSM6DS3TRC + +# On the Seeed XIAO nRF52840 Sense the LSM6DS3TR-C IMU is connected on a separate +# I2C bus and it has its own power pin that we need to enable. +imupwr = digitalio.DigitalInOut(board.IMU_PWR) +imupwr.direction = digitalio.Direction.OUTPUT +imupwr.value = True + +imu_i2c = busio.I2C(board.IMU_SCL, board.IMU_SDA) +sensor = LSM6DS3TRC(imu_i2c) + +while True: + print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration)) + print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro)) + print("") + time.sleep(0.5) From 5897882366fc7168c4bb0df4747d2d734db0db60 Mon Sep 17 00:00:00 2001 From: myllyja <43068636+myllyja@users.noreply.github.com> Date: Fri, 25 Feb 2022 21:12:47 +0200 Subject: [PATCH 2/2] Fix to comply with python/black formatting --- adafruit_lsm6ds/lsm6ds3trc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_lsm6ds/lsm6ds3trc.py b/adafruit_lsm6ds/lsm6ds3trc.py index 23a2f62..a918b60 100644 --- a/adafruit_lsm6ds/lsm6ds3trc.py +++ b/adafruit_lsm6ds/lsm6ds3trc.py @@ -9,6 +9,7 @@ _LSM6DS_CTRL10_C = const(0x19) + class LSM6DS3TRC(LSM6DS): # pylint: disable=too-many-instance-attributes """Driver for the LSM6DS3TR-C 6-axis accelerometer and gyroscope.