Skip to content

Commit 8a34894

Browse files
authored
Merge pull request #12 from jposada202020/improving_docs
improving docs and varia
2 parents ffefed8 + 5c27ce9 commit 8a34894

11 files changed

+171
-47
lines changed

README.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ For use with the ICM20649:
6262
6363
import time
6464
import board
65-
import busio
6665
import adafruit_icm20x
6766
68-
i2c = busio.I2C(board.SCL, board.SDA)
67+
i2c = board.I2C() # uses board.SCL and board.SDA
6968
icm = adafruit_icm20x.ICM20649(i2c)
7069
7170
while True:
@@ -80,10 +79,9 @@ For use with the ICM20948:
8079
8180
import time
8281
import board
83-
import busio
8482
import adafruit_icm20x
8583
86-
i2c = busio.I2C(board.SCL, board.SDA)
84+
i2c = board.I2C() # uses board.SCL and board.SDA
8785
icm = adafruit_icm20x.ICM20948(i2c)
8886
8987
while True:

adafruit_icm20x.py

Lines changed: 114 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,25 +112,25 @@ def is_valid(cls, value):
112112

113113

114114
class AccelRange(CV):
115-
"""Options for ``accelerometer_range``"""
115+
"""Options for :attr:`ICM20X.accelerometer_range`"""
116116

117117
pass # pylint: disable=unnecessary-pass
118118

119119

120120
class GyroRange(CV):
121-
"""Options for ``gyro_data_range``"""
121+
"""Options for :attr:`ICM20X.gyro_data_range`"""
122122

123123
pass # pylint: disable=unnecessary-pass
124124

125125

126126
class GyroDLPFFreq(CV):
127-
"""Options for ``gyro_dlpf_cutoff``"""
127+
"""Options for :attr:`ICM20X.gyro_dlpf_cutoff`"""
128128

129129
pass # pylint: disable=unnecessary-pass
130130

131131

132132
class AccelDLPFFreq(CV):
133-
"""Options for ``accel_dlpf_cutoff``"""
133+
"""Options for :attr:`ICM20X.accel_dlpf_cutoff`"""
134134

135135
pass # pylint: disable=unnecessary-pass
136136

@@ -140,7 +140,7 @@ class ICM20X: # pylint:disable=too-many-instance-attributes
140140
141141
142142
:param ~busio.I2C i2c_bus: The I2C bus the ICM20X is connected to.
143-
:param address: The I2C slave address of the sensor
143+
:param int address: The I2C address of the device.
144144
145145
"""
146146

@@ -227,7 +227,7 @@ def __init__(self, i2c_bus, address):
227227
self.initialize()
228228

229229
def initialize(self):
230-
"""Configure the sensors with the default settings. For use after calling `reset()`"""
230+
"""Configure the sensors with the default settings. For use after calling :meth:`reset`"""
231231

232232
self._sleep = False
233233
self.accelerometer_range = AccelRange.RANGE_8G # pylint: disable=no-member
@@ -262,7 +262,7 @@ def _sleep(self, sleep_enabled):
262262

263263
@property
264264
def acceleration(self):
265-
"""The x, y, z acceleration values returned in a 3-tuple and are in m / s ^ 2."""
265+
"""The x, y, z acceleration values returned in a 3-tuple and are in :math:`m / s ^ 2.`"""
266266
self._bank = 0
267267
raw_accel_data = self._raw_accel_data
268268
sleep(0.005)
@@ -275,7 +275,8 @@ def acceleration(self):
275275

276276
@property
277277
def gyro(self):
278-
"""The x, y, z angular velocity values returned in a 3-tuple and are in degrees / second"""
278+
"""The x, y, z angular velocity values returned in a 3-tuple and
279+
are in :math:`degrees / second`"""
279280
self._bank = 0
280281
raw_gyro_data = self._raw_gyro_data
281282
x = self._scale_gyro_data(raw_gyro_data[0])
@@ -331,12 +332,19 @@ def gyro_range(self, value):
331332

332333
@property
333334
def accelerometer_data_rate_divisor(self):
334-
"""The divisor for the rate at which accelerometer measurements are taken in Hz
335+
"""
336+
The divisor for the rate at which accelerometer measurements are taken in Hz
337+
338+
.. note::
339+
The data rates are set indirectly by setting a rate divisor according to the
340+
following formula:
341+
342+
.. math::
335343
336-
Note: The data rates are set indirectly by setting a rate divisor according to the
337-
following formula: ``accelerometer_data_rate = 1125/(1+divisor)``
344+
\\text{accelerometer_data_rate} = \\frac{1125}{1 + divisor}
338345
339346
This function sets the raw rate divisor.
347+
340348
"""
341349
self._bank = 2
342350
raw_rate_divisor = self._accel_rate_divisor
@@ -355,10 +363,16 @@ def accelerometer_data_rate_divisor(self, value):
355363

