Install MPU9250 on Nvidia Nano and Raspberry Pi for Python3.

Spread the love


Update your Operating System

sudo apt-get update && sudo apt-get dist-upgrade -y

Cleanup your unwanted files.

sudo apt autoremove

Connect the MPU9250 to the Nano/Pi.

Enable the i2c in setup.

If you are using a Raspberry Pi, you will need to enable the i2c interface in the Raspi config setup.

sudo raspi-config

Go to ‘5. Interfacing Options’ and enable ‘i2c’, then ‘P5 I2C – Enable/Disable automatic loading of I2C kernel module’.

Find i2c devices

Use the following command to detect your i2c devices. They may be on board 0 or 1 depending on your setup.

sudo i2cdetect -y -r 0
sudo i2cdetect -y -r 1

Download the Packages

Make sure you have pip3 installled.

sudo apt-get install python3-pip

Now clone the github site and install smbus2.

sudo git clone

pip3 install smbus2

Depending on your system, try pip install first, if it fails try pip3.

pip install FaBo9Axis_MPU9250
pip3 install FaBo9Axis_MPU9250

If it has installed, you should be able to find the file in ‘site-packages’

find -name MPU*

If is installed under python3.x, you have installed the software correctly.

Run the example code.

When the git was cloned, it should have created a folder called ‘ FaBo9Axis_MPU9250 ‘. There is an example in the example folder.

If you do not have the file, you can download it from the github link below.

cd FaBo9Axis_MPU9250
cd example


Depending on your setup, you may get different errors when you run the example python code.

Print error.

If you get the following error, you will need to edit the file in the site packages folder. The file location is listed in the error message.

You should be able to edit the file in your editor and save it. If it won’t allow you to save it due to permissions, use nano to edit the file.

sudo nano

To fix the print error, you will need to change the print syntax from python2 to python3. The correct code is shown below. I have added opening and closing brackets.

Smbus error

If you get the smbus error, you will need to change the file in site-packages to point to smbus2 instead of smbus.

Change from smbus to smbus2.

Run the example.

cd FaBo9Axis_MPU9250
cd example

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.