GithubHelp home page GithubHelp logo

adafruit / adafruit_circuitpython_bno055 Goto Github PK

View Code? Open in Web Editor NEW
86.0 24.0 52.0 3.02 MB

CircuitPython driver for BNO055 absolute orientation sensor

License: MIT License

Python 100.00%
circuitpython hacktoberfest

adafruit_circuitpython_bno055's Introduction

Introduction

Documentation Status Discord Build Status Code Style: Black

Dependencies

This driver depends on the Register and Bus Device libraries. Please ensure they are also available on the CircuitPython filesystem. This is easily achieved by downloading a library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-bno055

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-bno055

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-bno055

Usage Notes

Of course, you must import the library to use it:

import adafruit_bno055

This driver takes an instantiated and active I2C object as an argument to its constructor. The way to create an I2C object depends on the board you are using. For boards with labeled SCL and SDA pins, you can:

import board

i2c = board.I2C()

Once you have the I2C object, you can create the sensor object:

sensor = adafruit_bno055.BNO055_I2C(i2c)

And then you can start reading the measurements:

print(sensor.temperature)
print(sensor.euler)
print(sensor.gravity)

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_bno055's People

Contributors

brennen avatar caternuson avatar cedargrovestudios avatar davidskeck avatar deshipu avatar dhalbert avatar evaherrada avatar foamyguy avatar gamblor21 avatar guenterq avatar jposada202020 avatar katlings avatar kattni avatar ladyada avatar markus-k avatar mrmcwethy avatar peterhinch avatar pjjefferies avatar russmac avatar siddacious avatar sommersoft avatar tannewt avatar tcfranks avatar tdicola avatar tekktrik avatar viennamike avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_bno055's Issues

Library too large for smaller boards

Adafruit CircuitPython 6.0.0-rc.1 on 2020-11-03; Adafruit QT Py M0 with samd21e18
>>> import adafruit_bno055
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_bno055.py", line 111, in <module>
MemoryError: memory allocation failed, allocating 776 bytes
>>> 

Calibration not working, data spikes, and incorrect orientation

Hello,
I am running the latest version of Adafruit_CircuitPython_BNO055 installed from pip3 on a raspberry pi 3b+ and it seems that the board is not calibrating. Additionally, there are frequently large random spikes in the data and the quaternion is not a valid quaternion to describe orientation (not a unit quaternion). The data is so bad that the imu is not usable. Is there a fix to these issues?
Thank you for your help!

sensor.euler, quaternion, linear_acceleration, gravity returns None in a unpredictable way

Hi, I am using a RasPi 4 to communicate with https://www.adafruit.com/product/2472 via I2C. I am following instructions on https://learn.adafruit.com/adafruit-bno055-absolute-orientation-sensor/python-circuitpython. I am running the simpletest.py.

While the sensor.acceleration, magnetic and gyro gives me data just fine, sensor.euler, quaternion, linear_acceleration, gravity is behaving unpredictably. In each loop, sometimes they have value and sometimes they only return None. I tried adjusting the pause time between each while loop as 0.01, 0.05, 0.1 and 1. However, this didn't make a difference on the result I get.

euler, quaternion, linear_acceleration, gravity, seems to behave independently (for example it can happen where euler has value while the other three returns None)

Also, sensor temperature also is behaving similarly. Sometimes it returns ~25, which is makes sense, while the rest of the time it returns around ~ -104 (sometimes ~105 or -100)

I also tried on another product (I bought two), and it gave me the same result.

I further tested the M4G mode. Theoretically, I shouldn't get any data from sensor.gyro, but in some loop I get values in other loop I only get None. In M4G mode sensor.euler, quaternion, linear_acceleration, gravity always give me None and the temperature alternates between 29 and -99.

Thank you for your help!

Reading time too long

Hello!

I have a quick question regarding the time it takes to read the values of the sensor.
Here is a modified version of one of the simple examples which are provided:


import time
from adafruit_extended_bus import ExtendedI2C as I2C
import adafruit_bno055

i2c = I2C(8)
sensor = adafruit_bno055.BNO055_I2C(i2c)

sensor._reset()    
time.sleep(0.5)
sensor.accel_bandwidth = 0x1C
time.sleep(0.5)
sensor.mode = 7 

while True:
    t = time.time()    
    print("Accelerometer (m/s^2): {}".format(sensor.acceleration))
    t2 = time.time()
    print("took {} ms".format((t2-t)*1000))
    print("")

