Skip to content

Commit a0e05ce

Browse files
committed
updating examples and tested data rates
1 parent 82a66fc commit a0e05ce

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

adafruit_icm20x.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class ICM20X: # pylint:disable=too-many-instance-attributes
165165
_device_id = ROUnaryStruct(_ICM20X_WHO_AM_I, ">B")
166166
_bank_reg = UnaryStruct(_ICM20X_REG_BANK_SEL, ">B")
167167
_reset = RWBit(_ICM20X_PWR_MGMT_1, 7)
168-
_sleep = RWBit(_ICM20X_PWR_MGMT_1, 6)
168+
_sleep_reg = RWBit(_ICM20X_PWR_MGMT_1, 6)
169169
_low_power_en = RWBit(_ICM20X_PWR_MGMT_1, 5)
170170
_clock_source = RWBits(3, _ICM20X_PWR_MGMT_1, 0)
171171

@@ -246,15 +246,10 @@ def __init__(self, i2c_bus, address):
246246
def initialize(self):
247247
"""Configure the sensors with the default settings. For use after calling `reset()`"""
248248

249-
self._bank = 0
250-
sleep(0.005)
251249
self._sleep = False
252-
sleep(0.005)
253-
254250
self.accelerometer_range = AccelRange.RANGE_8G # pylint: disable=no-member
255251
self.gyro_range = GyroRange.RANGE_500_DPS # pylint: disable=no-member
256252

257-
# TODO: Test these
258253
self.accelerometer_data_rate_divisor = 20 # ~53.57Hz
259254
self.gyro_data_rate_divisor = 10 # ~100Hz
260255

@@ -268,6 +263,20 @@ def reset(self):
268263
while self._reset:
269264
sleep(0.005)
270265

266+
@property
267+
def _sleep(self):
268+
self._bank = 0
269+
sleep(0.005)
270+
self._sleep_reg = False
271+
sleep(0.005)
272+
273+
@_sleep.setter
274+
def _sleep(self, sleep_enabled):
275+
self._bank = 0
276+
sleep(0.005)
277+
self._sleep_reg = sleep_enabled
278+
sleep(0.005)
279+
271280
@property
272281
def acceleration(self):
273282
"""The x, y, z acceleration values returned in a 3-tuple and are in m / s ^ 2."""
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import time
2+
import board
3+
import busio
4+
from adafruit_icm20x import ICM20948
5+
6+
cycles = 200
7+
i2c = busio.I2C(board.SCL, board.SDA)
8+
icm = ICM20948(i2c)
9+
10+
# Cycle between two data rates
11+
# Best viewed in the Mu serial plotter where you can see how
12+
# the data rate affects the resolution of the data
13+
while True:
14+
icm.accelerometer_data_rate_divisor = 0 # minimum
15+
print("Data Rate:", icm.accelerometer_data_rate)
16+
time.sleep(2)
17+
for i in range(cycles):
18+
print(icm.acceleration)
19+
20+
icm.accelerometer_data_rate_divisor = 4095 # maximum
21+
print("Data Rate:", icm.accelerometer_data_rate)
22+
time.sleep(2)
23+
for i in range(cycles):
24+
print(icm.acceleration)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import time
2+
import board
3+
import busio
4+
from adafruit_icm20x import ICM20948
5+
6+
cycles = 200
7+
i2c = busio.I2C(board.SCL, board.SDA)
8+
icm = ICM20948(i2c)
9+
10+
# Cycle between two data rates
11+
# Best viewed in the Mu serial plotter where you can see how
12+
# the data rate affects the resolution of the data
13+
while True:
14+
icm.gyro_data_rate_divisor = 0 # minimum
15+
print("Data Rate:", icm.gyro_data_rate)
16+
time.sleep(2)
17+
for i in range(cycles):
18+
print(icm.gyro)
19+
20+
icm.gyro_data_rate_divisor = 255 # maximum
21+
print("Data Rate:", icm.gyro_data_rate)
22+
time.sleep(2)
23+
for i in range(cycles):
24+
print(icm.gyro)

examples/icm20948_mag_data_rate_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=no-member
12
import time
23
import board
34
import busio
@@ -7,7 +8,6 @@
78
i2c = busio.I2C(board.SCL, board.SDA)
89
icm = ICM20948(i2c)
910

10-
icm.accelerometer_data_rate_divisor = 0
1111
# Cycle between two data rates
1212
# Best viewed in the Mu serial plotter where you can see how
1313
# the data rate affects the resolution of the data

0 commit comments

Comments
 (0)