Install MPU9250 on Nvidia Nano and Raspberry Pi for Python3.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

References

https://www.element14.com/community/community/designcenter/single-board-computers/blog/2019/05/21/nvidia-jetson-nano-developer-kit-pinout-and-diagrams

https://learn.sparkfun.com/tutorials/mpu-9250-hookup-guide?_ga=2.158523837.624189382.1581760252-1143399707.1581760252

https://github.com/FaBoPlatform/FaBo9AXIS-MPU9250-Python

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 https://github.com/FaBoPlatform/FaBo9AXIS-MPU9250-Python.git

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 MPU9250.py file in ‘site-packages’

cd
find -name MPU*

If MPU9250.py 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 read9axis.py file, you can download it from the github link below.

https://github.com/FaBoPlatform/FaBo9AXIS-MPU9250-Python

cd
cd FaBo9Axis_MPU9250
cd example
python3 read9axis.py

Errors.

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 MPU9250.py 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 MPU9250.py

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 MPU9250.py file in site-packages to point to smbus2 instead of smbus.

Change from smbus to smbus2.

Run the example.

cd
cd FaBo9Axis_MPU9250
cd example
python3 read9axis.py

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.