Skip to content

Commit

Permalink
fixing bank selection and examples formating
Browse files Browse the repository at this point in the history
  • Loading branch information
jposada202020 committed Aug 11, 2023
1 parent 682be78 commit 3da06b0
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 46 deletions.
3 changes: 3 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
MicroPython ICM20948 Driver
===========================


.. automodule:: micropython_icm20948
:members:
Expand Down
5 changes: 0 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
"sphinx_immaterial",
]
Expand Down Expand Up @@ -185,10 +184,6 @@
},
]

python_type_aliases = {
"DigitalInOut": "digitalio.DigitalInOut",
}

object_description_options = [
("py:.*", dict(generate_synopses="first_sentence")),
]
Expand Down
2 changes: 1 addition & 1 deletion examples/icm20948_acc_dlpf_cutoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
print("Current Acc dlpf cutoff setting: ", icm.acc_dlpf_cutoff)
for _ in range(10):
accx, accy, accz = icm.acceleration
print("x:{:.2f}m/s2, y:{:.2f}m/s2, z:{:.2f}m/s2".format(accx, accy, accz))
print(f"x:{accx:.2f}m/, y:{accy:.2f}m/, z:{accz:.2f}m/s²")
print()
time.sleep(0.5)
icm.acc_dlpf_cutoff = acc_dlpf_cutoff
2 changes: 1 addition & 1 deletion examples/icm20948_accelerometer_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
print("Current Accelerometer range setting: ", icm.accelerometer_range)
for _ in range(10):
accx, accy, accz = icm.acceleration
print("x:{:.2f}m/s2, y:{:.2f}m/s2, z:{:.2f}m/s2".format(accx, accy, accz))
print(f"x:{accx:.2f}m/, y:{accy:.2f}m/, z:{accz:.2f}m/s²")
print()
time.sleep(0.5)
icm.accelerometer_range = accelerometer_range
2 changes: 1 addition & 1 deletion examples/icm20948_clock_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
print("Current Clock select setting: ", icm.clock_select)
for _ in range(10):
accx, accy, accz = icm.acceleration
print("x:{:.2f}m/s2, y:{:.2f}m/s2, z:{:.2f}m/s2".format(accx, accy, accz))
print(f"x:{accx:.2f}m/, y:{accy:.2f}m/, z:{accz:.2f}m/s²")
print()
time.sleep(0.5)
icm.clock_select = clock_select
5 changes: 3 additions & 2 deletions examples/icm20948_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
from machine import Pin, I2C
from micropython_icm20948 import icm20948

i2c = I2C(sda=Pin(8), scl=Pin(9)) # Correct I2C pins for UM FeatherS2
i2c = I2C(1, sda=Pin(2), scl=Pin(3))
icm = icm20948.ICM20948(i2c)


while True:
accx, accy, accz = icm.acceleration
gyrox, gyroy, gyroz = icm.gyro
print(f"x: {accx}m/s2, y: {accy},m/s2 z: {accz}m/s2")
print(f"x: {accx}m/, y: {accy},m/ z: {accz}m/")
print(f"x: {gyrox}°/s, y: {gyroy}°/s, z: {gyroz}°/s")
print()
time.sleep(1)
5 changes: 4 additions & 1 deletion examples/icm20948_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
from machine import Pin, I2C
from micropython_icm20948 import icm20948

i2c = I2C(sda=Pin(8), scl=Pin(9)) # Correct I2C pins for UM FeatherS2
i2c = I2C(1, sda=Pin(2), scl=Pin(3))
icm = icm20948.ICM20948(i2c)

_ = icm.temperature # Dummy read to initialize the sensor
time.sleep(0.05)


while True:
print(f"Temperature: {icm.temperature}°C")
Expand Down
52 changes: 26 additions & 26 deletions micropython_icm20948/icm20948.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ def __init__(self, i2c, address=0x69):
self.gyro_full_scale = FS_500_DPS

self.acc_data_rate_divisor = 22
print("ACC Data rate Divisor", self.acc_data_rate_divisor)
self.gyro_data_rate_divisor = 10
print("ACC data rate", self.acc_data_rate)