And here the output I get:


Accelerometer (m/s^2): (0.0, 1.28, 9.6)
took 4.441738128662109 ms

Accelerometer (m/s^2): (-0.02, 1.24, 9.64)
took 4.462003707885742 ms

Accelerometer (m/s^2): (-0.06, 1.31, 9.61)
took 3.902912139892578 ms

If I understand that correctly, it means that is takes about 4-5ms to read the values of the accelerometer. And it takes the same amount of time to read the gyro and magnet values as well, so that in practice we can only have values of the sensors once every 10-15 ms.

Is there a way to use the python library and improve those reading times that prevent using high frequencies for the accelerometer/gyroscope?

Thanks in advance for the help!
Aurélien

[PLEASE HELP] RuntimeError: UART read error: 7

Hello,

I'm trying to use BNO055 with my RPi 4B (Bullseye OS) in UART mode. I've followed all the steps outlined on the Python & CircuitPython page and enabled UART on the RPi but I keep getting the UART write error 7 when I run the bno055_simpletest.py from the examples. The program runs correctly for a second or two but then crashes.

Image of error message:
bno055_error

Setup of RPi and BNO055:
RPi_Wiring
BNO055_Wiring

Is there any way to solve this issue?
Thank you in advance!

I2C switching using address pin fails.

I can't seem to enable and disable multiple the IMUs connected to the same bus. It either connects to one and only reads from that one regardless of trying to switch via the address pins.

mode setter appears wrong

I'm writing a MicroPython driver for your board. In my testing it is only possible to change the device mode if you first change the mode to _CONFIG_MODE. Unfortunately I don't have any hardware capable of running CircuitPython but I think the following test will fail:

import adafruit_bno055
from busio import I2C
from board import SDA, SCL

i2c = I2C(SCL, SDA)
imu = adafruit_bno055.BNO055(i2c)
print(imu.euler)  # Check it's working
imu.mode = 5
print(imu.mode)  # I think this will be unchanged

The need to set _CONFIG_MODE prior to setting any other mode is contradicted in the chip datasheet (section 3.3.1). Consequently before I submit a PR I would be grateful if someone could perform the above test to confirm my findings.

For reference this is my mode setting code. This includes delays mandated by the device datasheet.

    def mode(self, new_mode=None):
        old_mode = self._read(_MODE_REGISTER)
        if new_mode is not None:
            self._write(_MODE_REGISTER, _CONFIG_MODE)  # This is empirically necessary if the mode is to be changed
            time.sleep_ms(20)  # Datasheet table 3.6
            if new_mode != _CONFIG_MODE:
                self._write(_MODE_REGISTER, new_mode)
                time.sleep_ms(10)  # Table 3.6
        return old_mode

Euler angles give a random -0.065 value

I have two imu's connected to the same i2c bus. One of them gives a random -0.065 for the pitch reading when the other is connected but works perfectly fine once the other is removed. Lowering the clock speed to 5kHz seems to decrease how often I get the random values when both are connected.

Initialisation fails due to reset in __init__.

While executing bno055_simpletest.py, the initialisation of the BNO055 always fails with the
following error:

Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
  File "/lib/adafruit_bno055.py", line 671, in __init__
  File "/lib/adafruit_bno055.py", line 185, in __init__
  File "/lib/adafruit_bno055.py", line 677, in _write_register
  File "/lib/adafruit_bno055.py", line 677, in _write_register
  File "adafruit_bus_device/i2c_device.py", line 102, in write
OSError: [Errno 5] Input/output error

The error occurs in the first I2C write after the reset in BNO055.__init__.

I'm currently porting an Arduino-based application to CircuitPython. On Arduino, the same BNO works fine with the
corresponding Adafruit library. I made some comparisons of the two libraries and noticed that the Arduino library
doesn't reset the BNO. So I removed the self._reset() line in and now the bno055_simpletest.py works fine.

I'm not experienced enough with CircuitPython yet to see what's causing this behaviour.

bno055 fails to init with esp32-s3

Can not get the bno055 library to init and not fail on a Unexpected Maker Feather-S3.
On first run it fails with the traceback below. However any subsequent tries, soft reboots, or pushed code changes without a hard reset and it fails with "RuntimeError: No pull up found on SDA or SCL; check your wiring". So after it fails the first time the entire i2c bus stops working until a hard reset is performed.

