Skip to content

Commit 0dfdcbe

Browse files
committed
added the lsm6dso32
1 parent f1cc47f commit 0dfdcbe

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

README.rst.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2+
3+
SPDX-License-Identifier: MIT

adafruit_lsm6ds.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,6 @@ class AccelRange(CV):
123123
"""Options for ``accelerometer_range``"""
124124

125125

126-
AccelRange.add_values(
127-
(
128-
("RANGE_2G", 0, 2, 0.061),
129-
("RANGE_16G", 1, 16, 0.488),
130-
("RANGE_4G", 2, 4, 0.122),
131-
("RANGE_8G", 3, 8, 0.244),
132-
)
133-
)
134-
135-
136126
class GyroRange(CV):
137127
"""Options for ``gyro_data_range``"""
138128

@@ -236,6 +226,7 @@ def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
236226

237227
self._bdu = True
238228

229+
self._add_accel_ranges()
239230
self.accelerometer_data_rate = Rate.RATE_104_HZ # pylint: disable=no-member
240231
self.gyro_data_rate = Rate.RATE_104_HZ # pylint: disable=no-member
241232

@@ -248,10 +239,22 @@ def reset(self):
248239
while self._sw_reset:
249240
sleep(0.001)
250241

242+
@staticmethod
243+
def _add_accel_ranges():
244+
AccelRange.add_values(
245+
(
246+
("RANGE_2G", 0, 2, 0.061),
247+
("RANGE_16G", 1, 16, 0.488),
248+
("RANGE_4G", 2, 4, 0.122),
249+
("RANGE_8G", 3, 8, 0.244),
250+
)
251+
)
252+
251253
@property
252254
def acceleration(self):
253255
"""The x, y, z acceleration values returned in a 3-tuple and are in m / s ^ 2."""
254256
raw_accel_data = self._raw_accel_data
257+
255258
x = self._scale_xl_data(raw_accel_data[0])
256259
y = self._scale_xl_data(raw_accel_data[1])
257260
z = self._scale_xl_data(raw_accel_data[2])
@@ -386,6 +389,33 @@ def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
386389
self._i3c_disable = True
387390

388391

392+
class LSM6DSO32(LSM6DS): # pylint: disable=too-many-instance-attributes
393+
394+
"""Driver for the LSM6DSO32 6-axis accelerometer and gyroscope.
395+
396+
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DSO32 is connected to.
397+
:param address: The I2C slave address of the sensor
398+
399+
"""
400+
401+
CHIP_ID = _LSM6DS_CHIP_ID
402+
403+
def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
404+
super().__init__(i2c_bus, address)
405+
self._i3c_disable = True
406+
self.accelerometer_range = AccelRange.RANGE_8G # pylint:disable=no-member
407+
408+
def _add_accel_ranges(self):
409+
AccelRange.add_values(
410+
(
411+
("RANGE_4G", 0, 4, 0.122),
412+
("RANGE_32G", 1, 32, 0.976),
413+
("RANGE_8G", 2, 8, 0.244),
414+
("RANGE_16G", 3, 16, 0.488),
415+
)
416+
)
417+
418+
389419
class LSM6DS33(LSM6DS): # pylint: disable=too-many-instance-attributes
390420

391421
"""Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import time
2+
import board
3+
import busio
4+
from adafruit_lsm6ds import LSM6DSO32
5+
6+
i2c = busio.I2C(board.SCL, board.SDA)
7+
sensor = LSM6DSO32(i2c)
8+
while True:
9+
print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration))
10+
print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro))
11+
print("")
12+
time.sleep(0.5)

0 commit comments

Comments
 (0)