Go Down

Topic: Wire MPU6050 (cheap eBay breakoutboard) to Arduino MEGA 1280 (Read 3392 times) previous topic - next topic

EliteTUM

Hi everyone,

I tried using a MPU6050 I got quite cheap from eBay with my Arduino MEGA 1280. Unfortunately, I can't get it running. I don't event get a proper connection.

I attached a picture of the breakout-board. For those who can't see it, the pins are:
VCC
GND
SCL
SDA
XDA
XCL
AD0
INT

I asked the seller and he gave me the following advice for wiring it all together:






MPU6050 breakoutboard Arduino MEGA 1280
VCC<->3V3
GND<->GND
SCL<->ANALOG IN A5
SDA<->ANALOG IN A4


I also attached the Code he gave me (RAR-File). For those who can not open it, try this Link. The Sketch-File looks like this:

Code: [Select]
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class
// 10/7/2011 by Jeff Rowberg <jeff@rowberg.net>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
//     2011-10-07 - initial release

/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2011 Jeff Rowberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

#define LED_PIN 13
bool blinkState = false;

void setup() {
    // join I2C bus (I2Cdev library doesn't do this automatically)
    Wire.begin();

    // initialize serial communication
    // (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
    // it's really up to you depending on your project)
    Serial.begin(38400);

    // initialize device
    Serial.println("Initializing I2C devices...");
    accelgyro.initialize();

    // verify connection
    Serial.println("Testing device connections...");
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");

    // configure Arduino LED for
    pinMode(LED_PIN, OUTPUT);
}

void loop() {
    if (accelgyro.testConnection()) {
        // read raw accel/gyro measurements from device
        accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
   
        // these methods (and a few others) are also available
        //accelgyro.getAcceleration(&ax, &ay, &az);
        //accelgyro.getRotation(&gx, &gy, &gz);
   
        // display tab-separated accel/gyro x/y/z values
        Serial.print("a/g:\t");
        Serial.print(ax); Serial.print("\t");
        Serial.print(ay); Serial.print("\t");
        Serial.print(az); Serial.print("\t");
        Serial.print(gx); Serial.print("\t");
        Serial.print(gy); Serial.print("\t");
        Serial.println(gz);
   
        // blink LED to indicate activity
        blinkState = !blinkState;
        digitalWrite(LED_PIN, blinkState);
    }
}


I slightly changed the loop()-Function here so it won't flood my SerialMonitor. Nevertheless, I always get the error

Quote
MPU6050 connection failed


Where did I go wrong? Is it simply my wiring, the code, or both?

I'm new to I2C-Usage on Arduino, so sorry for this (maybe) rather simple problem. Any help is appreciated  a lot; thanks in advance!

Regards!

My guess is that your breakout board doesn't include voltage regulators for the signal pins.  Therefore, you're feeding 5v to the sensor over the signal pins and probably fried it.  Get another one, but not just a breakout board but one with voltage regulators.

Tim
Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

EliteTUM

Thanks for the hint. I checked back with the seller and he assured me this should work without special voltage regulators. I'll try to test it with another Arduino.

Nantonos


I asked the seller and he gave me the following advice for wiring it all together:






MPU6050 breakoutboard Arduino MEGA 1280
VCC<->3V3
GND<->GND
SCL<->ANALOG IN A5
SDA<->ANALOG IN A4



That is wrong (it is the right answer for an Arduino Uno). One Arduino Mega1280 and Mega2560 the SCL is on pin 21 and the SDA is on pin 20.

Nantonos

#4
Nov 09, 2012, 09:23 am Last Edit: Nov 09, 2012, 09:27 am by Nantonos Reason: 1

My guess is that your breakout board doesn't include voltage regulators for the signal pins.  Therefore, you're feeding 5v to the sensor over the signal pins and probably fried it.  Get another one, but not just a breakout board but one with voltage regulators.


(Assuming you mean logic-level converters, not voltage regulators). Yes - looking at this page it clearly says the operting voltage is 2.375V-3.46V. In other words this expects 3V3 not 5V0 logic.