Traceback (most recent call last):
File "code.py", line 9, in
File "adafruit_bno055.py", line 777, in init
File "adafruit_bno055.py", line 212, in init
File "adafruit_bno055.py", line 788, in _read_register
File "adafruit_bus_device/i2c_device.py", line 140, in write_then_readinto
OSError: [Errno 116] ETIMEDOUT

Board used: https://circuitpython.org/board/unexpectedmaker_feather3/
I2c device used: https://www.adafruit.com/product/2472
Circuitpython version: Tested on 7.2.0-rc.0, 7.2.0, 7.2.4, 7.3.0-beta.0

When just doing a simple I2c device scan, theres no issue in seeing the device.
Scanning I2C bus
0x28
1 device(s) found on I2C bus

Other I2c devices also work fine. I was able to test a pressure sensor using adafruit_dps310, on the same I2c bus without issue.

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_bno055.py:142
  • adafruit_bno055.py:146
  • adafruit_bno055.py:150
  • adafruit_bno055.py:155
  • adafruit_bno055.py:160
  • adafruit_bno055.py:164
  • adafruit_bno055.py:172
  • adafruit_bno055.py:347
  • adafruit_bno055.py:381
  • adafruit_bno055.py:500
  • adafruit_bno055.py:518
  • adafruit_bno055.py:538
  • adafruit_bno055.py:558
  • adafruit_bno055.py:578
  • adafruit_bno055.py:598
  • adafruit_bno055.py:618
  • adafruit_bno055.py:638
  • adafruit_bno055.py:658
  • adafruit_bno055.py:667
  • adafruit_bno055.py:670
  • adafruit_bno055.py:706
  • adafruit_bno055.py:766
  • adafruit_bno055.py:771
  • adafruit_bno055.py:777
  • adafruit_bno055.py:789
  • adafruit_bno055.py:794
  • adafruit_bno055.py:807
  • adafruit_bno055.py:871
  • adafruit_bno055.py:882
  • adafruit_bno055.py:893
  • adafruit_bno055.py:904
  • adafruit_bno055.py:915

[Question] Can I use this package on Jetson Xavier NX module?

Hi~

I had some problem using this library on Jetson Xavier NX Board

Test Code

import busio
import board
import adafruit_bno055


sensor = adafruit_bno055.BNO055_I2C(busio.I2C(board.SCL_1, board.SDA_1)) 

Error

Traceback (most recent call last):
  File "board_test.py", line 48, in <module>
    import adafruit_bno055
  File "/home/javier/.local/lib/python3.6/site-packages/adafruit_bno055.py", line 35, in <module>
    from adafruit_bus_device.i2c_device import I2CDevice
  File "/home/javier/.local/lib/python3.6/site-packages/adafruit_bus_device/i2c_device.py", line 25, in <module>
    class I2CDevice:
  File "/home/javier/.local/lib/python3.6/site-packages/adafruit_bus_device/i2c_device.py", line 55, in I2CDevice
    def __init__(self, i2c: I2C, device_address: int, probe: bool = True) -> None:
NameError: name 'I2C' is not defined
Exiting... 
Cleaning up pins

How to do calibration?

Hi,

Does the device need calibration? If so, how can this be done? The online tutorial only mentions device calibration for the use with Arduino.

Thanks!

Raspberry Pi erroneous data

Thanks for the library. I've use the bno055_i2c-gpio_simpletest.py in the example folder to read sensor data from a bno055 connected directly to a Raspberry pi 4. I've tried bus 0 for the i2c connection, but I'm still getting erroneous data. much of the data is filled with "None" values and the temperature will usually read below -100 C.

Is there a specific bus that I should be using? I know that the clock stretching issue is a challenge, but I hoped that this example file had circumvented that issue. I have followed the /boot/config.txt instructions in the sample code comments. Thanks again for any advice.

Output below:

Temperature: -102 degrees C
Accelerometer (m/s^2): (-0.31, -0.3, 9.42)
Magnetometer (microteslas): (-23.5, -30.0625, -16.875)
Gyroscope (rad/sec): (0.002181661564992912, 0.003272492347489368, 0.002181661564992912)
Euler angle: (None, None, None)
Quaternion: (0.0, 0.0, 0.0, 0.0)
Linear acceleration (m/s^2): (0.0, 0.0, 0.0)
Gravity (m/s^2): (None, None, None)

