I am interfacing IMU10DOF sensor ( Mpu9250 at addr 0x68 and BMP280 at addr 0x77) with STM32F4 disc board.
I referred this module: https://github.com/micropython-IMU/micropython-mpu9x50
For using MPU9250 we need to create instance of I2C, which i created below.
from pyb import I2C
from mpu9250 import MPU9250
x = I2C(1,I2C.MASTER)
Now to use MPU9250, I need to pass the above created I2C instance .
Code: Select all
from pyb import I2C
from mpu9250 import MPU9250
import micropython
micropython.alloc_emergency_exception_buf(100)
# Note: with a magnetometer read in the callback, a frequency of 1KHz hogged the CPU
tim = pyb.Timer(4, freq=20) # freq in Hz
[b]x = I2C(1,I2C.MASTER)
imu = MPU9250(x)
[/b]
def cb(timer): # Callback: populate array members
imu.get_gyro_irq()
imu.get_accel_irq()
imu.get_mag_irq()
# print(imu.accel.ixyz)
tim.callback(cb)
#print("waiting one second")
print("You should see slightly different values on each pair of readings.")
print(" Accelerometer Gyro Magnetometer")
#pyb.delay(1)
for count in range(10):
pyb.delay(400) # Ensure an interrupt occurs to re-populate integer values
scale = 6.6666 # Correction factors involve floating point
mag = list(map(lambda x, y : x*y/scale, imu.mag.ixyz, imu.mag_correction))
print("Interrupt:", [x/16384 for x in imu.accel.ixyz], [x/131 for x in imu.gyro.ixyz], mag)
pyb.delay(100)
print("Normal: ", imu.accel.xyz, imu.gyro.xyz, imu.mag.xyz)
print()
tim.callback(None)
In the above code, i get following error. ""ValueError: Invalid I2C instance"""
Can anyone help to resolve it.