356364
@property
357365
def gyro_data_rate_divisor(self):
358-
"""The divisor for the rate at which gyro measurements are taken in Hz
366+
"""
367+
The divisor for the rate at which gyro measurements are taken in Hz
359368
360-
Note: The data rates are set indirectly by setting a rate divisor according to the
361-
following formula: ``gyro_data_rate = 1100/(1+divisor)``
369+
.. note::
370+
The data rates are set indirectly by setting a rate divisor according to the
371+
following formula:
372+
373+
.. math::
374+
375+
\\text{gyro_data_rate} = \\frac{1100}{1 + divisor}
362376
363377
This function sets the raw rate divisor.
364378
"""
@@ -388,8 +402,14 @@ def _gyro_rate_calc(self, divisor): # pylint:disable=no-self-use
388402
def accelerometer_data_rate(self):
389403
"""The rate at which accelerometer measurements are taken in Hz
390404
391-
Note: The data rates are set indirectly by setting a rate divisor according to the
392-
following formula: ``accelerometer_data_rate = 1125/(1+divisor)``
405+
.. note::
406+
407+
The data rates are set indirectly by setting a rate divisor according to the
408+
following formula:
409+
410+
.. math::
411+
412+
\\text{accelerometer_data_rate} = \\frac{1125}{1 + divisor}
393413
394414
This function does the math to find the divisor from a given rate but it will not be
395415
exactly as specified.
@@ -408,8 +428,14 @@ def accelerometer_data_rate(self, value):
408428
def gyro_data_rate(self):
409429
"""The rate at which gyro measurements are taken in Hz
410430
411-
Note: The data rates are set indirectly by setting a rate divisor according to the
412-
following formula: ``gyro_data_rate = 1100/(1+divisor)``
431+
.. note::
432+
The data rates are set indirectly by setting a rate divisor according to the
433+
following formula:
434+
435+
.. math::
436+
437+
\\text{gyro_data_rate } = \\frac{1100}{1 + divisor}
438+
413439
This function does the math to find the divisor from a given rate but it will not
414440
be exactly as specified.
415441
"""
@@ -429,8 +455,11 @@ def accel_dlpf_cutoff(self):
429455
above the given frequency will be filtered out. Must be an ``AccelDLPFCutoff``.
430456
Use AccelDLPFCutoff.DISABLED to disable the filter
431457
432-
**Note** readings immediately following setting a cutoff frequency will be
433-
inaccurate due to the filter "warming up" """
458+
.. note::
459+
Readings immediately following setting a cutoff frequency will be
460+
inaccurate due to the filter "warming up"
461+
462+
"""
434463
self._bank = 2
435464
return self._accel_dlpf_config
436465

@@ -452,8 +481,11 @@ def gyro_dlpf_cutoff(self):
452481
given frequency will be filtered out. Must be a ``GyroDLPFFreq``. Use
453482
GyroDLPFCutoff.DISABLED to disable the filter
454483
455-
**Note** readings immediately following setting a cutoff frequency will be
456-
inaccurate due to the filter "warming up" """
484+
.. note::
485+
Readings immediately following setting a cutoff frequency will be
486+
inaccurate due to the filter "warming up"
487+
488+
"""
457489
self._bank = 2
458490
return self._gyro_dlpf_config
459491