Temperature: -102 degrees C
Accelerometer (m/s^2): (-0.27, -0.3, 9.43)
Magnetometer (microteslas): (-22.0625, -28.25, -14.875)
Gyroscope (rad/sec): (0.001090830782496456, 0.001090830782496456, 0.004363323129985824)
Euler angle: (0.0, -1.75, 1.8125)
Quaternion: (None, None, None, None)
Linear acceleration (m/s^2): (None, None, None)
Gravity (m/s^2): (None, None, None)

Temperature: -102 degrees C
Accelerometer (m/s^2): (-0.27, -0.3, 9.450000000000001)
Magnetometer (microteslas): (-22.0625, -29.0, -15.25)
Gyroscope (rad/sec): (0.002181661564992912, -0.004363323129985824, -0.001090830782496456)
Euler angle: (None, None, None)
Quaternion: (None, None, None, None)
Linear acceleration (m/s^2): (None, None, None)
Gravity (m/s^2): (None, None, None)

Temperature: -102 degrees C
Accelerometer (m/s^2): (-0.27, -0.29, 9.44)
Magnetometer (microteslas): (-22.75, -27.875, -14.875)
Gyroscope (rad/sec): (0.001090830782496456, 0.002181661564992912, 0.002181661564992912)
Euler angle: (None, None, None)
Quaternion: (None, None, None, None)
Linear acceleration (m/s^2): (0.02, 0.0, -0.34)
Gravity (m/s^2): (-0.3, -0.31, 9.790000000000001)

Temperature: 27 degrees C
Accelerometer (m/s^2): (-0.26, -0.3, 9.42)
Magnetometer (microteslas): (-22.375, -27.875, -14.0625)
Gyroscope (rad/sec): (-0.001090830782496456, 0.0, 0.0)
Euler angle: (0.0, -1.75, 1.8125)
Quaternion: (None, None, None, None)
Linear acceleration (m/s^2): (None, None, None)
Gravity (m/s^2): (None, None, None)

Temperature: -101 degrees C
Accelerometer (m/s^2): (-0.27, -0.32, 9.42)
Magnetometer (microteslas): (-22.375, -27.5625, -15.25)
Gyroscope (rad/sec): (-0.001090830782496456, -0.001090830782496456, 0.0)
Euler angle: (None, None, None)
Quaternion: (None, None, None, None)
Linear acceleration (m/s^2): (None, None, None)
Gravity (m/s^2): (-0.3, -0.31, 9.790000000000001)

BNO055 instance fail unless with frequency arg. BNO055 polling unstable, fails invariably

Hello,
I am posting this after seeing a similar issue on the CCS811 here:
adafruit/Adafruit_CircuitPython_CCS811#9

I am experiencing exactly the same problems, with write fail like this:
File "adafruit_bus_device/i2c_device.py", line 102, in write
Example:

Traceback (most recent call last):
File "", line 1, in
File "ccs811_example.py", line 10, in
File "adafruit_ccs811.py", line 113, in init
File "adafruit_register/i2c_bit.py", line 40, in get
File "adafruit_register/i2c_bit.py", line 39, in get
File "adafruit_bus_device/i2c_device.py", line 102, in write
OSError: [Errno 5] EIO

I tried creating both busio and bitbangio instances with frequency set to 10000. This works:

i2c_bus = bitbangio.I2C(board.SCL, board.SDA, frequency=10000) # was 10000

But always after some time interval, there is a write error, like this:

Accelerometer (m/s^2): (162.55, -123.85, -30.97)
Magnetometer (microteslas): (2036.0, -0.0625, -0.0625)
Traceback (most recent call last):
File "main.py", line 73, in
File "adafruit_bno055.py", line 76, in get
File "adafruit_register/i2c_struct.py", line 58, in get
File "adafruit_register/i2c_struct.py", line 57, in get
File "adafruit_bus_device/i2c_device.py", line 102, in write
OSError: [Errno 19] ENODEV

I tried different frequencies and different delay times between polling intervals, to no avail.

Is there a way to stabilize the behavior of the sensor and the library?

Thank you!

Iannis Zannos

adafruit_bno055.py is failing pylint

See Actions run

************* Module adafruit_bno055
adafruit_bno055.py:137:8: R1725: Consider using Python 3 style super() without arguments (super-with-arguments)
adafruit_bno055.py:141:17: R1725: Consider using Python 3 style super() without arguments (super-with-arguments)

Here are the 2 methods that are failing:
Method 1

