Skip to content

Commit d96dc95

Browse files
authored
Merge pull request #23 from jposada202020/improving_docs
improving_docs
2 parents 0303c9a + c7cbbe3 commit d96dc95

File tree

11 files changed

+230
-41
lines changed

11 files changed

+230
-41
lines changed

README.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,15 @@ Usage Example
6262
.. code-block:: python3
6363
6464
import board
65-
import busio
66-
from adafruit_bno08x.i2c import BNO08X_I2C
67-
from adafruit_bno08x import BNO_REPORT_ACCELEROMETER
65+
import adafruit_bno08x
6866
69-
i2c = busio.I2C(board.SCL, board.SDA)
70-
bno = BNO08X_I2C(i2c)
71-
bno.enable_feature(BNO_REPORT_ACCELEROMETER)
67+
i2c = board.I2C() # uses board.SCL and board.SDA
68+
bno = adafruit_bno08x.BNO08X(i2c)
7269
7370
while True:
74-
accel_x, accel_y, accel_z = bno.acceleration # pylint:disable=no-member
75-
print("X: %0.6f Y: %0.6f Z: %0.6f m/s^2" % (accel_x, accel_y, accel_z))
71+
quat = bno.rotation_vector
72+
print("Rotation Vector Quaternion:")
73+
print("I: %0.3f J: %0.3f K: %0.3f Accuracy: %0.3f"%(quat.i, quat.j, quat.k, quat.accuracy))
7674
7775
Contributing
7876
============

adafruit_bno08x/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# SPDX-License-Identifier: MIT
55
"""
66
`adafruit_bno08x`
7-
================================================================================
7+
=================
88
99
Helper library for the Hillcrest Laboratories BNO08x IMUs
1010
@@ -16,14 +16,17 @@
1616
1717
**Hardware:**
1818
19-
* `Adafruit BNO08x Breakout <https:www.adafruit.com/products/4754>`_
19+
* `Adafruit 9-DOF Orientation IMU Fusion Breakout
20+
<https://www.adafruit.com/products/4754>`_ (Product ID: 4566)
2021
2122
**Software and Dependencies:**
2223
2324
* Adafruit CircuitPython firmware for the supported boards:
24-
https:# github.com/adafruit/circuitpython/releases
25+
https://circuitpython.org/downloads
26+
27+
* Adafruit's Bus Device library:
28+
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
2529
26-
* `Adafruit's Bus Device library <https:# github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_
2730
"""
2831
__version__ = "0.0.0-auto.0"
2932
__repo__ = "https:# github.com/adafruit/Adafruit_CircuitPython_BNO08x.git"
@@ -483,7 +486,11 @@ def is_error(cls, header):
483486
class BNO08X: # pylint: disable=too-many-instance-attributes, too-many-public-methods
484487
"""Library for the BNO08x IMUs from Hillcrest Laboratories
485488
486-
:param ~busio.I2C i2c_bus: The I2C bus the BNO08x is connected to.
489+
This sensor is able to communicate over I2C, SPI, or UART:
490+
491+
* I2C: :class:`adafruit_bno08x.i2c.BNO08X_I2C`
492+
* SPI: :class:`adafruit_bno08x.spi.BNO08X_SPI`
493+
* UART: :class:`adafruit_bno08x.uart.BNO08X_UART`
487494
488495
"""
489496

