Leonardo + MPU-6050 + Interrupt = hangs


hopefully someone can help me to figure out why the interrupt mechanism of the MPU-6050 does not work for my sketch.

I attached the sketch that I’m using for my project. It’s basically the default example of the ic2devlib with the DMP feature.

I attached the MPU-6050 to my arduino leonardo as follows:
MPU VCC to 3.3V
MPU SDL + SCL to SDL and SCL on the arduino board
MPU INT to PIN 3 as the manual says that this is the interrupt 0 PIN for leonardo.

When I start the sketch I only see the message “Initializing I2C devices…” on the serial console and nothing other happens. If I remove the wire connection of the INT pin the program goes further and prints many many messages, but as I far as I understand it correctly, the interrupt is not triggered actually.

I also added some debug output to the dmpDataReady() function which is also invoked, but I don’t understand why, because the wire is not connected.

Is there anyone that has similar problems, or can help me to figure out how I can solve that issue?
Thanks for your help.

Gyro.ino (14.8 KB)

In the library are some hardware registers used, I don't know how that will be for the Leonardo. Are you sure you have the normal I2CDEV_ARDUINO_WIRE selected ? Try that first before the extra fast i2cdevlib functions.

Pin 3 for INT_0 is okay.

Could you try the i2c_scanner with and without the INT connected ? http://playground.arduino.cc/Main/I2cScanner That should run normal.

thanks Peter for your reply.
I tried the scanner example that you provided and as long as the interrupt pin is not connected the sketch detects that address 0x68 is connected via i2c. However if the INT of MPU is connected to pin 3 the sketch also hangs up. The sketch prints the message “Scanning…” and thats all.
Seems to be the same behaviour as in my DMP example.

Any ideas on this?
BTW: Attached you find an image how I connected the MPU to my board.

Hi, Im having troubles too with MPU6050.

In your case, I read in other threads and forums in some cases 3.3v isnt enough for the MPU. In fact, MPU6050 has a voltage regulator, however I'm not sure at all, I'm based on that I read (I connect mine to 5V and havent problems).

I'm sorry, I made a mistake. For the Leonardo, INT0 is pin 3, but SCL is also pin 3. The header pin SCL is connected to digital pin 3, they are the same.

See the reference for the Leonardo board and the reference for attachInterrupt.

You can use pin 0 or 1 (but that is also Serial1) or pin 7.

After that, you have to change the library to use the other interrupt. The attachInterrupt() uses the interrupt number, not the pin number.

svesch and JotaStar: You can connect the 5V to Vcc of the sensor module. It's onboard voltage regulator will make 3.3V. That is a little better than using 3.3V from the Arduino board. When the 3.3V is going through the voltage regulator, the output will be between 3.1 and 3.2V which result in a lower voltage of the I2C signals from the sensor board.

That you for acclaration of voltage, Peter_n.

svesch, the basic example of MPU6050 in Arduino Playfround works for you? (http://playground.arduino.cc/Main/MPU-6050#short)

I always get the same values and i2cdevlib doesnt work for me (http://forum.arduino.cc/index.php?topic=271519.0)

Peter, many thanks for you help, now we are on the right path. I used PIN 7 instead and attached that one to interrupt 4 and indeed the interrupt is triggered. When I remove the connection between the INT pin and PIN 7 the interrupt is not triggered. Many thanks for solving this.

Though on the other hand I'm not sure why the event is triggered every 4 micro seconds, even if the sensor is not moved. The INT_STATUS register always shows me the value of 0x03, sometimes also 0x00. Bit 0 is the DATA_READY_INT bit, but bit 1 is not documented, at least not in revision 4.0 of the register map of the MPU-6050.

As far as I know, the i2cdevlib sets it to 100Hz. So every 10ms all the data (gyro + accel) is retrieved from the MPU-6050. The MPU-6050 generates an interrupt every 10ms, and a interrupt signals the Arduino to request the data from the MPU-6050.

That takes some time, so that is why the i2cdevlib has optimized fast i2c functions. But I don't know if that is compatible with the Arduino Leonardo.

The simple example of the i2cdevlib doesn't use the interrupt, the 'dmp' uses the automatic 100Hz interrupt.

Peter thanks for the clarification, but then what is the advantage of that interrupt stuff compared to just polling the raw values every X ms? I thougt that interrupts make things faster, because the processor needs to process data only if something changed/moves? Or do I need to change some thresholds in my configuration to archieve this?

If you want to level a platform, you may do without the 100Hz. This guide links at the end of the first post to code, that uses a kalman filter. http://forum.arduino.cc/index.php/topic,58048.0.html

However, when calculating the acceleration, and using the magic 'dmp' inside the MPU-6050, a fixed steady rate of 100Hz makes it possible to do accurate calculations with the acceleration and gyro.

I don't know what you mean with threshold.

I have similar problem, I attached the MPU-6050 to my arduino leonardo as follows: MPU GND to GND MPU VCC to 3.3V MPU SDL + SCL to SDL and SCL on the arduino board MPU INT to PIN 3 as the manual says that this is the interrupt 0 PIN for Leonardo. I uploaded the example sketch for MPU6050 When I start the sketch I only see the message "Initializing I2C devices..." on the serial console and nothing other happens.Even if I remove interrupt,it hangs and shows same message. please help me,I am new to arduino and MPU6050.