136    def __init__(self, register_address, struct_format, scale):
137        super(_ScaledReadOnlyStruct, self).__init__(register_address, struct_format)
138        self.scale = scale

Method 2

140    def __get__(self, obj, objtype=None):
141        result = super(_ScaledReadOnlyStruct, self).__get__(obj, objtype)
142        return tuple(self.scale * v for v in result)

Should I remove the arguments and then try getting it to work that way or should I just add a pylint disable?

Feature Request: Implement Axis Remap in CircuitPython version

The pre-CircuitPython version allowed one to read and write to the Axis Remap registers (see Section 3.4 of the datasheet). This seems very useful as the orientation of the board may vary depending upon usage.

I have a need for this in my current project and I'm willing to implement it, but I don't really understand the I2C read and write functions in the code and why they differ from the UART ones (which I do mostly understand). I've got the read working for UART by adding register constants up top in the code and adding this in the UART class:
'''
@Property
def axis_remap(self):
# Get the axis remap register value.
map_config = self._read_register(_AXIS_MAP_CONFIG_REGISTER)
z = (map_config >> 4) & 0x03
y = (map_config >> 2) & 0x03
x = map_config & 0x03
# Get the axis remap sign register value.
sign_config = self._read_register(_AXIS_MAP_SIGN_REGISTER)
x_sign = (sign_config >> 2) & 0x01
y_sign = (sign_config >> 1) & 0x01
z_sign = sign_config & 0x01
# Return the results as a tuple of all 3 values.
return (x, y, z, x_sign, y_sign, z_sign)
'''
Update on Saturday 4/3: I've got the setter function now working as well and have tested it with both the I2C and UART interface. I can probably put in a pull request next week. Anything I need to know about doing that?

IMUPLUS_MODE and M4G_MODE not properly supported.

Per the documentation for the BNO055 (section 3.3.3) there are absolute and non-absolute (relative) fusion modes. All 5 of these provide meaningful Euler angle and quaternion outputs, but the code in adafrit_bno055.py does not include IMUPLUS or M4G modes in the mode list to return values and instead always return None's.

Fix needed:
In the code:

@property
def euler(self):
    """Gives the calculated orientation angles, in degrees.
    Returns an empty tuple of length 3 when this property has been disabled by the current mode.
    """
    if self.mode in [0x09, 0x0B, 0x0C]:
        return self._euler
    return (None, None, None)

the values 0x08 and 0x0A need to be added to the list.
The same two values need to be added to the list in:

@property
def quaternion(self):
    """Gives the calculated orientation as a quaternion.
    Returns an empty tuple of length 3 when this property has been disabled by the current mode.
    """
    if self.mode in [0x09, 0x0B, 0x0C, 0x08, 0x0A]:
        return self._quaternion
    return (None, None, None, None)

Re-using calibration data

As a newcomer to this great sensor and python, I am getting good data using bno055_simpletest.py. It would be very useful if we had the option to save the self-calibration data for re-use at start-up, where repeated calibration is unecessary or causes delays. My searches on the internet indicate that other BNO055 users have the same issue, but have I have not found any workable paython code.

Update gyroscope to match design guide

This #33 made me check the Design Guide on sensor properties and units.

gyroscope should be gyro and the units should be radians per second.

This could be shimmed in like acceleration and magnetic appear to have been. So added in, not replaced:

    gyroscope = _ScaledReadOnlyStruct(0x14, '<hhh', 1/16)
    """Gives the raw gyroscope reading in degrees per second."""
    gyro = _ScaledReadOnlyStruct(0x14, '<hhh', 1/16) * 0.017453292519943295
    """Gives the raw gyroscope reading in radians per second."""

or just bury it all in the scale:

    gyro = _ScaledReadOnlyStruct(0x14, '<hhh', 0.001090830782496456)
    """Gives the raw gyroscope reading in radians per second."""

or be all fancy and use math.pi:

    gyro = _ScaledReadOnlyStruct(0x14, '<hhh', math.pi / 2880)
    """Gives the raw gyroscope reading in radians per second."""

The other approach would be to actually change the units via UNIT_SEL, but that would require more code changes.

mode command: docs vs. implementation

For the mode method, the docstring, and hence the API, read as if the user passes a text string to set a new mode. However, these text strings are defined at the top of the module, outside of the class, and use the circuit python const feature. One can work around it by looking up the mode vs. hex value and passing either an integer or hex, but that doesn't seem like the right solution. The most user-friendly mechanism would seem to be to support passing the text strings that correspond to the mode name. At a minimum, the docstring should be changed to show the mode name to hex mapping.

