diff --git a/.pylintrc b/.pylintrc index 40208c3..af5fc6e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,399 +1,122 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# SPDX-FileCopyrightText: 2023 Jose D. Montoya # # SPDX-License-Identifier: Unlicense [MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code extension-pkg-whitelist= - -# Add files or directories to the ignore-list. They should be base names, not -# paths. ignore=CVS - -# Add files or directories matching the regex patterns to the ignore-list. The -# regex matches against base names, not paths. ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). #init-hook= - -# Use multiple processes to speed up Pylint. jobs=1 - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. load-plugins=pylint.extensions.no_self_use - -# Pickle collected data for later comparisons. persistent=yes - -# Specify a configuration file. -#rcfile= - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. unsafe-load-any-extension=no - [MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. enable= - [REPORTS] - -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details #msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio).You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. output-format=text - -# Tells whether to display a full report or only the messages reports=no - -# Activate the evaluation score. score=yes - [REFACTORING] - -# Maximum number of nested blocks for function / method body max-nested-blocks=5 - [LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format logging-modules=logging - [SPELLING] - -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. spelling-dict= - -# List of comma separated words that should not be checked. spelling-ignore-words= - -# A path to a file that contains private dictionary; one word per line. spelling-private-dict-file= - -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. spelling-store-unknown-words=no - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -# notes=FIXME,XXX,TODO -notes=FIXME,XXX - - [TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. generated-members= - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). ignore-mixin-members=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis. It -# supports qualified module names, as well as Unix pattern matching. ignored-modules=board - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. missing-member-max-choices=1 - [VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. callbacks=cb_,_cb - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. redefining-builtins-modules=six.moves,future.builtins - [FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -# expected-line-ending-format= expected-line-ending-format=LF - -# Regexp for a line that is allowed to be longer than the limit. ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). indent-string=' ' - -# Maximum number of characters on a single line. max-line-length=100 - -# Maximum number of lines in a module max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. single-line-if-stmt=no - [SIMILARITIES] - -# Ignore comments when computing similarities. ignore-comments=yes - -# Ignore docstrings when computing similarities. ignore-docstrings=yes - -# Ignore imports when computing similarities. ignore-imports=yes - -# Minimum lines number of a similarity. min-similarity-lines=12 - [BASIC] - -# Regular expression matching correct argument names argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct attribute names attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Bad variable names which should always be refused, separated by a comma bad-names=foo,bar,baz,toto,tutu,tata - -# Regular expression matching correct class attribute names class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct class names -# class-rgx=[A-Z_][a-zA-Z0-9]+$ class-rgx=[A-Z_][a-zA-Z0-9_]+$ - -# Regular expression matching correct constant names const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. docstring-min-length=-1 - -# Regular expression matching correct function names function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Good variable names which should always be accepted, separated by a comma -# good-names=i,j,k,ex,Run,_ -good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ - -# Include a hint for the correct naming format with invalid-name +good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_,cs,c,a,b,s1,s2,s3,s4 include-naming-hint=no - -# Regular expression matching correct inline iteration names inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. property-classes=abc.abstractproperty - -# Regular expression matching correct variable names variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - [IMPORTS] - -# Allow wildcard imports from modules that define __all__. allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma deprecated-modules=optparse,tkinter.tix - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) ext-import-graph= - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. known-standard-library= - -# Force import order to recognize a module as part of a third party library. known-third-party=enchant - [CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. defining-attr-methods=__init__,__new__,setUp - -# List of member names, which should be excluded from the protected access -# warning. exclude-protected=_asdict,_fields,_replace,_source,_make - -# List of valid names for the first argument in a class method. valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. valid-metaclass-classmethod-first-arg=mcs - [DESIGN] - -# Maximum number of arguments for function / method max-args=5 - -# Maximum number of attributes for a class (see R0902). -# max-attributes=7 -max-attributes=11 - -# Maximum number of boolean expressions in a if statement +max-attributes=30 max-bool-expr=5 - -# Maximum number of branch for function / method body max-branches=12 - -# Maximum number of locals for function / method body max-locals=15 - -# Maximum number of parents for a class (see R0901). max-parents=7 - -# Maximum number of public methods for a class (see R0904). max-public-methods=20 - -# Maximum number of return / yield for function / method body max-returns=6 - -# Maximum number of statements in function / method body max-statements=50 - -# Minimum number of public methods for a class (see R0903). min-public-methods=1 - [EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" overgeneral-exceptions=Exception diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 94e63f2..097d102 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -5,7 +5,7 @@ version: 2 build: - os: ubuntu-20.04 + os: ubuntu-22.04 tools: python: "3" diff --git a/docs/conf.py b/docs/conf.py index 3942ea4..0cbd5d9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: MIT @@ -33,7 +31,6 @@ "sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinx.ext.napoleon", - "sphinx.ext.todo", "sphinx.ext.viewcode", "sphinx_immaterial", ] diff --git a/docs/examples.rst b/docs/examples.rst index 1c4891e..59eba15 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,3 +6,57 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/icm20948_simpletest.py :caption: examples/icm20948_simpletest.py :linenos: + +Clock select settings +---------------------- + +Example showing the Clock select setting + +.. literalinclude:: ../examples/icm20948_clock_select.py + :caption: examples/icm20948_clock_select.py + :lines: 5- + +Accelerometer range settings +----------------------------- + +Example showing the Accelerometer range setting + +.. literalinclude:: ../examples/icm20948_accelerometer_range.py + :caption: examples/icm20948_accelerometer_range.py + :lines: 5- + +Acc dlpf cutoff settings +------------------------- + +Example showing the Acc dlpf cutoff setting + +.. literalinclude:: ../examples/icm20948_acc_dlpf_cutoff.py + :caption: examples/icm20948_acc_dlpf_cutoff.py + :lines: 5- + +Gyro full scale settings +------------------------- + +Example showing the Gyro full scale setting + +.. literalinclude:: ../examples/icm20948_gyro_full_scale.py + :caption: examples/icm20948_gyro_full_scale.py + :lines: 5- + +Gyro dlpf cutoff settings +-------------------------- + +Example showing the Gyro dlpf cutoff setting + +.. literalinclude:: ../examples/icm20948_gyro_dlpf_cutoff.py + :caption: examples/icm20948_gyro_dlpf_cutoff.py + :lines: 5- + +Temperature Example +-------------------------- + +Example showing the how to get the temperature + +.. literalinclude:: ../examples/icm20948_temperature.py + :caption: examples/icm20948_temperature.py + :lines: 5- diff --git a/docs/index.rst b/docs/index.rst index 8934f8c..7fb774e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -20,3 +20,8 @@ Table of Contents :maxdepth: 3 api + +.. toctree:: + :caption: Other Links + + Download from GitHub diff --git a/examples.json b/examples.json index 1796b10..f10abba 100644 --- a/examples.json +++ b/examples.json @@ -1,6 +1,33 @@ { "urls": [ - ["micropython_icm20948/examples/icm20948_simpletest.py", "github:jposada202020/MicroPython_ICM20948/examples/icm20948_simpletest.py"] + [ + "micropython_icm20948/examples/icm20948_acc_dlpf_cutoff.py", + "github:jposada202020/MicroPython_ICM20948/examples/icm20948_acc_dlpf_cutoff.py" + ], + [ + "micropython_icm20948/examples/icm20948_temperature.py", + "github:jposada202020/MicroPython_ICM20948/examples/icm20948_temperature.py" + ], + [ + "micropython_icm20948/examples/icm20948_simpletest.py", + "github:jposada202020/MicroPython_ICM20948/examples/icm20948_simpletest.py" + ], + [ + "micropython_icm20948/examples/icm20948_gyro_full_scale.py", + "github:jposada202020/MicroPython_ICM20948/examples/icm20948_gyro_full_scale.py" + ], + [ + "micropython_icm20948/examples/icm20948_accelerometer_range.py", + "github:jposada202020/MicroPython_ICM20948/examples/icm20948_accelerometer_range.py" + ], + [ + "micropython_icm20948/examples/icm20948_clock_select.py", + "github:jposada202020/MicroPython_ICM20948/examples/icm20948_clock_select.py" + ], + [ + "micropython_icm20948/examples/icm20948_gyro_dlpf_cutoff.py", + "github:jposada202020/MicroPython_ICM20948/examples/icm20948_gyro_dlpf_cutoff.py" + ] ], - "version": "0.1" + "version": "1" } diff --git a/examples/icm20948_acc_dlpf_cutoff.py b/examples/icm20948_acc_dlpf_cutoff.py new file mode 100644 index 0000000..90a2582 --- /dev/null +++ b/examples/icm20948_acc_dlpf_cutoff.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya +# +# SPDX-License-Identifier: MIT + +import time +from machine import Pin, I2C +from micropython_icm20948 import icm20948 + +i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040 +icm = icm20948.ICM20948(i2c) + +icm.acc_dlpf_cutoff = icm20948.FREQ_246_0 + +while True: + for acc_dlpf_cutoff in icm20948.acc_filter_values: + 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() + time.sleep(0.5) + icm.acc_dlpf_cutoff = acc_dlpf_cutoff diff --git a/examples/icm20948_accelerometer_range.py b/examples/icm20948_accelerometer_range.py new file mode 100644 index 0000000..2922b8c --- /dev/null +++ b/examples/icm20948_accelerometer_range.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya +# +# SPDX-License-Identifier: MIT + +import time +from machine import Pin, I2C +from micropython_icm20948 import icm20948 + +i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040 +icm = icm20948.ICM20948(i2c) + +icm.accelerometer_range = icm20948.RANGE_2G + +while True: + for accelerometer_range in icm20948.acc_range_values: + 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() + time.sleep(0.5) + icm.accelerometer_range = accelerometer_range diff --git a/examples/icm20948_clock_select.py b/examples/icm20948_clock_select.py new file mode 100644 index 0000000..1e1b758 --- /dev/null +++ b/examples/icm20948_clock_select.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya +# +# SPDX-License-Identifier: MIT + +import time +from machine import Pin, I2C +from micropython_icm20948 import icm20948 + +i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040 +icm = icm20948.ICM20948(i2c) + +icm.clock_select = icm20948.CLK_SELECT_INTERNAL + +while True: + for clock_select in icm20948.clk_values: + 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() + time.sleep(0.5) + icm.clock_select = clock_select diff --git a/examples/icm20948_gyro_dlpf_cutoff.py b/examples/icm20948_gyro_dlpf_cutoff.py new file mode 100644 index 0000000..7f84635 --- /dev/null +++ b/examples/icm20948_gyro_dlpf_cutoff.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya +# +# SPDX-License-Identifier: MIT + +import time +from machine import Pin, I2C +from micropython_icm20948 import icm20948 + +i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040 +icm = icm20948.ICM20948(i2c) + +icm.gyro_dlpf_cutoff = icm20948.G_FREQ_11_6 + +while True: + for gyro_dlpf_cutoff in icm20948.gyro_filter_values: + print("Current Gyro dlpf cutoff setting: ", icm.gyro_dlpf_cutoff) + for _ in range(10): + gyrox, gyroy, gyroz = icm.gyro + print("x:{:.2f}°/s, y:{:.2f}°/s, z:{:.2f}°/s".format(gyrox, gyroy, gyroz)) + print() + time.sleep(0.5) + icm.gyro_dlpf_cutoff = gyro_dlpf_cutoff diff --git a/examples/icm20948_gyro_full_scale.py b/examples/icm20948_gyro_full_scale.py new file mode 100644 index 0000000..0c8a27a --- /dev/null +++ b/examples/icm20948_gyro_full_scale.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya +# +# SPDX-License-Identifier: MIT + +import time +from machine import Pin, I2C +from micropython_icm20948 import icm20948 + +i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040 +icm = icm20948.ICM20948(i2c) + +icm.gyro_full_scale = icm20948.FS_250_DPS + +while True: + for gyro_full_scale in icm20948.gyro_full_scale_values: + print("Current Gyro full scale setting: ", icm.gyro_full_scale) + for _ in range(10): + gyrox, gyroy, gyroz = icm.gyro + print("x:{:.2f}°/s, y:{:.2f}°/s, z:{:.2f}°/s".format(gyrox, gyroy, gyroz)) + print() + time.sleep(0.5) + icm.gyro_full_scale = gyro_full_scale diff --git a/examples/icm20948_simpletest.py b/examples/icm20948_simpletest.py index 329d448..a9c8422 100644 --- a/examples/icm20948_simpletest.py +++ b/examples/icm20948_simpletest.py @@ -9,5 +9,8 @@ while True: - print("Acceleration : ", icm.acceleration) + 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: {gyrox}°/s, y: {gyroy}°/s, z: {gyroz}°/s") time.sleep(1) diff --git a/examples/icm20948_temperature.py b/examples/icm20948_temperature.py new file mode 100644 index 0000000..a29fa41 --- /dev/null +++ b/examples/icm20948_temperature.py @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya + +import time +from machine import Pin, I2C +from micropython_icm20948 import icm20948 + +i2c = I2C(sda=Pin(8), scl=Pin(9)) # Correct I2C pins for UM FeatherS2 +icm = icm20948.ICM20948(i2c) + + +while True: + print(f"Temperature: {icm.temperature}°C") + print() + time.sleep(1) diff --git a/micropython_icm20948/icm20948.py b/micropython_icm20948/icm20948.py index 36a1acb..d66fa60 100644 --- a/micropython_icm20948/icm20948.py +++ b/micropython_icm20948/icm20948.py @@ -19,7 +19,7 @@ """ -# pylint: disable=too-many-arguments, line-too-long, too-many-instance-attributes +# pylint: disable=line-too-long from time import sleep from micropython import const @@ -52,7 +52,6 @@ CLK_SELECT_INTERNAL = const(0b000) CLK_SELECT_BEST = const(0b001) CLK_SELECT_STOP = const(0b111) -# End clk_values = (CLK_SELECT_INTERNAL, CLK_SELECT_BEST, CLK_SELECT_STOP) # ICM20948 @@ -62,7 +61,6 @@ GYRO_ENABLED = const(0b000) TEMP_ENABLED = const(0b0) TEMP_DISABLED = const(0b1) -# End gyro_en_values = (GYRO_DISABLED, GYRO_ENABLED) acc_en_values = (ACC_DISABLED, ACC_ENABLED) temperature_en_values = (TEMP_DISABLED, TEMP_ENABLED) @@ -72,15 +70,13 @@ USER_BANK_1 = const(1) USER_BANK_2 = const(2) USER_BANK_3 = const(3) -# End user_bank_values = (USER_BANK_0, USER_BANK_1, USER_BANK_2, USER_BANK_3) -# User Bank ICM20948 +# ACC Range ICM20948 RANGE_2G = const(0b00) RANGE_4G = const(0b01) RANGE_8G = const(0b10) RANGE_16G = const(0b11) - acc_range_values = (RANGE_2G, RANGE_4G, RANGE_8G, RANGE_16G) acc_range_sensitivity = (16384, 8192, 4096, 2048) @@ -276,7 +272,7 @@ class ICM20948: _gyro_full_scale = CBits(2, _GYRO_CONFIG_1, 1) _gyro_dplcfg = CBits(3, _GYRO_CONFIG_1, 3) - def __init__(self, i2c, address=_REG_WHOAMI): + def __init__(self, i2c, address=0x69): self._i2c = i2c self._address = address @@ -298,10 +294,11 @@ def __init__(self, i2c, address=_REG_WHOAMI): def clock_select(self): """ CLK_SELECT_INTERNAL: Internal 20 MHz oscillator - CLK_SELECT_BEST: Auto selects the best available clock source – PLL if ready, else use the - Internal oscillator + CLK_SELECT_BEST: Auto selects the best available clock source - PLL if + ready, else use the Internal oscillator CLK_SELECT_STOP: Stops the clock and keeps timing generator in reset - NOTE: CLKSEL should be set to ``CLK_SELECT_BEST`` to achieve full gyroscope performance. + NOTE: CLKSEL should be set to ``CLK_SELECT_BEST`` to achieve full + gyroscope performance. +------------------------------------------+-------------------+ | Mode | Value | @@ -335,7 +332,7 @@ def reset(self) -> int: return self._reset @reset.setter - def reset(self, value=1) -> None: + def reset(self, value: int = 1) -> None: self._reset = value sleep(1) @@ -390,13 +387,13 @@ def temperature_enabled(self) -> str: """ Temperature Enabled. When set to 1, this bit disables the temperature sensor. - +------------------------------------+------------------------------------------------------+ - | Mode | Value | - +====================================+======================================================+ - | :py:const:`icm20948.TEMP_ENABLED` | :py:const:`0b0` Temperature on | - +------------------------------------+------------------------------------------------------+ - | :py:const:`icm20948.TEMP_DISABLED` | :py:const:`0b1` Temperature disabled | - +------------------------------------+------------------------------------------------------+ + +------------------------------------+----------------------------------------+ + | Mode | Value | + +====================================+========================================+ + | :py:const:`icm20948.TEMP_ENABLED` | :py:const:`0b0` Temperature on | + +------------------------------------+----------------------------------------+ + | :py:const:`icm20948.TEMP_DISABLED` | :py:const:`0b1` Temperature disabled | + +------------------------------------+----------------------------------------+ """ values = ("TEMP_DISABLED", "TEMP_ENABLED") @@ -539,8 +536,9 @@ def gyro_full_scale(self, value: int) -> None: @property def temperature(self) -> float: """ - Temperature Value. In the setup tested, there is the need to read either the values from acceleration, - gyro and temperature or gyro and temperature at the same time in order to have a logic temperature value. + Temperature Value. In the setup tested, there is the need to read either the values + from acceleration, gyro and temperature or gyro and temperature at the same time + in order to have a logic temperature value. """ return (self._raw_temp_data[3] / 333.87) + 21 @@ -720,13 +718,38 @@ def acc_dlpf_cutoff(self) -> int: Readings immediately following setting a cutoff frequency will be inaccurate due to the filter "warming up" - """ - + +---------------------------------+-------------------+ + | Mode | Value | + +=================================+===================+ + | :py:const:`icm20948.FREQ_246_0` | :py:const:`0b001` | + +---------------------------------+-------------------+ + | :py:const:`icm20948.FREQ_111_4` | :py:const:`0b010` | + +---------------------------------+-------------------+ + | :py:const:`icm20948.FREQ_50_4` | :py:const:`0b011` | + +---------------------------------+-------------------+ + | :py:const:`icm20948.FREQ_23_9` | :py:const:`0b100` | + +---------------------------------+-------------------+ + | :py:const:`icm20948.FREQ_11_5` | :py:const:`0b101` | + +---------------------------------+-------------------+ + | :py:const:`icm20948.FREQ_5_7` | :py:const:`0b110` | + +---------------------------------+-------------------+ + | :py:const:`icm20948.FREQ_473` | :py:const:`0b111` | + +---------------------------------+-------------------+ + """ + values = ( + "FREQ_246_0", + "FREQ_111_4", + "FREQ_50_4", + "FREQ_23_9", + "FREQ_11_5", + "FREQ_5_7", + "FREQ_473", + ) self._user_bank = 2 sleep(0.005) raw_value = self._acc_dplcfg self._user_bank = 0 - return raw_value + return values[raw_value] @acc_dlpf_cutoff.setter def acc_dlpf_cutoff(self, value: int) -> None: @@ -764,13 +787,41 @@ def gyro_dlpf_cutoff(self) -> int: Readings immediately following setting a cutoff frequency will be inaccurate due to the filter "warming up" - """ - + +-----------------------------------+-------------------+ + | Mode | Value | + +===================================+===================+ + | :py:const:`icm20948.G_FREQ_196_6` | :py:const:`0b000` | + +-----------------------------------+-------------------+ + | :py:const:`icm20948.G_FREQ_151_8` | :py:const:`0b001` | + +-----------------------------------+-------------------+ + | :py:const:`icm20948.G_FREQ_119_5` | :py:const:`0b010` | + +-----------------------------------+-------------------+ + | :py:const:`icm20948.G_FREQ_51_2` | :py:const:`0b011` | + +-----------------------------------+-------------------+ + | :py:const:`icm20948.G_FREQ_23_9` | :py:const:`0b100` | + +-----------------------------------+-------------------+ + | :py:const:`icm20948.G_FREQ_11_6` | :py:const:`0b101` | + +-----------------------------------+-------------------+ + | :py:const:`icm20948.G_FREQ_5_7` | :py:const:`0b110` | + +-----------------------------------+-------------------+ + | :py:const:`icm20948.G_FREQ_361_4` | :py:const:`0b111` | + +-----------------------------------+-------------------+ + """ + values = ( + "G_FREQ_196_6", + "G_FREQ_151_8", + "G_FREQ_119_5", + "G_FREQ_51_2", + "G_FREQ_23_9", + "G_FREQ_11_6", + "G_FREQ_5_7", + "G_FREQ_361_4", + ) self._user_bank = 2 sleep(0.005) raw_value = self._gyro_dplcfg self._user_bank = 0 - return raw_value + return values[raw_value] @gyro_dlpf_cutoff.setter def gyro_dlpf_cutoff(self, value: int) -> None: diff --git a/package.json b/package.json index 039b81f..2d2cbeb 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,17 @@ { "urls": [ - ["micropython_icm20948/icm20948.py", "github:jposada202020/MicroPython_ICM20948/micropython_icm20948/icm20948.py"], - ["micropython_icm20948/i2c_helpers.py", "github:jposada202020/MicroPython_ICM20948/micropython_icm20948/i2c_helpers.py"], - ["micropython_icm20948/__init__.py", "github:jposada202020/MicroPython_ICM20948/micropython_icm20948/__init__.py"] + [ + "micropython_icm20948/icm20948.py", + "github:jposada202020/MicroPython_ICM20948/micropython_icm20948/icm20948.py" + ], + [ + "micropython_icm20948/i2c_helpers.py", + "github:jposada202020/MicroPython_ICM20948/micropython_icm20948/i2c_helpers.py" + ], + [ + "micropython_icm20948/__init__.py", + "github:jposada202020/MicroPython_ICM20948/micropython_icm20948/__init__.py" + ] ], - "version": "0.1" + "version": "1" }