Closed k79fi closed 3 years ago
The line
if self.whoami not in [0x71, 0x70]:
does not compare the i2c address. Instead it compares the value of the WHO_AM_I
register.
For MPU-9250 the value of WHO_AM_I
register is 0x71
and address is 0x68
or 0x69
. The value of MPU-6500 WHO_AM_I register is 0x70
and address is 0x68
or 0x69
.
Could you check what is the value of self.whoami
? Maybe you have a custom chip or a chip which is compatible but not actual MPU-9250.
No feedback.
Encountering the same issue as OP.
Using print(self.whoami)
the value I got was 115
- I believe this corresponds to 0x73
.
The module I am using is the same as the one described here.
Update: The following change runs without errors and the example code appears to output values correctly.
if self.whoami not in [0x71, 0x70]:
changed to,
if self.whoami not in [0x71, 0x70, 0x73]:
from machine import Pin, I2C from mpu6500 import MPU6500 from mpu9250 import MPU9250
i2c=I2C(scl=Pin(22), sda=Pin(21)) sensor=MPU9250(i2c) ...
Expected result: MPU9250 class successfully instantiated
Actual result: code throws runtime exception "MPU6500 not found in I2C bus."
Suspected code: if self.whoami not in [0x71, 0x70]: raise RuntimeError("MPU6500 not found in I2C bus.")
MPU9250 has i2c address 0x68, however here it compares it to 0x70 and 0x71 and fails if comparisons fail. Once this code is commented out, the library seems to work just fine.