Segmentation Fault

Hi

We are experiencing sometimes a segmentation fault when trying to run the example code of the BNO055 unit, is there a fix for this? We got our BNO055 to run, but after some time it stopped working and we are receiving the Segmentation Fault message, tried to debug it externally by running python inside a debugger without results.

adafruit_bno055.py throws exception (error 19) on register write during initialization

Environment: Metro M0 Express, CircuitPython 2.0 rc2 "latest" build as of last night's release.
Output:
Traceback (most recent call last):
File "code.py", line 71, in
File "/lib/adafruit_bno055.py", line 111, in init
File "/lib/adafruit_bno055.py", line 176, in init
File "/lib/adafruit_bno055.py", line 117, in _write_register
File "/lib/adafruit_bno055.py", line 117, in _write_register
File "libraries/helpers/bus_device/adafruit_bus_device/i2c_device.py", line 94, in write
OSError: 19

(If this actually belongs in the bundled library issues, close it and let me know and I'll open an issue there. Thanks! -Phil)

-92 degrees celsius randomly returned from imu's temperature field

While graphing this data, it was noticed that there were arbitrary dips to a negative value in the range of -92 degrees Celsius. Upon writing a simple test script, it was noticed that the library is indeed returning these large negative temperature values.

Sample Script:

!/bin/python

import board
import busio
import adafruit_bno055
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_bno055.BNO055_I2C(i2c)

for i in range(1000):
    print('Temperature: {} degrees C'.format(sensor.temperature))
    print('Accelerometer: (m/s^2): {}'.format(sensor.acceleration))
    print('Magnetometer (microteslas): {}'.format(sensor.magnetic))
    print('Gyroscope (deg/sec): {}'.format(sensor.gyro))
    print('Euler angle: {}'.format(sensor.euler))
    print('Quaternion: {}'.format(sensor.quaternion))
    print('Linear acceleration (m/s^2): {}'.format(sensor.linear_acceleration))
    print('Gravity (m/s^2): {}'.format(sensor.gravity))

The output was redirected to a file like so:
python3 imu_test.py > read_imu.txt
Then ran grep for Temperature values:
cat read_imu.txt | grep Temperature
The output shows that temperature arbitrarily drops to -92/-93 degrees:

Temperature: 35 degrees C
Temperature: 35 degrees C
Temperature: 35 degrees C
Temperature: 35 degrees C
Temperature: 35 degrees C
Temperature: 35 degrees C
Temperature: 35 degrees C
Temperature: 35 degrees C
Temperature: -93 degrees C
Temperature: 35 degrees C
Temperature: 35 degrees C
Temperature: 35 degrees C
Temperature: 35 degrees C
Temperature: 35 degrees C
Temperature: -93 degrees C
Temperature: 35 degrees C
Temperature: 35 degrees C

WebGL Example - Incorrect rotation on screen

The motion of the 3D model in the WebGL example does not reflect the motion of the BNO055 sensor. Specifically, with the sensor on a flat surface with the VIN to RST pin holes facing away, a change in pitch of the sensor (which accurately changes the values next to "Pitch =") causes the model to roll. A change in roll causes the model to yaw. And a change in yaw causes the model to pitch.

The system shows a complete calibration. Because the Euler output seems correct, I am guessing that there is some issue with the order of the quaternions in the code, but I have not been successful with identifying the exact issue.

I have tested this with two sensors, using both a direct soldered connection and a QWIIC connector.

Any guidance would be greatly appreciated!

How do I use the BNO055 COMPASS_MODE to determine compass heading?

I saw that there is a compass mode for the BNO055 in the https://circuitpython.readthedocs.io/_/downloads/bno055/en/5.1.0/pdf/ documentation. Furthermore, I would love to know how to turn on that mode so that I can use the magnetometer to determine the compass heading direction. For example, print("Heading: " + str(180+math.tan2(sensor.magnetic[1], sensor.magnetic[0])*180/math.pi). Currently, I am using that to determine the heading but it fluctuate a lot and it's not consistent. Thanks in advance.

update guide

heya @dherrada @siddacious @kattni if there is a breaking library change please also check the guide to update it!
this is is a good one to train @dherrada on :)

UART mode only allows for 10Hz data reads