adafruit_bno08x/i2c.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
#
33
# SPDX-License-Identifier: MIT
44
"""
5-
6-
Subclass of `adafruit_bno08x.BNO08X` to use I2C
7-
5+
Subclass of `adafruit_bno08x.BNO08X` to use I2C
6+
===============================================
87
"""
98
from struct import pack_into
109
import adafruit_bus_device.i2c_device as i2c_device
@@ -17,6 +16,48 @@ class BNO08X_I2C(BNO08X):
1716
"""Library for the BNO08x IMUs from Hillcrest Laboratories
1817
1918
:param ~busio.I2C i2c_bus: The I2C bus the BNO08x is connected to.
19+
:param ~digitalio.DigitalInOut reset: Optional for I2C use. Connected to the RST pin;
20+
used to hard-reset the device.
21+
:param int address: The I2C device address. Defaults to :const:`0x4A`
22+
:param bool debug: Enables print statements used for debugging. Defaults to `False`
23+
24+
25+
**Quickstart: Importing and using the device**
26+
27+
Here is an example of using the :class:`BNO08X_I2C` class.
28+
First you will need to import the libraries to use the sensor
29+
30+
.. code-block:: python
31+
32+
import board
33+
from adafruit_bno08x.i2c import BNO08X_I2C
34+
35+
Once this is done you can define your `board.I2C` object and define your sensor object
36+
37+
.. code-block:: python
38+
39+
# The sensor can communicate over I2C at 400kHz if you need the higher speed.
40+
i2c = board.I2C() # uses board.SCL and board.SDA
41+
bno = BNO08X_I2C(i2c)
42+
43+
For this particular you need to define some things to get some data.
44+
45+
.. code-block:: python
46+
47+
bno.enable_feature(adafruit_bno08x.BNO_REPORT_ACCELEROMETER)
48+
bno.enable_feature(adafruit_bno08x.BNO_REPORT_GYROSCOPE)
49+
bno.enable_feature(adafruit_bno08x.BNO_REPORT_MAGNETOMETER)
50+
bno.enable_feature(adafruit_bno08x.BNO_REPORT_ROTATION_VECTOR)
51+
52+
Now you have access to the :attr:`acceleration`, :attr:`gyro`
53+
:attr:`magnetic` and :attr:`quaternion` attributes
54+
55+
.. code-block:: python
56+
57+
accel_x, accel_y, accel_z = bno.acceleration
58+
gyro_x, gyro_y, gyro_z = bno.gyro
59+
mag_x, mag_y, mag_z = bno.magnetic
60+
quat_i, quat_j, quat_k, quat_real = bno.quaternion
2061
2162
"""
2263

@@ -59,7 +100,6 @@ def _read_packet(self):
59100
with self.bus_device_obj as i2c:
60101
i2c.readinto(self._data_buffer, end=4) # this is expecting a header?
61102
self._dbg("")
62-
# print("SHTP READ packet header: ", [hex(x) for x in self._data_buffer[0:4]])
63103

64104
header = Packet.header_from_buffer(self._data_buffer)
65105
packet_byte_count = header.packet_byte_count
@@ -117,5 +157,4 @@ def _data_ready(self):
117157
else:
118158
ready = header.data_length > 0
119159

120-
# self._dbg("\tdata ready", ready)
121160
return ready

adafruit_bno08x/spi.py

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
#
33
# SPDX-License-Identifier: MIT
44
"""
5-
6-
Subclass of `adafruit_bno08x.BNO08X` to use SPI
7-
5+
Subclass of `adafruit_bno08x.BNO08X` to use SPI
6+
================================================
87
"""
98
import time
109
from struct import pack_into
@@ -15,20 +14,55 @@
1514

1615