@@ -484,7 +516,32 @@ class ICM20649(ICM20X):
484516
"""Library for the ST ICM-20649 Wide-Range 6-DoF Accelerometer and Gyro.
485517
486518
:param ~busio.I2C i2c_bus: The I2C bus the ICM20649 is connected to.
487-
:param address: The I2C slave address of the sensor
519+
:param int address: The I2C address of the device. Defaults to :const:`0x68`
520+
521+
**Quickstart: Importing and using the ICM20649 temperature sensor**
522+
523+
Here is an example of using the :class:`ICM2020649` class.
524+
First you will need to import the libraries to use the sensor
525+
526+
.. code-block:: python
527+
528+
import board
529+
import adafruit_icm20x
530+
531+
Once this is done you can define your `board.I2C` object and define your sensor object
532+
533+
.. code-block:: python
534+
535+
i2c = board.I2C() # uses board.SCL and board.SDA
536+
icm = adafruit_icm20x.ICM20649(i2c)
537+
538+
Now you have access to the acceleration using :attr:`acceleration` attribute and
539+
the gyro information using the :attr:`gyro` attribute.
540+
541+
.. code-block:: python
542+
543+
acceleration = icm.acceleration
544+
gyro = icm.gyro
488545
489546
"""
490547

@@ -526,7 +583,7 @@ def __init__(self, i2c_bus, address=_ICM20649_DEFAULT_ADDRESS):
526583

527584

528585
class MagDataRate(CV):
529-
"""Options for ``magnetometer_data_rate``"""
586+
"""Options for :attr:`ICM20948.magnetometer_data_rate`"""
530587

531588
pass # pylint: disable=unnecessary-pass
532589

@@ -535,7 +592,36 @@ class ICM20948(ICM20X): # pylint:disable=too-many-instance-attributes
535592
"""Library for the ST ICM-20948 Wide-Range 6-DoF Accelerometer and Gyro.
536593
537594
:param ~busio.I2C i2c_bus: The I2C bus the ICM20948 is connected to.
538-
:param address: The I2C slave address of the sensor
595+
:param int address: The I2C address of the device. Defaults to :const:`0x69`
596+
597+
**Quickstart: Importing and using the ICM20948 temperature sensor**
598+
599+
Here is an example of using the :class:`ICM20948` class.
600+
First you will need to import the libraries to use the sensor
601+
602+
.. code-block:: python
603+
604+
import board
605+
import adafruit_icm20x
606+
607+
Once this is done you can define your `board.I2C` object and define your sensor object
608+
609+
.. code-block:: python
610+
611+
i2c = board.I2C() # uses board.SCL and board.SDA
612+
icm = adafruit_icm20x.ICM20948(i2c)
613+
614+
Now you have access to the acceleration using :attr:`acceleration` attribute,
615+
the gyro information using the :attr:`gyro` attribute and the magnetic information
616+
using the :attr:`magnetic` attribute
617+
618+
.. code-block:: python
619+
620+
acceleration = icm.acceleration
621+
gyro = icm.gyro
622+
magnetic = icm.magnetic
623+
624+
539625
"""
540626

541627
_slave_finished = ROBit(_ICM20X_I2C_MST_STATUS, 6)
@@ -670,7 +756,7 @@ def magnetic(self):
670756

671757
@property
672758
def magnetometer_data_rate(self):
673-
"""The rate at which the magenetometer takes measurements to update its output registers"""
759+
"""The rate at which the magnetometer takes measurements to update its output registers"""
674760
# read mag DR register
675761
self._read_mag_register(_AK09916_CNTL2)
676762

