Possible problem: pin interference
But as soon as I connect INT to anything (pins 0 through 3), the
sketches do not find the MPU6050 any more. (They report ""MPU6050
connection failed").
Is my wiring off, or is my chip defective, and even more important,
how could I figure that out on my own in the future? =)
If I'm reading the Arduino Leonardo schematic correctly,
Arduino D0 is Rx, Arduino D1 is Tx,
Arduino D2 is the I2C_SDA, and Arduino D3 is the I2C_SCL.
You're already using the I2C_SDA and I2C_SCL as bidirectional I2C communication;
connecting some other output pin (such as the MPU6050 INT pin) to either of those pins is going to disrupt that communication and then things won't work.
On most Arduinos, Serial.println() and Serial.read() and the reprogramming process use the Rx and Tx pins.
Perhaps connecting the MPU6050 INT pin to either of those pins also causes some sort of problem leading to things that don't work.
(Although the Arduino Leonardo actually uses its USB_D- and USB_D+ pins for both Serial.println() and reprogramming, so maybe it isn't really a problem for the Leonardo?).
I would avoid using those pins for anything other than serial communication, even though I'm not at all sure that would actually cause a problem on the Arduino Leonardo.
The example source code says
... this sketch depends on the MPU-6050's INT pin being connected to
the Arduino's external interrupt #0 pin. ...
The example does nothing (that I can see) to configure this pin.
I assume you're using https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/Examples/MPU6050_DMP6/MPU6050_DMP6.ino , right?
Interrupts are configured a little differently than I/O.
(In particular, "volatile" is critical to getting interrupts working right).
The part that configures that interrupt is in the setup() function:
void setup() {
// ...
// enable Arduino interrupt detection
Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
attachInterrupt(0, dmpDataReady, RISING);
// ...
}
The "attachInterrupt(0, dmpDataReady, RISING)" line
configures the interrupt vector table and the configuration bits so that when something drives Arduino pin D2 (i.e., external interrupt source 0) from a low to a high, no matter what the Arduino is in the middle of doing, the Arduino puts that on hold, executes the dmpDataReady() function, and then the Arduino resumes where it left off.
I don't see how that ever worked, since "external interrupt 0" comes from pin D2, which on the Arduino Leonardo is connected to I2C_SDA, which we're using for I2C communication, so we can't use it for watching the gyro interrupt pin.
However, since the "attachInterrupt()" gets run long after the "MPU6050 connection failed" message gets printed out on your screen, a software bug in how the example code uses attachInterrupt() doesn't explain why you get that "fail" message printed on your screen.
what to do about pin interference
I would try either using some other pin, or try getting it to work without hooking that pin to the Arduino at all.
Using some other pin
I would try to assign a dedicated pin on the Arduino to the MPU6050 INT pin.
Maybe D9 would work?
I'm guessing on the Arduino Leonardo, the interrupt should be set up something more like:
// warning: untested code.
#include <PinChangeInt.h>
#include <PinChangeIntConfig.h>
// connect MPU6050 interrupt to Arduino D9
#define MPU6050_INT D9
void setup(){
// ...
// pin change interrupt
pinMode(MPU6050_INT, INPUT);
PCintPort::attachInterrupt(MPU6050_INT, dmpDataReady, RISING);
// ...
}
Getting it to work without hooking INT to the Arduino
It's not at all clear that the Arduino really needs to be connected to the MPU6050 INT pin.
It appears that another option is for the Arduino to occasionally use the I2C communication to read the status of the MPU6050, which includes the current state of that pin.
That simplifies the hardware -- simply leave the MPU6050 INT pin unconnected.