Skip to content

Commit 7261e46

Browse files
authored
Merge pull request #50 from myllyja/fix-lsm6ds3trc
Fixed LSM6DS3 to LSM6DS3TR-C
2 parents ccfea10 + 5897882 commit 7261e46

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

adafruit_lsm6ds/lsm6ds3.py renamed to adafruit_lsm6ds/lsm6ds3trc.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,38 @@
22
#
33
# SPDX-License-Identifier: MIT
44
"""
5-
This module provides the `adafruit_lsm6ds.lsm6ds3` subclass of LSM6DS sensors
5+
This module provides the `adafruit_lsm6ds.lsm6ds3trc` subclass of LSM6DS sensors
66
===============================================================================
77
"""
8-
from . import LSM6DS
8+
from . import LSM6DS, RWBit, const
99

10+
_LSM6DS_CTRL10_C = const(0x19)
1011

11-
class LSM6DS3(LSM6DS): # pylint: disable=too-many-instance-attributes
1212

13-
"""Driver for the LSM6DS3 6-axis accelerometer and gyroscope.
13+
class LSM6DS3TRC(LSM6DS): # pylint: disable=too-many-instance-attributes
1414

15-
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS3 is connected to.
15+
"""Driver for the LSM6DS3TR-C 6-axis accelerometer and gyroscope.
16+
17+
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS3TR-C is connected to.
1618
:param int address: The I2C device address. Defaults to :const:`0x6A`
1719
1820
1921
**Quickstart: Importing and using the device**
2022
21-
Here is an example of using the :class:`LSM6DS3` class.
23+
Here is an example of using the :class:`LSM6DS3TRC` class.
2224
First you will need to import the libraries to use the sensor
2325
2426
.. code-block:: python
2527
2628
import board
27-
from adafruit_lsm6ds.lsm6ds3 import LSM6DS3
29+
from adafruit_lsm6ds.lsm6ds3trc import LSM6DS3TRC
2830
2931
Once this is done you can define your `board.I2C` object and define your sensor object
3032
3133
.. code-block:: python
3234
3335
i2c = board.I2C() # uses board.SCL and board.SDA
34-
sensor = LSM6DS3(i2c)
36+
sensor = LSM6DS3TRC(i2c)
3537
3638
Now you have access to the :attr:`acceleration` and :attr:`gyro`: attributes
3739
@@ -43,3 +45,7 @@ class LSM6DS3(LSM6DS): # pylint: disable=too-many-instance-attributes
4345
"""
4446

4547
CHIP_ID = 0x6A
48+
49+
# This version of the IMU has a different register for enabling the pedometer
50+
# https://www.st.com/resource/en/datasheet/lsm6ds3tr-c.pdf
51+
_ped_enable = RWBit(_LSM6DS_CTRL10_C, 4)
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
import time
5+
import board
6+
import digitalio
7+
import busio
8+
from adafruit_lsm6ds.lsm6ds3trc import LSM6DS3TRC
9+
10+
# On the Seeed XIAO nRF52840 Sense the LSM6DS3TR-C IMU is connected on a separate
11+
# I2C bus and it has its own power pin that we need to enable.
12+
imupwr = digitalio.DigitalInOut(board.IMU_PWR)
13+
imupwr.direction = digitalio.Direction.OUTPUT
14+
imupwr.value = True
15+
16+
imu_i2c = busio.I2C(board.IMU_SCL, board.IMU_SDA)
17+
sensor = LSM6DS3TRC(imu_i2c)
18+
19+
while True:
20+
print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration))
21+
print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro))
22+
print("")
23+
time.sleep(0.5)

0 commit comments

Comments
 (0)