67
67
L3DS20_RANGE_500DPS = const (1 )
68
68
L3DS20_RANGE_2000DPS = const (2 )
69
69
70
+ L3DS20_RATE_100HZ = const (0x00 )
71
+ L3DS20_RATE_200HZ = const (0x40 )
72
+ L3DS20_RATE_400HZ = const (0x80 )
73
+ L3DS20_RATE_800HZ = const (0xC0 )
74
+
70
75
_L3GD20_REGISTER_CTRL_REG1 = const (0x20 )
71
76
_L3GD20_REGISTER_CTRL_REG4 = const (0x23 )
72
77
@@ -91,9 +96,12 @@ class L3GD20:
91
96
92
97
:param int rng: a range value one of L3DS20_RANGE_250DPS (default), L3DS20_RANGE_500DPS, or
93
98
L3DS20_RANGE_2000DPS
99
+
100
+ :param int rate: a rate value one of L3DS20_RATE_100HZ (default), L3DS20_RATE_200HZ,
101
+ L3DS20_RATE_400HZ, or L3DS20_RATE_800HZ
94
102
"""
95
103
96
- def __init__ (self , rng = L3DS20_RANGE_250DPS ):
104
+ def __init__ (self , rng = L3DS20_RANGE_250DPS , rate = L3DS20_RATE_100HZ ):
97
105
chip_id = self .read_register (_ID_REGISTER )
98
106
if chip_id not in (_L3GD20_CHIP_ID , _L3GD20H_CHIP_ID ):
99
107
raise RuntimeError (
@@ -119,7 +127,7 @@ def __init__(self, rng=L3DS20_RANGE_250DPS):
119
127
# 0 XEN X-axis enable (0 = disabled, 1 = enabled)
120
128
121
129
# Switch to normal mode and enable all three channels
122
- self .write_register (_L3GD20_REGISTER_CTRL_REG1 , 0x0F )
130
+ self .write_register (_L3GD20_REGISTER_CTRL_REG1 , rate | 0x0F )
123
131
124
132
# Set CTRL_REG2 (0x21)
125
133
# ====================================================================
@@ -212,12 +220,14 @@ class L3GD20_I2C(L3GD20):
212
220
gyro_raw = Struct (_L3GD20_REGISTER_OUT_X_L_X80 , "<hhh" )
213
221
"""Gives the raw gyro readings, in units of rad/s."""
214
222
215
- def __init__ (self , i2c , rng = L3DS20_RANGE_250DPS , address = 0x6B ):
223
+ def __init__ (
224
+ self , i2c , rng = L3DS20_RANGE_250DPS , address = 0x6B , rate = L3DS20_RATE_100HZ
225
+ ):
216
226
import adafruit_bus_device .i2c_device as i2c_device # pylint: disable=import-outside-toplevel
217
227
218
228
self .i2c_device = i2c_device .I2CDevice (i2c , address )
219
229
self .buffer = bytearray (2 )
220
- super ().__init__ (rng )
230
+ super ().__init__ (rng , rate )
221
231
222
232
def write_register (self , register , value ):
223
233
"""
@@ -254,13 +264,20 @@ class L3GD20_SPI(L3GD20):
254
264
:param baudrate: spi baud rate default is 100000
255
265
"""
256
266
257
- def __init__ (self , spi_busio , cs , rng = L3DS20_RANGE_250DPS , baudrate = 100000 ):
267
+ def __init__ (
268
+ self ,
269
+ spi_busio ,
270
+ cs ,
271
+ rng = L3DS20_RANGE_250DPS ,
272
+ baudrate = 100000 ,
273
+ rate = L3DS20_RATE_100HZ ,
274
+ ): # pylint: disable=too-many-arguments
258
275
import adafruit_bus_device .spi_device as spi_device # pylint: disable=import-outside-toplevel
259
276
260
277
self ._spi = spi_device .SPIDevice (spi_busio , cs , baudrate = baudrate )
261
278
self ._spi_bytearray1 = bytearray (1 )
262
279
self ._spi_bytearray6 = bytearray (6 )
263
- super ().__init__ (rng )
280
+ super ().__init__ (rng , rate )
264
281
265
282
def write_register (self , register , value ):
266
283
"""
0 commit comments