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"""
98from struct import pack_into
109import 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
0 commit comments