-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from uutzinger/main
Improvements on datarate, added dataReady function, fixed accelerometer and gyroscope divisor
- Loading branch information
Showing
5 changed files
with
83 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
|
||
import time | ||
import board | ||
from adafruit_icm20x import ICM20649, AccelRange, GyroRange | ||
|
||
i2c = board.I2C() # uses board.SCL and board.SDA | ||
|
||
ism = ICM20649(i2c, address=0x69) | ||
|
||
ism.accelerometer_range = AccelRange.RANGE_4G | ||
print("Accelerometer range set to: %d g" % AccelRange.string[ism.accelerometer_range]) | ||
|
||
ism.gyro_range = GyroRange.RANGE_500_DPS | ||
print("Gyro range set to: %d DPS" % GyroRange.string[ism.gyro_range]) | ||
|
||
ism.gyro_data_rate = 1100 # 1100 max | ||
ism.accelerometer_data_rate = 1125 # 1125 max | ||
|
||
print("Gyro rate: {:f}".format(ism.gyro_data_rate)) | ||
print("Accel rate: {:f}".format(ism.accelerometer_data_rate)) | ||
|
||
ism.gravity = 9.8 | ||
|
||
previousTime = time.perf_counter() | ||
while True: | ||
if ism.data_ready: | ||
currentTime = time.perf_counter() | ||
print("\033[2J") | ||
print( | ||
"Accel X:%5.2f Y:%5.2f Z:%5.2f ms^2 " | ||
"Gyro X:%8.3f Y:%8.3f Z:%8.3f degrees/s Sample Rate: %8.1f Hz" | ||
% (*ism.acceleration, *ism.gyro, (1 / (currentTime - previousTime))) | ||
) | ||
previousTime = currentTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters