1

I am using an Arduino Leonardo together with a GY-521 breakout board (like this one, schematic) for an MPU 6050.

I am currently trying to get the DMP Version of the examples from Mr Rowberg to work.

For all my tests, I use these connections:

  • GY-521 -> Leonardo
  • VCC -> 5V (3.3V has the same behaviour)
  • SDA -> SDA
  • SCL -> SCL
  • GND -> GND

The "raw" sketch works fine, I can read out the sensor data. For the DMP version I think I need to connect the INT pin to pin 3 on the leonardo, to allow the MPU6050 to trigger an interrupt.

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? =)

Edit: The example source code says

/* =========================================================================
   NOTE: In addition to connection 3.3v, GND, SDA, and SCL, this sketch
   depends on the MPU-6050's INT pin being connected to the Arduino's
   external interrupt #0 pin. On the Arduino Uno and Mega 2560, this is
   digital I/O pin 2.
 * ========================================================================= */

The example does nothing (that I can see) to configure this pin.

Edit again:

I've borrowed an oscilloscope. SDA and SCL sit on 3.3V during normal communication, and I can see packets being exchanged. As soon as I connect the INT pin to any input pin on my Leonardo, both SDA and SCL go to ground. This means nothing to me, but maybe to someone else.

5 Answers 5

2

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.

1

possible problem: level mismatch

I speculate that maybe some output on this Arduino is trying to push close to 5.0 V into your gyro, which is well outside the specifications of your gyro. You are lucky that anything worked at all.

According to page 12 of the MPU-6050 gyroscope datasheet, the gyroscope is designed to operate from a power supply of VDD = 2.375V to 3.46V.

You might think that is already taken care of by the 3.3V regulator on your breakout board.

However, a VDD of 3.3 also implies that the gyro expects all of its inputs to be in the range 0 V to 3.3 V, and the gyro will drive its outputs in the range 0 V to 3.3 V.

Page 358 of the ATmega32u4 datasheet says that the ATmega32u4 is designed work with any power supply in the range 2.7V to 5.5V.

There is a 3.3V regulator on the Arduino Leonardo and another one on the GY-521 breakout board. So the GY-521 breakout board should have its VCC connected to 5V and its GND connected to the Arduino GND so that regulator can power the gyro chip with 3.3.

Unfortunately for you, the Arduino Leonardo is designed to power the ATmega32u4 with VCC = 5.0 V.

What to do about level mismatch

Perhaps it would work better if we connect things the way they were designed to be used.

If I were you, I would try to keep signal levels within specifications by any one of:

  • Use a level converter, perhaps a I2C-compatible level converter for each data connection between the 3.3V I/O pins of the gyro and the 5.0V I/O pins of the Arduino Leonardo. (a) (b) (c) Or,
  • Somehow tweak the Arduino Leonardo to connect 3.3 V to the VCC pin of the ATmega32u4. (Does this require cutting traces on the PCB?). Or,
  • Use some other Arduino configured to run the processor at 3.3V (LilyPad Arduino USB; Arduino Fio; Arduino Zero; Arduino Due; Arduino TRE; some versions of Arduino Pro Mini; some versions of Arduino Pro; etc.) or easily connected to 3.3V (LilyPad Arduino SimpleSnap; LilyPad Arduino Simple; LilyPad Arduino; etc.)
0

Is it possible that the INT pin on the MPU 6050 in an input, not an output?

The symptoms you describe make it sound like you're locking the gyro chip into an interrupt state so it's not responding any more.

I wasn't able to figure out the use of the INT pin from a quick scan of the data sheet however. It would take more careful study.

Do you have your Arduino pin set up as an input or an output? And if it's an input, does it have a pull-up or pull-down resistor, either internal or external, set up?

1
  • Thanks for your input. I'll need to check how the pins are configured; I only use the example code linked in the question and have nothing configured myself. The INT on the MPU should be an output. This setup works for others (at least with a Uno).
    – Jens
    Sep 2, 2014 at 6:59
0

To use external interrupt 4 (INT6), pin D7 on Leonardo board. we need change interrupt register as follows

   EICRB |= (1<<ISC60)|(1<<ISC61); // sets the interrupt type
   EIMSK |= (1<<INT6); // activates the interrupt

that write in WInterrupts.c

Follow this link

http://forum.arduino.cc/index.php?topic=124057.0

-1

the interrupt pin in the attachInterrupt command should be kept to #4 which is pin D7 as stated here "http://arduino.cc/en/Reference/AttachInterrupt" since we can't use pins D0-D3 the only left out option is D7 but the problem still persists. Somebody please solve this !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.