Bosch BNO055 Python Library


I am using the Bosch BNO055 connected to ESP-WROOM-32 board, to collect data from this sensor. However there are some missings in python library for BNO055 that are limiting my progress, which are the linear acceleration and the calibration status.
For linear acceleration, I’ve included it in the library and it’s working. However, the “get_calibration_status” function, I’ve tried include it, but I can not get it to work.
Can anyone help me?
The code I’ve included in library were:

For Linear Acceleration:

def get_linear_acceleration(self):
        “”“Return the current linear acceleration (acceleration from movement,
        not from gravity) reading as a tuple of X, Y, Z values in meters/second^2.
        x, y, z = self._read_vector(BNO055_LINEAR_ACCEL_DATA_X_LSB_ADDR)
        return (x/100.0, y/100.0, z/100.0)

For Status Calibration:
def get_calibration_status(self):
        # Return the calibration status register value.
        cal_status = self._read_byte(BNO055_CALIB_STAT_ADDR)
        sys = (cal_status >> 6) & 0x03
        gyro = (cal_status >> 4) & 0x03
        accel = (cal_status >> 2) & 0x03
        mag = cal_status & 0x03
        # Return the results as a tuple of all 3 values.
        return (sys, gyro, accel, mag)



Hello @“Marco Branco”

thanks for your additions to the library!

The code of get_calibration_status seems right, the issue is probably that you are not putting the BNO055 in config mode as stated in the datasheet (pag 49):

The calibration profile includes sensor offsets and sensor radius. Host system can read the offsets and radius only after a full calibration is achieved and the operation mode is switched to CONFIG_MODE. Refer to sensor offsets and sensor radius registers.

Let me know if this solves your issue;

Feel free to fork and add a pull request for your changes!

Hi @Giacomo
I tried but without success. The calibration status don't work, and my inexperience does not help me.
I don't know what fails. Can you help me?
Thank you


Hello @“Marco Branco” ,

Can you please post the modified get_calibration_status and the output you get from that function?


Hello @Giacomo,
My first step was to include the Config mode in the BNO055 library as suggested before:

_modes = {

Then added the function in the BNO055 library:
    def get_calibration_status(self):
        “”“Read the calibration status of the sensors and return a 4 tuple with
        calibration status as follows:
          - System, 3=fully calibrated, 0=not calibrated
          - Gyroscope, 3=fully calibrated, 0=not calibrated
          - Accelerometer, 3=fully calibrated, 0=not calibrated
          - Magnetometer, 3=fully calibrated, 0=not calibrated
        # Return the calibration status register value.
        cal_status = self._read_byte(BNO055_CALIB_STAT_ADDR)
        sys = (cal_status >> 6) & 0x03
        gyro = (cal_status >> 4) & 0x03
        accel = (cal_status >> 2) & 0x03
        mag = cal_status & 0x03
        # Return the results as a tuple of all 3 values.
        return (sys, gyro, accel, mag)

My script is:

import streams
import socket
from bosch.bno055 import bno055

# init serial
# Setup BNO055 sensor 
bno = bno055.BNO055(I2C0)
print(‘Initiating BNO055…’)

# Enabled IMU

sys, gyro, accel, mag = bno.get_calibration_status()
print(sys, gyro, accel, mag)

The output that I can see is:

Initiating BNO055…


Hello @“Marco Branco” ,

can you try to put your main loop inside a try/except block just to be sure that now exception is raised?

import ...<br><br>streams.serial()<br><br>try:<br>&nbsp;&nbsp;&nbsp; <your main code here><br>except Exception as e:<br>&nbsp;&nbsp;&nbsp; print(e)<br>

Hello @Giacomo

This is what happens:

Initiating BNO055...
IndexError @[0053:0042:0000:004B:0000:0000:0000:0000]

which is associated to  "AttributeError  at line 28 of __main__"

If I'm not wrong this means that the error is at line 28 of the

my line 28 is:

    sys, gyro, accel, mag = bno.get_calibration_status()

but what this means? what can I do?


Hello @“Marco Branco” ,

can you share with us your project code or send it to me in a private message? I’'ll give a look at it to check what’s going on.


Hi @Giacomo,

I’ve already share it in a comment above, on feb 26, where I refer



Ok. Sorry I thought you had some more files in the project.

I will let you know soon.


Hi Marco,

the AttributeError you get is related to the fact that inside your code (function get_calibration_status()) you call non-existing methods in our Zerynth lib (self._config_mode() and self.read_byte() ?? ).

I just commit all new features you need in the official Zerynth Repository for Bosch-BNO055 library; you have to replace the under the path “your_home/zerynth2/dist/r2.1.0/libs/official/bosch/bno055/” or wait for the release of the next patch that will be available soon.

Let me know if this can help you :slight_smile:


Hi @Giacomo
There was some problems, but I think I’ve found and solve them.
The first one was in line 255 of BNO055 library, where is “self.write_byte” I place "self.write_bytes"
The second one was in line 290 because the config mode was not in “modes”. For that I just add
“config”: OPERATION_MODE_CONFIG, in line 195.
and so far is working.
Thanks a lot.


New updates are available on the official Zerynth Github repository.

Happy coding :slight_smile:


Thanks @“Matteo Cipriani”


After the update to version 2.1, working with bno055 is being very unstable.

This is the error that appears at this moment with my script:

TimeoutError  at line 22 of main
raised at line 251 of bosch.bno055.bno055.init
raised at line 104 of i2c.write_bytes
raised at line 118 of i2c.write

With the Get Acceleration Example script, appear this error:

TimeoutError  at line 21 of main
raised at line 291 of bosch.bno055.bno055.init
raised at line 104 of i2c.write_bytes
raised at line 118 of i2c.write

How can I solve it?


Hi Marco,

this is a known new bug related to I2C Clock Stretching on ESP32 devices; we’re already working on it.
In the meantime you can try to set a very low clock frequency (example 10kHz) and test if it works so you can continue to develop your application.

Let me know if this can help you :slight_smile:


Hi Matteo,
How can I set a low clock frequency?


Hi Marco,
as reported in the library doc, just add the clk argument when creating the bno object:

bno = bno055.BNO055(I2C0, clk=10000)


Hi @anba
Thanks for the tip.
Now I can work with the BNO055, however when I try to connect to TCP-IP have this error.

IOError at line 57 of main
raised at line 145 of socket.connect

Please consider that my 57th line is:
sock.connect((‘192.168.XXX.XXX’, 5005)) # the XXXs are other numbers.
and it is already connected to the wireless.

What is the reason for that?


Hi Marco,

From your line, the syntax seems correct; anyway, if you provide to me your main I can better understand your issue and try to replicate it for fixing.

Furthermore, I think you want to create a raw socket and connected to a local machine that exposed a web server on the (IP : PORT) address that you inserted as the tuple in the connect argument.

To do that the machine that exposes this server and the device must be connected to the same net; you can test this (IP : PORT) address with another machine to see if it is reachable or not because it seems an error due to an unreachable address.

Let me know