1716
class BNO08X_SPI(BNO08X):
18-
"""Instantiate a `adafruit_bno08x.BNO08X_SPI` instance to communicate with
17+
"""
18+
Instantiate a `adafruit_bno08x.spi.BNO08X_SPI` instance to communicate with
1919
the sensor using SPI
2020
21-
Args:
22-
spi_bus ([busio.SPI]): The SPI bus to use to communicate with the BNO08x
23-
cs_pin ([digitalio.DigitalInOut]): The pin object to use for the SPI Chip Select
24-
debug (bool, optional): Enables print statements used for debugging. Defaults to False.
25-
"""
21+
:param ~busio.SPI spi_bus: The SPI bus to use to communicate with the BNO08x
22+
:param ~digitalio.DigitalInOut cspin: The pin object to use for the SPI Chip Select
23+
:param ~digitalio.DigitalInOut intpin: The pin object to interrupt
24+
:param ~digitalio.DigitalInOut resetpin: Required for SPI mode. Connected to the
25+
RST pin on the device, and used to hard-reset the device.
26+
:param int baudrate: baudrate of the SPI bus. Defaults to :const:`1000000`
27+
:param bool debug: Enables print statements used for debugging. Defaults to `False`
28+
29+
**Quickstart: Importing and using the device**
30+
31+
Here is an example of using the :class:`BNO08X_SPI` class.
32+
First you will need to import the libraries to use the sensor
33+
34+
.. code-block:: python
35+
36+
import board
37+
from adafruit_bno08x.spi import BNO08X_SPI
2638
27-
# """Library for the BNO08x IMUs from Hillcrest Laboratories
39+
Once this is done you can define your `board.SPI` object and define your sensor object
2840
29-
# :param ~busio.SPI spi_bus: The SPI bus the BNO08x is connected to.
41+
.. code-block:: python
3042
31-
# """
43+
spi = board.SPI()
44+
bno = BNO08X_SPI(spi)
45+
46+
For this particular you need to define some things to get some data.
47+
48+
.. code-block:: python
49+
50+
bno.enable_feature(adafruit_bno08x.BNO_REPORT_ACCELEROMETER)
51+
bno.enable_feature(adafruit_bno08x.BNO_REPORT_GYROSCOPE)
52+
bno.enable_feature(adafruit_bno08x.BNO_REPORT_MAGNETOMETER)
53+
bno.enable_feature(adafruit_bno08x.BNO_REPORT_ROTATION_VECTOR)
54+
55+
Now you have access to the :attr:`acceleration`, :attr:`gyro`
56+
:attr:`magnetic` and :attr:`quaternion` attributes
57+
58+
.. code-block:: python
59+
60+
accel_x, accel_y, accel_z = bno.acceleration
61+
gyro_x, gyro_y, gyro_z = bno.gyro
62+
mag_x, mag_y, mag_z = bno.magnetic
63+
quat_i, quat_j, quat_k, quat_real = bno.quaternion
64+
65+
"""
3266

3367
def __init__(
3468
self, spi_bus, cspin, intpin, resetpin, baudrate=1000000, debug=False

adafruit_bno08x/uart.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
#
33
# SPDX-License-Identifier: MIT
44
"""
5-
6-
Subclass of `adafruit_bno08x.BNO08X` to use UART
7-
5+
Subclass of `adafruit_bno08x.BNO08X` to use UART
6+
================================================
87
"""
98
import time
109
from struct import pack_into
@@ -21,7 +20,48 @@
2120
class BNO08X_UART(BNO08X):
2221
"""Library for the BNO08x IMUs from Hillcrest Laboratories
2322
24-
:param uart: The UART devce the BNO08x is connected to.
23+
:param uart: The UART device the BNO08x is connected to.
24+
:param ~digitalio.DigitalInOut reset: The pin object to reset
25+
:param bool debug: Enables print statements used for debugging. Defaults to `False`
26+
27+
28+
**Quickstart: Importing and using the device**
29+
30+
Here is an example of using the :class:`BNO08X_UART` class.
31+
First you will need to import the libraries to use the sensor
32+
33+
.. code-block:: python
34+
35+
import board
36+
import busio
37+
from adafruit_bno08x.uart import BNO08X_UART
38+
39+
Once this is done you can define your `busio.UART` object and define your sensor object
40+
41+
.. code-block:: python
42+
43+
uart = busio.UART(board.TX, board.RX, baudrate=3000000, receiver_buffer_size=2048)
44+
bno = BNO08X_UART(uart)
45+
46+
For this particular you need to define some things to get some data.
47+
48+
.. code-block:: python
49+
50+
bno.enable_feature(adafruit_bno08x.BNO_REPORT_ACCELEROMETER)
51+
bno.enable_feature(adafruit_bno08x.BNO_REPORT_GYROSCOPE)
52+
bno.enable_feature(adafruit_bno08x.BNO_REPORT_MAGNETOMETER)
53+
bno.enable_feature(adafruit_bno08x.BNO_REPORT_ROTATION_VECTOR)
54+
55+
56+
Now you have access to the :attr:`acceleration`, :attr:`gyro`
57+
:attr:`magnetic` and :attr:`quaternion` attributes
58+
59+
.. code-block:: python
60+
61+
accel_x, accel_y, accel_z = bno.acceleration
62+
gyro_x, gyro_y, gyro_z = bno.gyro
63+
mag_x, mag_y, mag_z = bno.magnetic
64+
quat_i, quat_j, quat_k, quat_real = bno.quaternion
2565
2666
"""
2767

docs/api.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@
66
77
.. automodule:: adafruit_bno08x
88
:members:
9+
:exclude-members: PacketError
10+
11+
.. automodule:: adafruit_bno08x.i2c
12+
:members:
13+
14+
.. automodule:: adafruit_bno08x.spi
15+
:members:
16+
17+
.. automodule:: adafruit_bno08x.uart
18+
:members:

docs/examples.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,63 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/bno08x_simpletest.py
77
:caption: examples/bno08x_simpletest.py
88
:linenos:
9+
10+
11+
Simple test SPI
12+
---------------
13+
14+
This is the simple test using the SPI bus
15+
16+
.. literalinclude:: ../examples/bno08x_simpletest_spi.py
17+
:caption: examples/bno08x_simpletest_spi.py
18+
:linenos:
19+
20+
21+
Simple test UART
22+
----------------
23+
24+
This is the simple test using the UART bus
25+
26+
.. literalinclude:: ../examples/bno08x_simpletest_uart.py
27+
:caption: examples/bno08x_simpletest_uart.py
28+
:linenos:
29+
30+
31+
Quaternion Service
32+
------------------
33+
34+
Example showing the quaternion service
35+
36+
.. literalinclude:: ../examples/bno08x_quaternion_service.py
37+
:caption: examples/bno08x_quaternion_service.py
38+
:linenos:
39+
40+
41+
Reports Example
42+
---------------
43+
44+
Example showing how to produce reports
45+
46+
.. literalinclude:: ../examples/bno08x_more_reports.py
47+
:caption: examples/bno08x_more_reports.py
48+
:linenos:
49+
50+
51+
Finding heading example
52+
-----------------------
53+
54+
This illustrate how to find the heading
55+
56+
.. literalinclude:: ../examples/bno08x_more_reports.py
57+
:caption: examples/bno08x_more_reports.py
58+
:linenos:
59+
60+
61+
Calibration Example
62+
-------------------
63+
64+
How to calibrate the device
65+
66+
.. literalinclude:: ../examples/bno08x_calibration.py
67+
:caption: examples/bno08x_calibration.py
68+
:linenos:

docs/index.rst

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

26+
Adafruit 9-DOF Orientation IMU Fusion Breakout - BNO085 Learning Guide <https://learn.adafruit.com/adafruit-9-dof-orientation-imu-fusion-breakout-bno085/>
27+
28+
2629
.. toctree::
2730
:caption: Related Products
2831

29-
* `Adafruit BNO08x Breakout <https:www.adafruit.com/products/4754>`_
32+
Adafruit 9-DOF Orientation IMU Fusion Breakout - BNO085 <https://www.adafruit.com/products/4754>
3033

3134

3235
.. toctree::

examples/bno08x_calibration.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
# SPDX-License-Identifier: Unlicense
44
import time
55
import board
6-
import busio
76
from digitalio import DigitalInOut
87
import adafruit_bno08x
98
from adafruit_bno08x.i2c import BNO08X_I2C
109

11-
i2c = busio.I2C(board.SCL, board.SDA)
10+
i2c = board.I2C() # uses board.SCL and board.SDA
1211
reset_pin = DigitalInOut(board.D5)
1312
bno = BNO08X_I2C(i2c, reset=reset_pin, debug=False)
1413

examples/bno08x_quaternion_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from adafruit_ble_adafruit.quaternion_service import QuaternionService
99
from adafruit_bno08x import BNO08X
1010

11-
i2c = board.I2C()
11+
i2c = board.I2C() # uses board.SCL and board.SDA
1212
bno = BNO08X(i2c)
1313

1414
quat_svc = QuaternionService()

0 commit comments

Comments
 (0)