64
64
65
65
__version__ = "0.0.0-auto.0"
66
66
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DSOX.git"
67
+
68
+ __version__ = "0.0.0-auto.0"
69
+ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS.git"
70
+
67
71
from time import sleep
68
72
from math import radians
69
73
from micropython import const
70
74
import adafruit_bus_device .i2c_device as i2c_device
75
+
71
76
from adafruit_register .i2c_struct import ROUnaryStruct , Struct
72
77
from adafruit_register .i2c_bits import RWBits
73
78
from adafruit_register .i2c_bit import RWBit
74
79
75
- __version__ = "0.0.0-auto.0"
76
- __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS.git"
77
-
78
-
79
- _LSM6DS_DEFAULT_ADDRESS = const (0x6A )
80
-
81
- _LSM6DS_CHIP_ID = const (0x6C )
82
- _ISM330DHCX_CHIP_ID = const (0x6B )
83
- _LSM6DS33_CHIP_ID = const (0x69 )
84
-
85
- _LSM6DS_FUNC_CFG_ACCESS = const (0x1 )
86
- _LSM6DS_PIN_CTRL = const (0x2 )
87
- _LSM6DS_UI_INT_OIS = const (0x6F )
88
- _LSM6DS_WHOAMI = const (0xF )
89
- _LSM6DS_CTRL1_XL = const (0x10 )
90
- _LSM6DS_CTRL2_G = const (0x11 )
91
- _LSM6DS_CTRL3_C = const (0x12 )
92
- _LSM6DS_CTRL_5_C = const (0x14 )
93
- _LSM6DS_MASTER_CONFIG = const (0x14 )
94
- _LSM6DS_CTRL8_XL = const (0x17 )
95
- _LSM6DS_CTRL9_XL = const (0x18 )
96
- _LSM6DS_CTRL10_C = const (0x19 )
97
- _LSM6DS_OUT_TEMP_L = const (0x20 )
98
- _LSM6DS_OUT_TEMP_H = const (0x21 )
99
- _LSM6DS_OUTX_L_G = const (0x22 )
100
- _LSM6DS_OUTX_H_G = const (0x23 )
101
- _LSM6DS_OUTY_L_G = const (0x24 )
102
- _LSM6DS_OUTY_H_G = const (0x25 )
103
- _LSM6DS_OUTZ_L_G = const (0x26 )
104
- _LSM6DS_OUTZ_H_G = const (0x27 )
105
- _LSM6DS_OUTX_L_A = const (0x28 )
106
- _LSM6DS_OUTX_H_A = const (0x29 )
107
- _LSM6DS_OUTY_L_A = const (0x2A )
108
- _LSM6DS_OUTY_H_A = const (0x2B )
109
- _LSM6DS_OUTZ_L_A = const (0x2C )
110
- _LSM6DS_OUTZ_H_A = const (0x2D )
111
- _LSM6DS_STEP_COUNTER = const (0x4B )
112
- _LSM6DS_TAP_CFG = const (0x58 )
113
-
114
- _MILLI_G_TO_ACCEL = 0.00980665
115
-
116
80
117
81
class CV :
118
82
"""struct helper"""
@@ -143,18 +107,6 @@ class GyroRange(CV):
143
107
"""Options for ``gyro_data_range``"""
144
108
145
109
146
- GyroRange .add_values (
147
- (
148
- ("RANGE_125_DPS" , 125 , 125 , 4.375 ),
149
- ("RANGE_250_DPS" , 0 , 250 , 8.75 ),
150
- ("RANGE_500_DPS" , 1 , 500 , 17.50 ),
151
- ("RANGE_1000_DPS" , 2 , 1000 , 35.0 ),
152
- ("RANGE_2000_DPS" , 3 , 2000 , 70.0 ),
153
- ("RANGE_4000_DPS" , 4000 , 4000 , 140.0 ),
154
- )
155
- )
156
-
157
-
158
110
class Rate (CV ):
159
111
"""Options for ``accelerometer_data_rate`` and ``gyro_data_rate``"""
160
112
@@ -190,6 +142,25 @@ class AccelHPF(CV):
190
142
)
191
143
)
192
144
145
+ LSM6DS_DEFAULT_ADDRESS = const (0x6A )
146
+
147
+ LSM6DS_CHIP_ID = const (0x6C )
148
+
149
+ _LSM6DS_WHOAMI = const (0xF )
150
+ _LSM6DS_CTRL1_XL = const (0x10 )
151
+ _LSM6DS_CTRL2_G = const (0x11 )
152
+ _LSM6DS_CTRL3_C = const (0x12 )
153
+ _LSM6DS_CTRL8_XL = const (0x17 )
154
+ _LSM6DS_CTRL9_XL = const (0x18 )
155
+ _LSM6DS_CTRL10_C = const (0x19 )
156
+ _LSM6DS_OUT_TEMP_L = const (0x20 )
157
+ _LSM6DS_OUTX_L_G = const (0x22 )
158
+ _LSM6DS_OUTX_L_A = const (0x28 )
159
+ _LSM6DS_STEP_COUNTER = const (0x4B )
160
+ _LSM6DS_TAP_CFG = const (0x58 )
161
+
162
+ _MILLI_G_TO_ACCEL = 0.00980665
163
+
193
164
194
165
class LSM6DS : # pylint: disable=too-many-instance-attributes
195
166
@@ -224,10 +195,12 @@ class LSM6DS: # pylint: disable=too-many-instance-attributes
224
195
_pedometer_reset = RWBit (_LSM6DS_CTRL10_C , 1 )
225
196
_func_enable = RWBit (_LSM6DS_CTRL10_C , 2 )
226
197
_ped_enable = RWBit (_LSM6DS_TAP_CFG , 6 )
227
-
198
+ pedometer_steps = ROUnaryStruct (_LSM6DS_STEP_COUNTER , "<h" )
199
+ """The number of steps detected by the pedometer. You must enable with `pedometer_enable`
200
+ before calling. Use `pedometer_reset` to reset the number of steps"""
228
201
CHIP_ID = None
229
202
230
- def __init__ (self , i2c_bus , address = _LSM6DS_DEFAULT_ADDRESS ):
203
+ def __init__ (self , i2c_bus , address = LSM6DS_DEFAULT_ADDRESS ):
231
204
self ._cached_accel_range = None
232
205
self ._cached_gyro_range = None
233
206
@@ -239,7 +212,7 @@ def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
239
212
"Failed to find %s - check your wiring!" % self .__class__ .__name__
240
213
)
241
214
self .reset ()
242
-
215
+ self . _add_gyro_ranges ()
243
216
self ._bdu = True
244
217
245
218
self ._add_accel_ranges ()
@@ -255,6 +228,18 @@ def reset(self):
255
228
while self ._sw_reset :
256
229
sleep (0.001 )
257
230
231
+ @staticmethod
232
+ def _add_gyro_ranges ():
233
+ GyroRange .add_values (
234
+ (
235
+ ("RANGE_125_DPS" , 125 , 125 , 4.375 ),
236
+ ("RANGE_250_DPS" , 0 , 250 , 8.75 ),
237
+ ("RANGE_500_DPS" , 1 , 500 , 17.50 ),
238
+ ("RANGE_1000_DPS" , 2 , 1000 , 35.0 ),
239
+ ("RANGE_2000_DPS" , 3 , 2000 , 70.0 ),
240
+ )
241
+ )
242
+
258
243
@staticmethod
259
244
def _add_accel_ranges ():
260
245
AccelRange .add_values (
@@ -320,13 +305,10 @@ def gyro_range(self):
320
305
def gyro_range (self , value ):
321
306
if not GyroRange .is_valid (value ):
322
307
raise AttributeError ("range must be a `GyroRange`" )
323
- if value is GyroRange .RANGE_4000_DPS and not isinstance (self , ISM330DHCX ):
324
- raise AttributeError ("4000 DPS is only available for ISM330DHCX" )
325
-
326
308
if value is GyroRange .RANGE_125_DPS :
327
309
self ._gyro_range_125dps = True
328
310
self ._gyro_range_4000dps = False
329
- elif value is GyroRange . RANGE_4000_DPS :
311
+ elif value == 4000 :
330
312
self ._gyro_range_125dps = False
331
313
self ._gyro_range_4000dps = True
332
314
else :
@@ -387,76 +369,3 @@ def high_pass_filter(self, value):
387
369
if not AccelHPF .is_valid (value ):
388
370
raise AttributeError ("range must be an `AccelHPF`" )
389
371
self ._high_pass_filter = value
390
-
391
-
392
- class LSM6DSOX (LSM6DS ): # pylint: disable=too-many-instance-attributes
393
-
394
- """Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
395
-
396
- :param ~busio.I2C i2c_bus: The I2C bus the LSM6DSOX 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
-
407
-
408
- class LSM6DSO32 (LSM6DS ): # pylint: disable=too-many-instance-attributes
409
-
410
- """Driver for the LSM6DSO32 6-axis accelerometer and gyroscope.
411
-
412
- :param ~busio.I2C i2c_bus: The I2C bus the LSM6DSO32 is connected to.
413
- :param address: The I2C slave address of the sensor
414
-
415
- """
416
-
417
- CHIP_ID = _LSM6DS_CHIP_ID
418
-
419
- def __init__ (self , i2c_bus , address = _LSM6DS_DEFAULT_ADDRESS ):
420
- super ().__init__ (i2c_bus , address )
421
- self ._i3c_disable = True
422
- self .accelerometer_range = AccelRange .RANGE_8G # pylint:disable=no-member
423
-
424
- def _add_accel_ranges (self ):
425
- AccelRange .add_values (
426
- (
427
- ("RANGE_4G" , 0 , 4 , 0.122 ),
428
- ("RANGE_32G" , 1 , 32 , 0.976 ),
429
- ("RANGE_8G" , 2 , 8 , 0.244 ),
430
- ("RANGE_16G" , 3 , 16 , 0.488 ),
431
- )
432
- )
433
-
434
-
435
- class LSM6DS33 (LSM6DS ): # pylint: disable=too-many-instance-attributes
436
-
437
- """Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
438
-
439
- :param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
440
- :param address: The I2C slave address of the sensor
441
-
442
- """
443
-
444
- CHIP_ID = _LSM6DS33_CHIP_ID
445
-
446
-
447
- class ISM330DHCX (LSM6DS ): # pylint: disable=too-many-instance-attributes
448
-
449
- """Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
450
-
451
- :param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
452
- :param address: The I2C slave address of the sensor
453
-
454
- """
455
-
456
- CHIP_ID = _ISM330DHCX_CHIP_ID
457
-
458
- def __init__ (self , i2c_bus , address = _LSM6DS_DEFAULT_ADDRESS ):
459
- super ().__init__ (i2c_bus , address )
460
-
461
- # Called DEVICE_CONF in the datasheet, but it recommends setting it
462
- self ._i3c_disable = True
0 commit comments