If I modify the lib manually and decrease the sleep from 0.1 to 0.01 in the UART mode, I can read the data at 100Hz just fine.

Is there a reason these sleep values are so high and throttling the data?

Not Running Properly (server.py and setup.py)

I am running python 2.7.16 and I am using an installation that to my knowledge, was working. Upon trying to run server.py (or any of the simpletests), I am given the error message below (with the corresponding line number 2 for the simpletests):
Traceback (most recent call last):
File "server.py", line 34, in
import board
ImportError: No module named board

I figured that there was just something wrong with the installation, so I proceeded to try to run the install with setup.py and I was greeted with this long traceback error. I have no idea what's causing it. I just did a fresh install of python and was greeted with the same errors. Any help would be appreciated.

debian@beaglebone:~/Adafruit_CircuitPython_BNO055$ sudo python setup.py
/tmp/easy_install-_gKWbh/setuptools_scm-6.0.1/src
<pkg_resources.WorkingSet object at 0xb5e3cef0>
Traceback (most recent call last):
File "setup.py", line 56, in
py_modules=["adafruit_bno055"],
File "/usr/lib/python2.7/dist-packages/setuptools/init.py", line 144, in s etup
_install_setup_requires(attrs)
File "/usr/lib/python2.7/dist-packages/setuptools/init.py", line 139, in _ install_setup_requires
dist.fetch_build_eggs(dist.setup_requires)
File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 724, in fetch _build_eggs
replace_conflicting=True,
File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 782, i n resolve
replace_conflicting=replace_conflicting
File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 1065, in best_match
return self.obtain(req, installer)
File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 1077, in obtain
return installer(requirement)
File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 791, in fetch _build_egg
return cmd.easy_install(req)
File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li ne 704, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li ne 730, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li ne 915, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li ne 1183, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li ne 1169, in run_setup
run_setup(setup_script, args)
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 253, in ru n_setup
raise
File "/usr/lib/python2.7/contextlib.py", line 35, in exit
self.gen.throw(type, value, traceback)
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 195, in se tup_context
yield
File "/usr/lib/python2.7/contextlib.py", line 35, in exit
self.gen.throw(type, value, traceback)
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 166, in sa ve_modules
saved_exc.resume()
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 141, in re sume
six.reraise(type, exc, self._tb)
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 154, in sa ve_modules
yield saved
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 195, in se tup_context
yield
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 250, in ru n_setup
_execfile(setup_script, ns)
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 45, in _ex ecfile
exec(code, globals, locals)
File "/tmp/easy_install-_gKWbh/setuptools_scm-6.0.1/setup.py", line 52, in
keywords="adafruit 9-dof absolute orientation accelerometer velocity tempera ture gravity"
File "/tmp/easy_install-_gKWbh/setuptools_scm-6.0.1/setup.py", line 29, in scm _config
url="https://github.com/adafruit/Adafruit_CircuitPython_BNO055",
File "/tmp/easy_install-_gKWbh/setuptools_scm-6.0.1/src/setuptools_scm/_init _.py", line 8, in
File "/tmp/easy_install-_gKWbh/setuptools_scm-6.0.1/src/setuptools_scm/config. py", line 6, in
File "/tmp/easy_install-_gKWbh/setuptools_scm-6.0.1/src/setuptools_scm/utils.p y", line 41
print(*k)

The reset method seems inconsistent

The BNO055 class reset method is user-accesible

def reset(self):
"""Resets the sensor to default settings."""
self.mode = CONFIG_MODE
try:
self._write_register(_TRIGGER_REGISTER, 0x20)
except OSError: # error due to the chip resetting
pass
# wait for the chip to reset (650 ms typ.)
time.sleep(0.7)

If a user calls this method, my reading of the datasheet is that the behaviour of the chip is equivalent to a power-on or a pulse on the reset line. It therefore seems inconsistent that the constructor, after calling reset(), issues
self._write_register(_POWER_REGISTER, _POWER_NORMAL)
self._write_register(_PAGE_REGISTER, 0x00)
self._write_register(_TRIGGER_REGISTER, 0x00)
time.sleep(0.01)
self.mode = NDOF_MODE
time.sleep(0.01)

Either these lines are redundant or they should be included in the reset method. Alternatively user access could be discouraged by renaming it _reset.

How to use euler as a compass heading

Currently the euler acts like a heading when it's turned on facing north. I wonder how I could make it so the sensor.euler[0] acts like a compass heading when not facing north originally when the IMU turned on. Thank you in advance.

