MPU-9250 Library issue with Due

Problem:

My code seems to be hanging when the MPU9250 object is created. This occurs before the setup function is ever entered.

Setup:

I am using an Arduino Due (DEV-11589) connected to the MPU-9250 breakout board (SEN-13762) via I2C. I have SDA connected to pin 20 and SCL connected to pin 21. The power for the MPU-9250 is connected to the 3.3V rail and GND of the Due. The programming port is connected to my computer running Windows 10 and using the Arduino IDE V1.8.9. External power is also being provided to the barrel jack at 9VDC. I installed the Sparkfun MPU-9250 Library ([Github) using the Arduino IDE.

Expected Behavior:

The Arduino will read the Acc/Gyro/Mag data from the MPU-9250 and print the raw values to terminal on my computer.

To-date Troubleshooting:

After the initial program didn’t work, I placed a small snippet of code at the very beginning of the setup function to blink the LED connected to pin 13. After compiling and downloading, the LED never blinked. Instead, the LED stayed on. There are only #includes, #defines, an object creation, and a global variable declaration before the setup. The first few lines of code are shown below.

I also created a separate program that only blinks pin13 in setup with the same #includes, #defines, but without the object creation and global variable declaration. This program works.

Given the two cases above, I can only conclude that the MPU9250 object creation is the source of the problem. When looking through the library, I don’t see where there is a platform specific issue. The library explicitly calls out compatibility with Arduino Pro Mini and Teensy 3.1.

#include "MPU9250.h"

#define I2Cclock 400000
#define I2Cport Wire
#define MPU9250_ADDRESS MPU9250_ADDRESS_AD0

MPU9250 myIMU(MPU9250_ADDRESS, I2Cport, I2Cclock);

bool newData = false; //used as state variable for outputing data to user.

void setup() 
{
  pinMode(13,OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);

](GitHub - sparkfun/SparkFun_MPU-9250_Breakout_Arduino_Library: Arduino sketch for MPU-9250 9DoF with AHRS sensor fusion)

I don’t think that library works with on a Due; you probably have to modify the library to work with that microcontroller/platform.

Hi D_SWA,

You may need to define your SDA and SCL pins for the Due on this library. If that does not work, I’m not sure if I2C is going to work with the Due here so you could either try using the MPU-9250 with SPI or possibly the library Kris Winer wrote that ours is based on works with the Due. Here’s a link to Kris Winer’s [MPU-9250 Library.](GitHub - kriswiner/MPU9250: Arduino sketches for MPU9250 9DoF with AHRS sensor fusion)