Run BNO055 python sample code with I2C (Raspberry Pi 3B)

Summary

I had a chance to run BNO005 on i2C on Raspberry Pi 3B, and I stumbled, so I will leave it as a memorandum.

The language used is Python. I proceeded with the development environment settings according to here. When I moved the official sample of here, it did not work with I2C as it is.

solution

I changed the following code around line 30.

Befor

# Create and configure the BNO sensor connection.  Make sure only ONE of the
# below 'bno = ...' lines is uncommented:
# Raspberry Pi configuration with serial UART and RST connected to GPIO 18:
bno = BNO055.BNO055(serial_port='/dev/serial0', rst=18)
# BeagleBone Black configuration with default I2C connection (SCL=P9_19, SDA=P9_20),
# and RST connected to pin P9_12:
#bno = BNO055.BNO055(rst='P9_12')

After

# Create and configure the BNO sensor connection.  Make sure only ONE of the
# below 'bno = ...' lines is uncommented:
# Raspberry Pi configuration with serial UART and RST connected to GPIO 18:
bno = BNO055.BNO055(rst=18)
# BeagleBone Black configuration with default I2C connection (SCL=P9_19, SDA=P9_20),
# and RST connected to pin P9_12:
#bno = BNO055.BNO055(rst='P9_12')

What I did was not to specify the communication interface when initializing BNO005. By doing this, I2C settings were automatically made.

I found it by looking at the following part of the BNO005.py library.

if serial_port is not None:
            # Use serial communication if serial_port name is provided.
            # Open the serial port at 115200 baud, 8N1.  Add a 5 second timeout
            # to prevent hanging if device is disconnected.
            self._serial = serial.Serial(serial_port, 115200, timeout=serial_timeout_sec,
                                         writeTimeout=serial_timeout_sec)
        else:
            # Use I2C if no serial port is provided.
            # Assume we're using platform's default I2C bus if none is specified.
            if i2c is None:
                import Adafruit_GPIO.I2C as I2C
                i2c = I2C
            # Save a reference to the I2C device instance for later communication.
            self._i2c_device = i2c.get_i2c_device(address, **kwargs)

in conclusion

Even when using I2C, I wanted you to write it in the explanation of the sample code ...

Recommended Posts

Run BNO055 python sample code with I2C (Raspberry Pi 3B)
GPS tracking with Raspberry Pi 4B + BU-353S4 (Python)
raspberry pi 1 model b, python
Use vl53l0x with Raspberry Pi (python)
getrpimodel: Recognize Raspberry Pi model (A, B, B +, B2, B3, etc) with python
Run servomotor on Raspberry Pi 3 using python
Working with GPS on Raspberry Pi 3 Python
Discord bot with python raspberry pi zero with [Notes]
I tried L-Chika with Raspberry Pi 4 (Python edition)
Get CPU information of Raspberry Pi with Python
Connect to MySQL with Python on Raspberry Pi
Measure CPU temperature of Raspberry Pi with Python
Run Python with VBA
Run prepDE.py with python3
GPGPU with Raspberry Pi
DigitalSignage with Raspberry Pi
Run iperf with python
Specific sample code for working with SQLite3 in Python
Try debugging Python on Raspberry Pi with Visual Studio.
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
USB boot with Raspberry Pi 4 Model B (3) LVM edition
Display USB camera video with Python OpenCV with Raspberry Pi
Let's operate GPIO of Raspberry Pi with Python CGI
Raspberry Pi with Elixir, which is cooler than Python
Run the output code with tkinter, saying "A, pretending to be B" in python
Raspberry Pi 4B initial setting
Get country code with python
Sample data created with python
Python with VS Code (Windows 10)
Mutter plants with Raspberry Pi
Update Python for Raspberry Pi to 3.7 or later with pyenv
Run AWS IoT Device SDK for Python on Raspberry Pi
Run python with PyCharm (Windows)
Let's run jupyter natively supported by VS Code with python3.8
Run Python with CloudFlash (arm926ej-s)
Let's run Excel with Python
Python beginner opens and closes interlocking camera with Raspberry Pi
I tried running Movidius NCS with python of Raspberry Pi3
Create an LCD (16x2) game with Raspberry Pi and Python
Debug Python with VS Code
Raspberry Pi + Python + OpenGL memo
Run Label with tkinter [Python]
SSD 1306 OLED can be used with Raspberry Pi + python (Note)
[Python] Sample code for Python grammar
Run DHT22 with RasPi + Python
Translate I2C device driver for Arduino to Python for Raspberry pi
Document Python code with Doxygen
Send push notifications to iOS apps with Python2 (with sample code)
Connect Raspberry Pi to Alibaba Cloud IoT Platform with Python
Getting Started with Heroku-Viewing Hello World in Python Django with Raspberry PI 3
Control the motor with a motor driver using python on Raspberry Pi 3!
I want to run the Python GUI when starting Raspberry Pi
Programd automatic start at startup with Raspberry Pi 3B + systemd Summary
Get US stock price from Python with Web API with Raspberry Pi
[Note] Using 16x2-digit character LCD (1602A) from Python with Raspberry Pi
Port FreeRTOS to Raspberry Pi 4B
[Raspberry Pi] Stepping motor control with Raspberry Pi
raspberry pi 1 model b, node-red part 17
Servo motor control with Raspberry Pi
Run Rotrics DexArm with python API
Serial communication with Raspberry Pi + PySerial