How to Run FaBo9Axis_MPU9250 on Raspberry Pi with Python3

Environment

  • Raspberry Pi 3B+
  • Raspbian GNU/Linux 9.4
  • Python 3
  • Stratux AHRS Sensor (MPU9250 + BMP280)

Setup I2C

$ raspi-config
$ sudo apt install i2c-tools
$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- 0c -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- 76 --

Install smbus2 and FaBo9Axis_MPU9250

$ pip install smbus2
$ pip install FaBo9Axis_MPU9250
$ pip show FaBo9Axis_MPU9250
Name: FaBo9Axis-MPU9250
Version: 1.0.0
Summary: This is a library for the FaBo 9AXIS I2C Brick.
Home-page: https://github.com/FaBoPlatform/FaBo9AXIS-MPU9250-Python/
Author: FaBo
Author-email: info@fabo.io
License: Apache License 2.0
Location: /home/pi/env/lib/python3.5/site-packages
Requires: 
Required-by: 

Edit MPU9250.py

Use smbus2 instead of smbus. And comment out all of print lines.

$ vim /home/pi/env/lib/python3.5/site-packages/FaBo9Axis_MPU9250/MPU9250.py
...
# import smbus
import smbus2 as smbus
...
# print "ax...
...

Run

$ vim scan.py
import FaBo9Axis_MPU9250
import time

mpu9250 = FaBo9Axis_MPU9250.MPU9250()

while True:
  accel = mpu9250.readAccel()
  print("accel X: " + str(accel['x']))
  time.sleep(0.1)
$ python scan.py
accel X: 0.571
accel X: 0.571
accel X: 0.573
accel X: 0.574
accel X: 0.573

Reference