Reading too many bits from OPR_MODE register for determing the operation mode

Hello friends,

According to Page 56 of the BNO055 datasheet (Rev. 1.7, November 2020), only bit0 - bit3 of OPR_MODE register represent the operation mode of the sensor.

However, in file adafruit_bno055.py, line 302, all of the eight bits are returned as the operation mode, which leads to strange behaviors as reported in #67. There, some physical values such as euler, quaternion etc. are shown as None, because a wrongly translated operation mode is out of range.

Suggestion:
return ( self._read_register(_MODE_REGISTER) & 0b00001111 )

Best Regards
GuenterQ

RuntimeError: bad chip id (1 != a0) on ESP8266

Not sure if this is related to #2 or not. The traces look different, so maybe bitbangio is playing into it? It's failing before it even gets to the reset part.

Adafruit CircuitPython 2.2.4 on 2018-03-07; ESP module with ESP8266
>>> import board
>>> import busio
>>> import adafruit_bno055
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> sensor = adafruit_bno055.BNO055(i2c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_bno055.py", line 125, in __init__
RuntimeError: bad chip id (1 != a0)
>>> 

esp8266_bno055

sensor.gyroscope RPS not DPS

The old Python BNO055 library has an issue where the gyroscope method returns RPS not DPS as defined in the documentation.

The UNIT_SEL address hasn't been set to degrees and there's no conversion to degrees in either the new or old library.

I'm still using all the old Python libraries as I use boards that don't support Circuit-Python currently. It's a shame they've been archived as I got stuck on this issue for days.

Thanks,

Sam.

Implement calibration reads

The Arduino library allows for reading the calibration registers to know when the BNO055 is oriented. We should too.

Micropython requirement

Hello, it seems that Micropython is required, but I don´t know how to installed, since it seems that it is not available on pip anymore, or I can´t find it:

Traceback (most recent call last):
File "python3gyrotests.py", line 4, in
from elements.ada_bno055 import *
File "/home/pi/turrydronetestspython3/elements/ada_bno055.py", line 37, in
from micropython import const

Best regards.

How to get output in LSB for Python application?

Currently, the Python library gives an output for accelerations and g-components as floats with two-digit accuracy. Is it possible to get actual output in LSB to convert to m/s2 using range and with better accuracy?

Access to read / write calibration offsets

There are two "calibration" related registers:

  • Status - read only, via the CALIB_STAT register at 0x35
  • Offsets - read and write, via the 22 registers 0x55 - 0x6A

Access to the status related one was implemented in #15 as a fix for #11. That issue was perhaps intended to address the offsets, but might have been confused for simply the status.

Access to the offset related ones are still not implemented. For ref, here the related funcs from the older library:
https://github.com/adafruit/Adafruit_Python_BNO055/blob/master/Adafruit_BNO055/BNO055.py#L527
https://github.com/adafruit/Adafruit_Python_BNO055/blob/master/Adafruit_BNO055/BNO055.py#L542

BNO055 reset yields a bad chip id runtime error

I'm creating a system that's supposed to utilize the ability of the BNO055 sensor to know the angle for rotation.

However, for the system to be continuous and long lasting, I need to implement a reset function where it resets the current reading of the BNO055 back to zero.

So, I created this function inside the python file under BNO055_I2C class, and around line 778 to implement the reset.

def _resetBNO055(self):
       super()._init__()

The system did work as it has the ability to reset the sensor reading back to 0. However, after a short while let's say for a few minutes, it shows this error. Did I miss to put something inside the reset function? Or did the delays of getting signals messed up.

Traceback (most recent call last):
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/pi/Downloads/Multiprocess Copy/launcher.py", line 73, in runRover
    rover.rotate()
  File "/home/pi/Downloads/Multiprocess Copy/rover.py", line 109, in rotate
    self.stop()
  File "/home/pi/Downloads/Multiprocess Copy/rover.py", line 129, in stop
    self.headingSensor._resetBNO055()
  File "/home/pi/.local/lib/python3.9/site-packages/adafruit_bno055.py", line 781, in _resetBNO055
    super().__init__()
  File "/home/pi/.local/lib/python3.9/site-packages/adafruit_bno055.py", line 214, in __init__
    raise RuntimeError("bad chip id (%x != %x)" % (chip_id, _CHIP_ID))
RuntimeError: bad chip id (d0 != a0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.