20
20
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
# THE SOFTWARE.
22
22
"""
23
- `adafruit_lsm6dsox `
23
+ `adafruit_lsm6ds `
24
24
================================================================================
25
25
26
26
CircuitPython library for the ST LSM6DSOX 6-axis Accelerometer and Gyro
58
58
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DSOX.git"
59
59
60
60
61
- _LSM6DSOX_DEFAULT_ADDRESS = const (0x6a )
62
- _LSM6DSOX_CHIP_ID = const (0x6C )
63
- _ISM330DHCX_CHIP_ID = const (0x6B )
64
-
65
-
66
- _LSM6DSOX_FUNC_CFG_ACCESS = const (0x1 )
67
- _LSM6DSOX_PIN_CTRL = const (0x2 )
68
- _LSM6DSOX_UI_INT_OIS = const (0x6F )
69
- _LSM6DSOX_WHOAMI = const (0xF )
70
- _LSM6DSOX_CTRL1_XL = const (0x10 )
71
- _LSM6DSOX_CTRL2_G = const (0x11 )
72
- _LSM6DSOX_CTRL3_C = const (0x12 )
73
- _LSM6DSOX_CTRL_5_C = const (0x14 )
74
- _LSM6DSOX_MASTER_CONFIG = const (0x14 )
75
- _LSM6DSOX_CTRL9_XL = const (0x18 )
76
- _LSM6DSOX_OUT_TEMP_L = const (0x20 )
77
- _LSM6DSOX_OUT_TEMP_H = const (0x21 )
78
- _LSM6DSOX_OUTX_L_G = const (0x22 )
79
- _LSM6DSOX_OUTX_H_G = const (0x23 )
80
- _LSM6DSOX_OUTY_L_G = const (0x24 )
81
- _LSM6DSOX_OUTY_H_G = const (0x25 )
82
- _LSM6DSOX_OUTZ_L_G = const (0x26 )
83
- _LSM6DSOX_OUTZ_H_G = const (0x27 )
84
- _LSM6DSOX_OUTX_L_A = const (0x28 )
85
- _LSM6DSOX_OUTX_H_A = const (0x29 )
86
- _LSM6DSOX_OUTY_L_A = const (0x2A )
87
- _LSM6DSOX_OUTY_H_A = const (0x2B )
88
- _LSM6DSOX_OUTZ_L_A = const (0x2C )
89
- _LSM6DSOX_OUTZ_H_A = const (0x2D )
61
+ _LSM6DS_DEFAULT_ADDRESS = const (0x6a )
62
+
63
+ _LSM6DS_CHIP_ID = const (0x6C )
64
+ _ISM330DHCT_CHIP_ID = const (0x6B )
65
+ _LSM6DS33_CHIP_ID = const (0x69 )
66
+
67
+ _LSM6DS_FUNC_CFG_ACCESS = const (0x1 )
68
+ _LSM6DS_PIN_CTRL = const (0x2 )
69
+ _LSM6DS_UI_INT_OIS = const (0x6F )
70
+ _LSM6DS_WHOAMI = const (0xF )
71
+ _LSM6DS_CTRL1_XL = const (0x10 )
72
+ _LSM6DS_CTRL2_G = const (0x11 )
73
+ _LSM6DS_CTRL3_C = const (0x12 )
74
+ _LSM6DS_CTRL_5_C = const (0x14 )
75
+ _LSM6DS_MASTER_CONFIG = const (0x14 )
76
+ _LSM6DS_CTRL9_XL = const (0x18 )
77
+ _LSM6DS_OUT_TEMP_L = const (0x20 )
78
+ _LSM6DS_OUT_TEMP_H = const (0x21 )
79
+ _LSM6DS_OUTX_L_G = const (0x22 )
80
+ _LSM6DS_OUTX_H_G = const (0x23 )
81
+ _LSM6DS_OUTY_L_G = const (0x24 )
82
+ _LSM6DS_OUTY_H_G = const (0x25 )
83
+ _LSM6DS_OUTZ_L_G = const (0x26 )
84
+ _LSM6DS_OUTZ_H_G = const (0x27 )
85
+ _LSM6DS_OUTX_L_A = const (0x28 )
86
+ _LSM6DS_OUTX_H_A = const (0x29 )
87
+ _LSM6DS_OUTY_L_A = const (0x2A )
88
+ _LSM6DS_OUTY_H_A = const (0x2B )
89
+ _LSM6DS_OUTZ_L_A = const (0x2C )
90
+ _LSM6DS_OUTZ_H_A = const (0x2D )
90
91
91
92
_MILLI_G_TO_ACCEL = 0.00980665
92
93
@@ -153,7 +154,8 @@ class Rate(CV):
153
154
('RATE_1_6_HZ' , 11 , 1.6 , None )
154
155
))
155
156
156
- class LSM6DSOX : #pylint: disable=too-many-instance-attributes
157
+
158
+ class LSM6DS : #pylint: disable=too-many-instance-attributes
157
159
158
160
"""Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
159
161
@@ -163,73 +165,72 @@ class LSM6DSOX: #pylint: disable=too-many-instance-attributes
163
165
"""
164
166
165
167
#ROUnaryStructs:
166
- _chip_id = ROUnaryStruct (_LSM6DSOX_WHOAMI , "<b" )
167
- _temperature = ROUnaryStruct (_LSM6DSOX_OUT_TEMP_L , "<h" )
168
+ _chip_id = ROUnaryStruct (_LSM6DS_WHOAMI , "<b" )
169
+ _temperature = ROUnaryStruct (_LSM6DS_OUT_TEMP_L , "<h" )
168
170
169
171
#RWBits:
170
- _ois_ctrl_from_ui = RWBit (_LSM6DSOX_FUNC_CFG_ACCESS , 0 )
171
- _shub_reg_access = RWBit (_LSM6DSOX_FUNC_CFG_ACCESS , 6 )
172
- _func_cfg_access = RWBit (_LSM6DSOX_FUNC_CFG_ACCESS , 7 )
173
- _sdo_pu_en = RWBit (_LSM6DSOX_PIN_CTRL , 6 )
174
- _ois_pu_dis = RWBit (_LSM6DSOX_PIN_CTRL , 7 )
175
- _spi2_read_en = RWBit (_LSM6DSOX_UI_INT_OIS , 3 )
176
- _den_lh_ois = RWBit (_LSM6DSOX_UI_INT_OIS , 5 )
177
- _lvl2_ois = RWBit (_LSM6DSOX_UI_INT_OIS , 6 )
178
- _int2_drdy_ois = RWBit (_LSM6DSOX_UI_INT_OIS , 7 )
179
- _lpf_xl = RWBit (_LSM6DSOX_CTRL1_XL , 1 )
180
-
181
- _accel_range = RWBits (2 , _LSM6DSOX_CTRL1_XL , 2 )
182
- _accel_data_rate = RWBits (4 , _LSM6DSOX_CTRL1_XL , 4 )
183
-
184
- _gyro_data_rate = RWBits (4 , _LSM6DSOX_CTRL2_G , 4 )
185
- _gyro_range = RWBits (2 , _LSM6DSOX_CTRL2_G , 2 )
186
- _gyro_range_125dps = RWBit (_LSM6DSOX_CTRL2_G , 1 )
187
-
188
- _sw_reset = RWBit (_LSM6DSOX_CTRL3_C , 0 )
189
- _if_inc = RWBit (_LSM6DSOX_CTRL3_C , 2 )
190
- _sim = RWBit (_LSM6DSOX_CTRL3_C , 3 )
191
- _pp_od = RWBit (_LSM6DSOX_CTRL3_C , 4 )
192
- _h_lactive = RWBit (_LSM6DSOX_CTRL3_C , 5 )
193
- _bdu = RWBit (_LSM6DSOX_CTRL3_C , 6 )
194
- _boot = RWBit (_LSM6DSOX_CTRL3_C , 7 )
195
- _st_xl = RWBits (2 , _LSM6DSOX_CTRL_5_C , 0 )
196
- _st_g = RWBits (2 , _LSM6DSOX_CTRL_5_C , 2 )
197
- _rounding_status = RWBit (_LSM6DSOX_CTRL_5_C , 4 )
198
- _rounding = RWBits (2 , _LSM6DSOX_CTRL_5_C , 5 )
199
- _xl_ulp_en = RWBit (_LSM6DSOX_CTRL_5_C , 7 )
200
- _aux_sens_on = RWBits (2 , _LSM6DSOX_MASTER_CONFIG , 0 )
201
- _master_on = RWBit (_LSM6DSOX_MASTER_CONFIG , 2 )
202
- _shub_pu_en = RWBit (_LSM6DSOX_MASTER_CONFIG , 3 )
203
- _pass_through_mode = RWBit (_LSM6DSOX_MASTER_CONFIG , 4 )
204
- _start_config = RWBit (_LSM6DSOX_MASTER_CONFIG , 5 )
205
- _write_once = RWBit (_LSM6DSOX_MASTER_CONFIG , 6 )
206
- _rst_master_regs = RWBit (_LSM6DSOX_MASTER_CONFIG , 7 )
207
- _i3c_disable = RWBit (_LSM6DSOX_CTRL9_XL , 1 )
208
-
209
- _raw_temp = ROUnaryStruct (_LSM6DSOX_OUT_TEMP_L , "<h" )
210
-
211
- _raw_accel_data = Struct (_LSM6DSOX_OUTX_L_A , "<hhh" )
212
- _raw_gyro_data = Struct (_LSM6DSOX_OUTX_L_G , "<hhh" )
213
-
214
- def __init__ (self , i2c_bus , address = _LSM6DSOX_DEFAULT_ADDRESS ):
215
- self .i2c_device = i2c_device .I2CDevice (i2c_bus , address )
172
+ _ois_ctrl_from_ui = RWBit (_LSM6DS_FUNC_CFG_ACCESS , 0 )
173
+ _shub_reg_access = RWBit (_LSM6DS_FUNC_CFG_ACCESS , 6 )
174
+ _func_cfg_access = RWBit (_LSM6DS_FUNC_CFG_ACCESS , 7 )
175
+ _sdo_pu_en = RWBit (_LSM6DS_PIN_CTRL , 6 )
176
+ _ois_pu_dis = RWBit (_LSM6DS_PIN_CTRL , 7 )
177
+ _spi2_read_en = RWBit (_LSM6DS_UI_INT_OIS , 3 )
178
+ _den_lh_ois = RWBit (_LSM6DS_UI_INT_OIS , 5 )
179
+ _lvl2_ois = RWBit (_LSM6DS_UI_INT_OIS , 6 )
180
+ _int2_drdy_ois = RWBit (_LSM6DS_UI_INT_OIS , 7 )
181
+ _lpf_xl = RWBit (_LSM6DS_CTRL1_XL , 1 )
182
+
183
+ _accel_range = RWBits (2 , _LSM6DS_CTRL1_XL , 2 )
184
+ _accel_data_rate = RWBits (4 , _LSM6DS_CTRL1_XL , 4 )
185
+
186
+ _gyro_data_rate = RWBits (4 , _LSM6DS_CTRL2_G , 4 )
187
+ _gyro_range = RWBits (2 , _LSM6DS_CTRL2_G , 2 )
188
+ _gyro_range_125dps = RWBit (_LSM6DS_CTRL2_G , 1 )
189
+ _gyro_range_4000dps = RWBit (_LSM6DS_CTRL2_G , 0 )
190
+
191
+ _sw_reset = RWBit (_LSM6DS_CTRL3_C , 0 )
192
+ _sim = RWBit (_LSM6DS_CTRL3_C , 3 )
193
+ _pp_od = RWBit (_LSM6DS_CTRL3_C , 4 )
194
+ _h_lactive = RWBit (_LSM6DS_CTRL3_C , 5 )
195
+ _bdu = RWBit (_LSM6DS_CTRL3_C , 6 )
196
+ _boot = RWBit (_LSM6DS_CTRL3_C , 7 )
197
+ _st_xl = RWBits (2 , _LSM6DS_CTRL_5_C , 0 )
198
+ _st_g = RWBits (2 , _LSM6DS_CTRL_5_C , 2 )
199
+ _rounding_status = RWBit (_LSM6DS_CTRL_5_C , 4 )
200
+ _rounding = RWBits (2 , _LSM6DS_CTRL_5_C , 5 )
201
+ _xl_ulp_en = RWBit (_LSM6DS_CTRL_5_C , 7 )
202
+ _aux_sens_on = RWBits (2 , _LSM6DS_MASTER_CONFIG , 0 )
203
+ _master_on = RWBit (_LSM6DS_MASTER_CONFIG , 2 )
204
+ _shub_pu_en = RWBit (_LSM6DS_MASTER_CONFIG , 3 )
205
+ _pass_through_mode = RWBit (_LSM6DS_MASTER_CONFIG , 4 )
206
+ _start_config = RWBit (_LSM6DS_MASTER_CONFIG , 5 )
207
+ _write_once = RWBit (_LSM6DS_MASTER_CONFIG , 6 )
208
+ _rst_master_regs = RWBit (_LSM6DS_MASTER_CONFIG , 7 )
209
+ _i3c_disable = RWBit (_LSM6DS_CTRL9_XL , 1 )
210
+
211
+ _raw_temp = ROUnaryStruct (_LSM6DS_OUT_TEMP_L , "<h" )
212
+
213
+ _raw_accel_data = Struct (_LSM6DS_OUTX_L_A , "<hhh" )
214
+ _raw_gyro_data = Struct (_LSM6DS_OUTX_L_G , "<hhh" )
215
+ CHIP_ID = None
216
+ def __init__ (self , i2c_bus , address = _LSM6DS_DEFAULT_ADDRESS ):
217
+ self ._cached_accel_range = None
218
+ self ._cached_gyro_range = None
216
219
217
- if self ._chip_id not in [_LSM6DSOX_CHIP_ID , _ISM330DHCX_CHIP_ID ]:
218
- raise RuntimeError ("Failed to find LSM6DSOX or ISM330DHCX - check your wiring!" )
220
+ self .i2c_device = i2c_device .I2CDevice (i2c_bus , address )
221
+ if self .CHIP_ID is None :
222
+ raise AttributeError ("LSM6DS Parent Class cannot be directly instantiated" )
223
+ if self ._chip_id != self .CHIP_ID :
224
+ raise RuntimeError ("Failed to find %s - check your wiring!" % self .__class__ .__name__ )
219
225
self .reset ()
220
226
221
227
self ._bdu = True
222
- self ._i3c_disable = True
223
- self ._if_inc = True
224
228
225
- self ._accel_data_rate = Rate .RATE_104_HZ #pylint: disable=no-member
226
- self ._gyro_data_rate = Rate .RATE_104_HZ #pylint: disable=no-member
227
-
228
- self ._accel_range = AccelRange .RANGE_4G #pylint: disable=no-member
229
- self ._cached_accel_range = self ._accel_range
230
- self ._gyro_range = GyroRange .RANGE_250_DPS #pylint: disable=no-member
231
- self ._cached_gyro_range = self ._gyro_range
229
+ self .accelerometer_data_rate = Rate .RATE_104_HZ #pylint: disable=no-member
230
+ self .gyro_data_rate = Rate .RATE_104_HZ #pylint: disable=no-member
232
231
232
+ self .accelerometer_range = AccelRange .RANGE_4G #pylint: disable=no-member
233
+ self .gyro_range = GyroRange .RANGE_250_DPS #pylint: disable=no-member
233
234
234
235
def reset (self ):
235
236
"Resets the sensor's configuration into an initial state"
@@ -240,12 +241,6 @@ def reset(self):
240
241
while self ._boot :
241
242
sleep (0.001 )
242
243
243
- @property
244
- def is_lsm6dsox (self ):
245
- """Returns `True` if the connected sensor is an LSM6DSOX,
246
- `False` if not, it's an ICM330DHCX"""
247
- return self ._chip_id is _LSM6DSOX_CHIP_ID
248
-
249
244
@property
250
245
def acceleration (self ):
251
246
"""The x, y, z acceleration values returned in a 3-tuple and are in m / s ^ 2."""
@@ -291,15 +286,15 @@ def accelerometer_range(self, value):
291
286
def gyro_range (self ):
292
287
"""Adjusts the range of values that the sensor can measure, from 125 Degrees/second to 4000
293
288
degrees/s. Note that larger ranges will be less accurate. Must be a `GyroRange`. 4000 DPS
294
- is only available for the ISM330DHCX """
289
+ is only available for the ISM330DHCT """
295
290
return self ._cached_gyro_range
296
291
297
292
@gyro_range .setter
298
293
def gyro_range (self , value ):
299
294
if not GyroRange .is_valid (value ):
300
295
raise AttributeError ("range must be a `GyroRange`" )
301
- if value is GyroRange .RANGE_4000_DPS and self . is_lsm6dsox :
302
- raise AttributeError ("4000 DPS is only available for ISM330DHCX " )
296
+ if value is GyroRange .RANGE_4000_DPS and not isinstance ( self , ISM330DHCT ) :
297
+ raise AttributeError ("4000 DPS is only available for ISM330DHCT " )
303
298
304
299
if value is GyroRange .RANGE_125_DPS :
305
300
self ._gyro_range_125dps = True
@@ -309,7 +304,7 @@ def gyro_range(self, value):
309
304
self ._gyro_range_4000dps = True
310
305
else :
311
306
self ._gyro_range_125dps = False
312
- self ._gyro_range_4000dps = True
307
+ self ._gyro_range_4000dps = False
313
308
self ._gyro_range = value
314
309
315
310
self ._cached_gyro_range = value
@@ -344,3 +339,41 @@ def gyro_data_rate(self, value):
344
339
345
340
self ._gyro_data_rate = value
346
341
# sleep(.2) # needed to let new range settle
342
+
343
+ class LSM6DSOX (LSM6DS ): #pylint: disable=too-many-instance-attributes
344
+
345
+ """Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
346
+
347
+ :param ~busio.I2C i2c_bus: The I2C bus the LSM6DSOX is connected to.
348
+ :param address: The I2C slave address of the sensor
349
+
350
+ """
351
+ CHIP_ID = _LSM6DS_CHIP_ID
352
+ def __init__ (self , i2c_bus , address = _LSM6DS_DEFAULT_ADDRESS ):
353
+ super ().__init__ (i2c_bus , address )
354
+ self ._i3c_disable = True
355
+
356
+ class LSM6DS33 (LSM6DS ): #pylint: disable=too-many-instance-attributes
357
+
358
+ """Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
359
+
360
+ :param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
361
+ :param address: The I2C slave address of the sensor
362
+
363
+ """
364
+ CHIP_ID = _LSM6DS33_CHIP_ID
365
+
366
+ class ISM330DHCT (LSM6DS ): #pylint: disable=too-many-instance-attributes
367
+
368
+ """Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
369
+
370
+ :param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
371
+ :param address: The I2C slave address of the sensor
372
+
373
+ """
374
+ CHIP_ID = _ISM330DHCT_CHIP_ID
375
+ def __init__ (self , i2c_bus , address = _LSM6DS_DEFAULT_ADDRESS ):
376
+ super ().__init__ (i2c_bus , address )
377
+
378
+ # Called DEVICE_CONF in the datasheet, but it recommends setting it
379
+ self ._i3c_disable = True
0 commit comments