How to use MPU9250

I cannot get an MPU9250 to work. I tried with sample codes in examples section and also the examples in webide.

-The code in examples throws an error (freeRTOS error) at enableInterrupt(),

-If i comment out enableInterrupt(), it hangs at waitfordata()? (Which can be normal, as i checked the interrupt wire with an oscilloscope and it doesn’t work).

-Lastly if i comment out waitfordata() and try to read every sys.delay(250), i get some reading everytime along with some I2C_TIMEOUT log prints. (the numbers read seem to be very wrong though).

-I tried both hSens1 & 2, i also checked the MPU9250 on a rpi with RTIMULib2, it works (without interrupt)

-The MPU9250 board that i am using is an ebay one looking exacly like the one in the picture of husarion website:
https://husarion.com/assets/img/core2-hardware/mpu9250.svg

-I am using 5 wires Vcc, gnd, sda, scl, int

Any help would be much appreciated. Thanks!

PS: I couldn’t find anything except that in modules/MPU9250.cpp i2c address is defined as 0x69. And when i try that with RTIMULib2 it doesn’t work while 0x68 works.

Hi, thanks, I just made a little fix in MPU9250 example in Web IDE. I tested this example and everything works fine. Have you connected MPU9250 to the hExt interface as described in main.cpp (“a. Arduino MPU9250 example”):

//at first connect MPU9250 to the hExt I2C:
// https://husarion.com/core2/manuals/hardware/#hardware-hext
// SCL -> hExt.i2c.pinScl
// SDA -> hExt.i2c.pinSda
// VCC -> +5V (sw)
// GND -> GND

Here is a pin map: https://husarion.com/core2/manuals/core2/#hardware-hext .

image

Best,
Dominik

Hi Dominik,
Thanks for your answer. I hadn’t checked Arduino MPU9250 example, i will do it when i have some time.
However i found the issue and got it working.
It was because of the I2C address, the default in MPU9250 is 0x68 and in modules/src/MPU9250.cpp
the address is set to 0x69. In order to set the address to 0x69, AD0 pin of MPU should be high. Basically the example in
https://husarion.com/core2/examples/#modules__MPU9250_basic
won’t work with the wiring shown in
https://husarion.com/assets/img/core2-hardware/mpu9250.svg

It either needs another wire between pin2 and AD0, set to high.
or
const uint8_t I2C_ADDR = 0x69; should be changed to const uint8_t I2C_ADDR = 0x68; in MPU9250.cpp

regards,

1 Like