Go Down

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


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


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

MPU6050 breakoutboard Arduino MEGA 1280

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:

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() {
        // 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(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");
        // 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?


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