So it should be connected via an I2C-capable logic level converter.

On the other hand, since the break-out boad was connected to A4 and A5 which were doing nothing (on a Mega1280) the board is maybe not fried ... yet. And on the third hand, this datasheet says (on page 20):

Quote
Supply Voltage, VDD   -0.5V to +6V

Nantonos



Code: [Select]
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class
// 10/7/2011 by Jeff Rowberg <jeff@rowberg.net>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
//     2011-10-07 - initial release

}



The code the vendor gave you is old. The link in the code is good though; going to that page shows an actively maintained library and, indeed, 2 days ago, the sample code for MPU6050 was updated  :) so I suggest you downnload and use that.

Code: [Select]
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class using DMP (MotionApps v2.0)
// 6/21/2012 by Jeff Rowberg <jeff@rowberg.net>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
// 2012-06-21 - added note about Arduino 1.0.1 + Leonardo compatibility error
// 2012-06-20 - improved FIFO overflow handling and simplified read process
// 2012-06-19 - completely rearranged DMP initialization code and simplification
// 2012-06-13 - pull gyro and accel data from FIFO packet instead of reading directly
// 2012-06-09 - fix broken FIFO read sequence and change interrupt detection to RISING
// 2012-06-05 - add gravity-compensated initial reference frame acceleration output
// - add 3D math helper file to DMP6 example sketch
// - add Euler output and Yaw/Pitch/Roll output formats
// 2012-06-04 - remove accel offset clearing for better results (thanks Sungon Lee)
// 2012-06-01 - fixed gyro sensitivity to be 2000 deg/sec instead of 250
// 2012-05-30 - basic DMP initialization working

EliteTUM



I asked the seller and he gave me the following advice for wiring it all together:






MPU6050 breakoutboard Arduino MEGA 1280
VCC<->3V3
GND<->GND
SCL<->ANALOG IN A5
SDA<->ANALOG IN A4



That is wrong (it is the right answer for an Arduino Uno). One Arduino Mega1280 and Mega2560 the SCL is on pin 21 and the SDA is on pin 20.


Thanks for the hint. Could have figured that out by myself, duuuh.
I re-wired everything now and get the following:

Quote
Initializing I2C devices...
Testing device connections...
MPU6050 connection failed
a/g:   13312   0   0   0   0   0
a/g:   13312   0   0   0   0   0
a/g:   13312   0   0   0   0   0
a/g:   13312   0   0   0   0   0
a/g:   13312   0   0   0   0   0


I guess the message "MPU6050 connection failed" can be ignored, since my loop()-Function looks like this:

Code: [Select]
void loop() {
    if(accelgyro.testConnection()==true){
        delay(100);
        // read raw accel/gyro measurements from device
        accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
   
        // these methods (and a few others) are also available
        //accelgyro.getAcceleration(&ax, &ay, &az);
        //accelgyro.getRotation(&gx, &gy, &gz);
   
        // display tab-separated accel/gyro x/y/z values
        Serial.print("a/g:\t");
        Serial.print(ax); Serial.print("\t");
        Serial.print(ay); Serial.print("\t");
        Serial.print(az); Serial.print("\t");
        Serial.print(gx); Serial.print("\t");
        Serial.print(gy); Serial.print("\t");
        Serial.println(gz);
   
        // blink LED to indicate activity
        blinkState = !blinkState;
        digitalWrite(LED_PIN, blinkState);
    }
}


So, maybe the connection-test just does not work correctly when called during setup(), but later it returns true.
Nevertheless, it still doesn't seem to be working since it doesn't output anything except what you see above. No mater how fast I move/rotate the sensor.
Could be I accidently now fried it if it wasn't fried before  :(

Would the testConnection()-Function still return true even if the MPU6050 were damaged?

EliteTUM

After taking some time with a Multimeter, I found that the soldering was quite bad (high resistance; don't know what wnt wrong there). I resoldered everything et voila, I get good Sensor Signals with the Raw Read Example Sketch.

Thanks for the support guys!

Damn my impatience: I allready ordered a ADXL335 which now is obsolete. :)

Go Up