@property
def clock_select(self):
Expand Down Expand Up @@ -413,7 +411,7 @@ def acceleration(self) -> Tuple[float, float, float]:
:return: Acceleration Values
"""
raw_measurement = self._raw_accel_data
sleep(0.005)
# sleep(0.005)
x = (
raw_measurement[0]
/ acc_range_sensitivity[self._memory_accel_range]
Expand All @@ -440,7 +438,7 @@ def gyro(self) -> Tuple[float, float, float]:
:return: Angular velocity Values
"""
raw_measurement = self._raw_gyro_data
sleep(0.005)
# sleep(0.005)
x = (
raw_measurement[0]
/ gyro_full_scale_sensitivity[self._memory_gyro_fs]
Expand Down Expand Up @@ -498,7 +496,6 @@ def accelerometer_range(self, value: int) -> None:
raise ValueError("Value must be a valid Accelerometer Range Setting")
self._user_bank = 2
self._acc_data_range = value
sleep(0.005)
self._memory_accel_range = value
self._user_bank = 0

Expand Down Expand Up @@ -528,10 +525,10 @@ def gyro_full_scale(self, value: int) -> None:
raise ValueError("Value must be a valid gyro_full_scale setting")
self._user_bank = 2
self._gyro_full_scale = value
sleep(0.005)
# sleep(0.005)
self._memory_gyro_fs = value
self._user_bank = 0
sleep(0.1)
# sleep(0.1)

@property
def temperature(self) -> float:
Expand Down Expand Up @@ -616,7 +613,7 @@ def gyro_data_rate_divisor(self) -> int:

self._user_bank = 2
raw_rate_divisor = self._gyro_rate_divisor
sleep(0.005)
# sleep(0.005)
self._user_bank = 0
return raw_rate_divisor

Expand All @@ -625,9 +622,10 @@ def gyro_data_rate_divisor(self, value: int) -> None:
if value not in gyro_rate_divisor_values:
raise ValueError("Value must be a valid gyro data rate divisor setting")
self._user_bank = 2
sleep(0.005)
# sleep(0.005)
self._gyro_rate_divisor = value
sleep(0.005)
self._user_bank = 0
# sleep(0.005)

@property
def acc_data_rate(self):
Expand Down Expand Up @@ -694,7 +692,7 @@ def acc_data_rate_divisor(self) -> int:

self._user_bank = 2
raw_rate_divisor = self._acc_rate_divisor
sleep(0.005)
# sleep(0.005)
self._user_bank = 0
return raw_rate_divisor

Expand All @@ -705,9 +703,10 @@ def acc_data_rate_divisor(self, value: int) -> None:
"Value must be a valid acceleration data rate divisor setting"
)
self._user_bank = 2
sleep(0.005)
# sleep(0.005)
self._acc_rate_divisor = value
sleep(0.005)
self._user_bank = 0
# sleep(0.005)

@property
def acc_dlpf_cutoff(self) -> int:
Expand Down Expand Up @@ -746,37 +745,38 @@ def acc_dlpf_cutoff(self) -> int:
"FREQ_473",
)
self._user_bank = 2
sleep(0.005)
# sleep(0.005)
raw_value = self._acc_dplcfg
print(raw_value)
self._user_bank = 0
return values[raw_value]
return values[raw_value - 1]

@acc_dlpf_cutoff.setter
def acc_dlpf_cutoff(self, value: int) -> None:
if value not in acc_filter_values:
raise ValueError("Value must be a valid dlpf setting")
self._user_bank = 2
sleep(0.005)
# sleep(0.005)
self._acc_dplcfg = value
self._user_bank = 0
sleep(0.005)
# sleep(0.005)

@property
def acc_filter_choice(self) -> int:
"""Enables accelerometer DLPF"""
self._user_bank = 2
sleep(0.005)
# sleep(0.005)
raw_value = self._acc_choice
self._user_bank = 0
return raw_value

@acc_filter_choice.setter
def acc_filter_choice(self, value: int) -> None:
self._user_bank = 2
sleep(0.005)
# sleep(0.005)
self._acc_choice = value
self._user_bank = 0
sleep(0.05)
# sleep(0.05)

@property
def gyro_dlpf_cutoff(self) -> int:
Expand Down Expand Up @@ -818,7 +818,7 @@ def gyro_dlpf_cutoff(self) -> int:
"G_FREQ_361_4",
)
self._user_bank = 2
sleep(0.005)
# sleep(0.005)
raw_value = self._gyro_dplcfg
self._user_bank = 0
return values[raw_value]
Expand All @@ -828,24 +828,24 @@ def gyro_dlpf_cutoff(self, value: int) -> None:
if value not in gyro_filter_values:
raise ValueError("Value must be a valid dlpf setting")
self._user_bank = 2
sleep(0.005)
# sleep(0.005)
self._gyro_dplcfg = value
self._user_bank = 0
sleep(0.005)
# sleep(0.005)

@property
def gyro_filter_choice(self) -> int:
"""Enables gyro DLPF"""
self._user_bank = 2
sleep(0.005)
# sleep(0.005)
raw_value = self._gyro_choice
self._user_bank = 0
return raw_value

@gyro_filter_choice.setter
def gyro_filter_choice(self, value: int) -> None:
self._user_bank = 2
sleep(0.005)
# sleep(0.005)
self._gyro_choice = value
self._user_bank = 0
sleep(0.05)
# sleep(0.05)
15 changes: 6 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,27 @@
# SPDX-License-Identifier: MIT

[build-system]
requires = [
"setuptools",
"wheel",
"setuptools-scm",
]
requires = ["setuptools", "wheel", "setuptools-scm"]

[project]
name = "micropython-icm20948"
description = "MicroPython Driver for the Accelerometer and Gyro ICM20948 Sensor"
version = "0.0.0+auto.0"
readme = "README.rst"
authors = [
{name = "Jose D. Montoya", email = "icm20948@mailmeto.mozmail.com"}
{ name = "Jose D. Montoya", email = "icm20948@mailmeto.mozmail.com" },
]
urls = {Homepage = "https://github.com/jposada202020/MicroPython_ICM20948"}
urls = { Homepage = "https://github.com/jposada202020/MicroPython_ICM20948" }
keywords = [
"micropython",
"icm20948",
"gyro",
"accelerometer",
"acceleration",
"sensor",
"tdk",
]
license = {text = "MIT"}
license = { text = "MIT" }
classifiers = [
"Intended Audience :: Developers",
"Topic :: Software Development :: Libraries",
Expand All @@ -41,4 +38,4 @@ dynamic = ["dependencies", "optional-dependencies"]
packages = ["micropython_icm20948"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
dependencies = { file = ["requirements.txt"] }

0 comments on commit 3da06b0

Please sign in to comment.