@@ -707,7 +793,7 @@ def _read_mag_register(self, register_addr, slave_addr=0x0C):
707793
finished = False
708794
for _i in range(100):
709795
finished = self._slave_finished
710-
if finished: # bueno!
796+
if finished: # bueno! :)
711797
break
712798
sleep(0.010)
713799

@@ -737,7 +823,7 @@ def _write_mag_register(self, register_addr, value, slave_addr=0x0C):
737823
finished = False
738824
for _i in range(100):
739825
finished = self._slave_finished
740-
if finished: # bueno!
826+
if finished: # bueno! :)
741827
break
742828
sleep(0.010)
743829

docs/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
77
.. automodule:: adafruit_icm20x
88
:members:
9+
:member-order: bysource

docs/examples.rst

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,53 @@
1-
Simple test
2-
------------
1+
ICM20649 Simple test
2+
--------------------
33

4-
Ensure your device works with one of these simple tests.
4+
Ensure your ICM20649 device works with one of these simple tests.
55

66
.. literalinclude:: ../examples/icm20x_icm20649_simpletest.py
77
:caption: examples/icm20x_icm20649_simpletest.py
88
:linenos:
99

10+
ICM20649 Full test
11+
------------------
12+
13+
Test using all the ICM20649 sensor capabilities
14+
15+
.. literalinclude:: ../examples/icm20x_icm20649_full_test.py
16+
:caption: examples/examples/icm20x_icm20649_full_test.py
17+
:linenos:
18+
19+
ICM20948 Simple test
20+
--------------------
21+
22+
Ensure your ICM20948 device works with one of these simple tests.
23+
1024
.. literalinclude:: ../examples/icm20x_icm20948_simpletest.py
1125
:caption: examples/icm20x_icm20948_simpletest.py
1226
:linenos:
27+
28+
ICM20948 Acceleration data rate test
29+
------------------------------------
30+
31+
Example showing ICM20948 sensor cycling between two acceleration data rates
32+
33+
.. literalinclude:: ../examples/icm20x_icm20948_accel_data_rate_test.py
34+
:caption: examples/icm20x_icm20948_accel_data_rate_test.py
35+
:linenos:
36+
37+
ICM20948 Gyro data rate test
38+
----------------------------
39+
40+
Example showing ICM20948 sensor cycling between two gyro data rates
41+
42+
.. literalinclude:: ../examples/icm20x_icm20948_gyro_data_rate_test.py
43+
:caption: examples/icm20x_icm20948_gyro_data_rate_test.py
44+
:linenos:
45+
46+
ICM20948 Magnetic data rate test
47+
--------------------------------
48+
49+
Example showing ICM20948 sensor cycling between two magnetic data rates
50+
51+
.. literalinclude:: ../examples/icm20x_icm20948_mag_data_rate_test.py
52+
:caption: examples/icm20x_icm20948_mag_data_rate_test.py
53+
:linenos:

docs/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26+
Adafruit's ICM20649 Learning Guide <https://learn.adafruit.com/adafruit-icm20649-wide-range-6-dof-imu-accelerometer-and-gyro>
27+
Adafruit's ICM20948 Learning Guide <https://learn.adafruit.com/adafruit-tdk-invensense-icm-20948-9-dof-imu>
28+
2629
.. toctree::
2730
:caption: Related Products
2831

2932
Adafruit's ICM20649 Breakout <https://adafruit.com/product/4464>
33+
Adafruit's ICM20948 Breakout <https://www.adafruit.com/product/4554>
3034

3135

3236
.. toctree::

examples/icm20x_icm20649_full_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import time
55
import board
6-
import busio
76
from adafruit_icm20x import ICM20649, AccelRange, GyroRange
87

98

@@ -15,7 +14,7 @@ def printNewMax(value, current_max, axis):
1514

1615

1716
# pylint:disable=no-member
18-
i2c = busio.I2C(board.SCL, board.SDA)
17+
i2c = board.I2C() # uses board.SCL and board.SDA
1918

2019
ism = ICM20649(i2c)
2120

0 commit comments

Comments
 (0)