(1) I have installed micropython-mpu9250.
(2) I have detected the i2c bus using "i2cdetect -y 1".
How come my program don't run?
(1) What does the command "i2cdetect ..." do?
The commend "i2cdetect -y 1" is used to detect if there is any working I2C devices connected to the bus, and display the devices' address as two hexadecimal digits.
For example, if you have a device MPU9250 with address "0x68". So i2cdetect -y 1 should display at the "60" (7th row) row two digits "68".
If you have installed a driver for the device MPU9250, for example, by using the text editor "nano" editing the file /boot/config.txt by adding a line like this:
then i2cdetect might display "UU" instead of "68".
And even i2cdect detects the device, it does not mean the device should work correctly. It only means i2cdetect "pings" (say hello to) the device, and the device replies "I am here". In other words, MPU9250 only says he is present, not guaranteeing that he is OK to work.
(2) Importing micropython python modules
First you need to import the correct python modules. Below are the example statements from the microPython MPU9250 I2C Driver Git HubGitHub:
from machine import I2C, Pin, Timer
from mpu9250 import MPU9250
Note that the example is not using the Rpi default I2C pins GPIO 2, 3 (40 pin header physical pin numbers 3, 5). This implies the usual import command "import smbus" won't work. You must first import "micropython", then from "machine import I2C ...".
(3) Setting up an I2C bus and give it a name, eg "i2c123"
Then you need to setup the i2c bus, and give it a name, say "Nile", like the following example in gitHub:
i2cBusNile = I2C(scl = Pin(22), sda = Pin(21))
Here, I2C is the class which can create/instantiate objects, and "i2cBustNile" is the bus object.
(4) Creating an object (instance) of the micropython class for device
Now the time has come for the class "MCU9250" to "give birth" a new mpu9050 "baby" object，and give him a name, eg "mpu9250BabyJonathan"：
mpu925BabyJonathan = MPU9250(i2cBusNile)
Now you can "teach" baby MPU9250 Jonathan to do something!
(5) Other possible I2C programming problems
I have been using Rpi3B+ stretch playing with I2C 3/6/9 DOF sensors and found a big
program, ie, for Rpi3B+, I2C speed is a flat rate of 100kHz and cannot be changed (though "official" instructions says otherwise!). Furthermore, the python I2C (smbus) module does not entertain "bus stretching" which is required in some cases.
A get around is to lower I2C speed, but not for Rpi3B+.
To solve the problem, you need to use Rpi4B buster, which allows lower I2C speed to as low as 10kHz, and problem solved. See Reference 4 below for more details.
(6) MPU9250 Make Easy For Newbies
There is not that many tutorials for 9-DOF MPU9250. For newbies I would recommend to try 6-DOF MPU6500, or even 3-DOF sensors. MPU9250 actually has MPU6500 and another 3-DOF magneto sensor glued together inside (Ref 3, Appendix A (the pink and orange rectangles of MPU9250 block diagram)). So the knowledge and skills acquired in MPU6500 can directly transfer to MPU9250.
In other words, eat the big 9-DOF elephant bite by bite, in three 3-DOF bites. This way, the very steep MPU9250 learning curve becomes three shallow ones.
(1) MicroPython MPU-9250 (MPU-6500 + AK8963) I2C driver GitHub
(2) MPU9250 Datasheet - Invensense
(3) MPU9250/MPU6250 Newbie Advice - tlfong01 2018nov
(4) Rpi4B buster BNO055 9-DOF Sensor and 16 Channel PWM Driver CircuitPython Programming Problem - tlfong01 2019jun
(5) MPU9250 Learning Notes - tlfong01 2019mar
Appendix A - MPU9250 Block Diagram
Appendix B - MPU9250 Module Schematic
Appendix C - MicroPython PyBoard and AdaFruit Circuit Python Modules
I started learning microPython in 2015, using PyBoard V1.0, then BBC MicroBit. I found micropython's REPL (Read-Evaluate-Print-Loop) and Mu Editor (also available in Rpi4B GUI Desktop) very slow, so I switched to Rpi IDLE python 3.5.3 and now Thonny 3.7.3 which I found good. For absolute newbies, I would recommend AdaFruit CircuitPython Modules. (You can install microPython application in Rpi, but again there are many version incompatibility problems. :()
End of answer