29
29
30
30
* Adafruit's Register library:
31
31
https://github.com/adafruit/Adafruit_CircuitPython_Register
32
+
32
33
"""
33
34
34
35
# imports
74
75
STANDARD_GRAVITY = 9.80665
75
76
76
77
78
+ class ClockSource : # pylint: disable=too-few-public-methods
79
+ """Allowed values for :py:attr:`clock_source`.
80
+
81
+ * :py:attr:'ClockSource.CLKSEL_INTERNAL_8MHz
82
+ * :py:attr:'ClockSource.CLKSEL_INTERNAL_X
83
+ * :py:attr:'ClockSource.CLKSEL_INTERNAL_Y
84
+ * :py:attr:'ClockSource.CLKSEL_INTERNAL_Z
85
+ * :py:attr:'ClockSource.CLKSEL_EXTERNAL_32
86
+ * :py:attr:'ClockSource.CLKSEL_EXTERNAL_19
87
+ * :py:attr:'ClockSource.CLKSEL_RESERVED
88
+ * :py:attr:'ClockSource.CLKSEL_STOP
89
+ """
90
+
91
+ CLKSEL_INTERNAL_8MHz = 0 # Internal 8MHz oscillator
92
+ CLKSEL_INTERNAL_X = 1 # PLL with X Axis gyroscope reference
93
+ CLKSEL_INTERNAL_Y = 2 # PLL with Y Axis gyroscope reference
94
+ CLKSEL_INTERNAL_Z = 3 # PLL with Z Axis gyroscope reference
95
+ CLKSEL_EXTERNAL_32 = 4 # External 32.768 kHz reference
96
+ CLKSEL_EXTERNAL_19 = 5 # External 19.2 MHz reference
97
+ CLKSEL_RESERVED = 6 # Reserved
98
+ CLKSEL_STOP = 7 # Stops the clock, constant reset mode
99
+
100
+
77
101
class Range : # pylint: disable=too-few-public-methods
78
- """Allowed values for `accelerometer_range`.
102
+ """Allowed values for :py:attr: `accelerometer_range`.
79
103
80
- * :attr:`Range.RANGE_2_G`
81
- * :attr:`Range.RANGE_4_G`
82
- * :attr:`Range.RANGE_8_G`
83
- * :attr:`Range.RANGE_16_G`
104
+ * :py: attr:`Range.RANGE_2_G`
105
+ * :py: attr:`Range.RANGE_4_G`
106
+ * :py: attr:`Range.RANGE_8_G`
107
+ * :py: attr:`Range.RANGE_16_G`
84
108
85
109
"""
86
110
@@ -91,12 +115,12 @@ class Range: # pylint: disable=too-few-public-methods
91
115
92
116
93
117
class GyroRange : # pylint: disable=too-few-public-methods
94
- """Allowed values for `gyro_range`.
118
+ """Allowed values for :py:attr: `gyro_range`.
95
119
96
- * :attr:`GyroRange.RANGE_250_DPS`
97
- * :attr:`GyroRange.RANGE_500_DPS`
98
- * :attr:`GyroRange.RANGE_1000_DPS`
99
- * :attr:`GyroRange.RANGE_2000_DPS`
120
+ * :py: attr:`GyroRange.RANGE_250_DPS`
121
+ * :py: attr:`GyroRange.RANGE_500_DPS`
122
+ * :py: attr:`GyroRange.RANGE_1000_DPS`
123
+ * :py: attr:`GyroRange.RANGE_2000_DPS`
100
124
101
125
"""
102
126
@@ -107,15 +131,15 @@ class GyroRange: # pylint: disable=too-few-public-methods
107
131
108
132
109
133
class Bandwidth : # pylint: disable=too-few-public-methods
110
- """Allowed values for `filter_bandwidth`.
134
+ """Allowed values for :py:attr: `filter_bandwidth`.
111
135
112
- * :attr:`Bandwidth.BAND_260_HZ`
113
- * :attr:`Bandwidth.BAND_184_HZ`
114
- * :attr:`Bandwidth.BAND_94_HZ`
115
- * :attr:`Bandwidth.BAND_44_HZ`
116
- * :attr:`Bandwidth.BAND_21_HZ`
117
- * :attr:`Bandwidth.BAND_10_HZ`
118
- * :attr:`Bandwidth.BAND_5_HZ`
136
+ * :py: attr:`Bandwidth.BAND_260_HZ`
137
+ * :py: attr:`Bandwidth.BAND_184_HZ`
138
+ * :py: attr:`Bandwidth.BAND_94_HZ`
139
+ * :py: attr:`Bandwidth.BAND_44_HZ`
140
+ * :py: attr:`Bandwidth.BAND_21_HZ`
141
+ * :py: attr:`Bandwidth.BAND_10_HZ`
142
+ * :py: attr:`Bandwidth.BAND_5_HZ`
119
143
120
144
"""
121
145
@@ -129,12 +153,12 @@ class Bandwidth: # pylint: disable=too-few-public-methods
129
153
130
154
131
155
class Rate : # pylint: disable=too-few-public-methods
132
- """Allowed values for `cycle_rate`.
156
+ """Allowed values for :py:attr: `cycle_rate`.
133
157
134
- * :attr:`Rate.CYCLE_1_25_HZ`
135
- * :attr:`Rate.CYCLE_5_HZ`
136
- * :attr:`Rate.CYCLE_20_HZ`
137
- * :attr:`Rate.CYCLE_40_HZ`
158
+ * :py: attr:`Rate.CYCLE_1_25_HZ`
159
+ * :py: attr:`Rate.CYCLE_5_HZ`
160
+ * :py: attr:`Rate.CYCLE_20_HZ`
161
+ * :py: attr:`Rate.CYCLE_40_HZ`
138
162
139
163
"""
140
164
@@ -175,7 +199,6 @@ class MPU6050:
175
199
acc_x, acc_y, acc_z = sensor.acceleration
176
200
gyro_x, gyro_y, gyro_z = sensor.gyro
177
201
temperature = sensor.temperature
178
-
179
202
"""
180
203
181
204
def __init__ (self , i2c_bus : I2C , address : int = _MPU6050_DEFAULT_ADDRESS ) -> None :
@@ -191,7 +214,9 @@ def __init__(self, i2c_bus: I2C, address: int = _MPU6050_DEFAULT_ADDRESS) -> Non
191
214
self ._gyro_range = GyroRange .RANGE_500_DPS
192
215
self ._accel_range = Range .RANGE_2_G
193
216
sleep (0.100 )
194
- self ._clock_source = 1 # set to use gyro x-axis as reference
217
+ self .clock_source = (
218
+ ClockSource .CLKSEL_INTERNAL_X
219
+ ) # set to use gyro x-axis as reference
195
220
sleep (0.100 )
196
221
self .sleep = False
197
222
sleep (0.010 )
@@ -206,7 +231,7 @@ def reset(self) -> None:
206
231
_signal_path_reset = 0b111 # reset all sensors
207
232
sleep (0.100 )
208
233
209
- _clock_source = RWBits (3 , _MPU6050_PWR_MGMT_1 , 0 )
234
+ _clksel = RWBits (3 , _MPU6050_PWR_MGMT_1 , 0 )
210
235
_device_id = ROUnaryStruct (_MPU6050_WHO_AM_I , ">B" )
211
236
212
237
_reset = RWBit (_MPU6050_PWR_MGMT_1 , 7 , 1 )
@@ -347,3 +372,17 @@ def cycle_rate(self, value: int) -> None:
347
372
raise ValueError ("cycle_rate must be a Rate" )
348
373
self ._cycle_rate = value
349
374
sleep (0.01 )
375
+
376
+ @property
377
+ def clock_source (self ) -> int :
378
+ """The clock source for the sensor"""
379
+ return self ._clksel
380
+
381
+ @clock_source .setter
382
+ def clock_source (self , value : int ) -> None :
383
+ """Select between Internal/External clock sources"""
384
+ if value not in range (8 ):
385
+ raise ValueError (
386
+ "clock_source must be ClockSource value, integer from 0 - 7."
387
+ )
388
+ self ._clksel = value
0 commit comments