MPU6050 not connecting

Hello!

I'm new and trying to use a MPU6050 (GY-521 sensor) by using Jeff Rowdberg's code (from i2cdevlib/Arduino at master · jrowberg/i2cdevlib · GitHub), I imported the I2Cdev and MPU6050 folders into the library and tried to run MPU6050_DMP6, but it printed:

Initializing I2C devices...
Testing device connections...
MPU6050 connection failed
Send any character to begin DMP programming and demo:

After that I can send a character and it will give me sensor data that appears to match what I should be seeing, but it stops printing to serial after around 10 seconds. It shows up on the I2C scanner so I know that's not the issue. Any help would be appreciated! Here is my setup:

You will want to show the sketch you are using that shows the output you showed.

try running the I2C scanner to check if it finds any devices

I used the I2C scanner before and it showed up as 0x68, which is supposed to happen. I think the problem is with this code:

/** Get Device ID.
 * This register is used to verify the identity of the device (0b110100, 0x34).
 * @return Device ID (6 bits only! should be 0x34)
 * @see MPU6050_RA_WHO_AM_I
 * @see MPU6050_WHO_AM_I_BIT
 * @see MPU6050_WHO_AM_I_LENGTH
 */
uint8_t MPU6050_Base::getDeviceID() {
    I2Cdev::readBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, buffer, I2Cdev::readTimeout, wireObj);
    return buffer[0];
}

The program checks if GetDeviceId is equal to 0x34, and if it doesn't then it thinks it is not connected. When I run it, I get 56, which is 0x38. What does it mean if the identity of the device is not verified?

This is the code that prints the output:

Serial.println(F("Testing device connections..."));
    Serial.println(mpu.getDeviceID());
    Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

And this is the code that checks tests the connection:

bool MPU6050_Base::testConnection() {
    return getDeviceID() == 0x34;
} 

I am unfamiliar with the i2cdevlib you are using.

I am more familiar with using the Arduino wire library.

Have you tried Adafruit's i2c scanner? The link is posted above in horace's post. It uses the wire library.

If that works, there is probably an issue with i2cdevlib. It does have 262 outstanding issues.

installed I2Cdev and MPU6050 from I2C Device Library
ran MPU6050_DMP6 serial monitor output

Initializing I2C devices...
Testing device connections...
MPU6050 connection successful

Send any character to begin DMP programming and demo: 
Initializing DMP...
>......>......-2068.00000,	459.00000,	1422.00000,	-273.00000,	2369.00000,	-9.00000

Enabling DMP...
Enabling interrupt detection (Arduino external interrupt 0)...
DMP ready! Waiting for first interrupt...
ypr	0.01	0.06	0.45
ypr	0.01	0.09	0.45
ypr	0.01	0.13	0.45
ypr	0.01	0.14	0.45

ran MPU6050_RAW

Initializing I2C devices...
Testing device connections...
MPU6050 connection successful
a/g:	0	0	0	0	0	0
a/g:	-100	676	14212	1116	179	29
a/g:	16352	608	7348	1242	300	2015
a/g:	-116	16372	-4628	1223	915	2534
a/g:	-780	17176	-5300	1360	-868	-2464
a/g:	-7776	2412	10680	-2015	-8153	3324
a/g:	-304	-1284	-19752	2120	-2134	-489
a/g:	4048	16864	-7988	-378	-576	2792
a/g:	9236	7260	7092	-4930	-923	2500
a/g:	-820	1116	14084	1131	222	31
a/g:	-760	1152	13996	1133	274	37

running Adafruit MPU6050 basic_readings example gives

Adafruit MPU6050 test!
MPU6050 Found!
Accelerometer range set to: +-8G
Gyro range set to: +- 500 deg/s
Filter bandwidth set to: 21 Hz

Acceleration X: 0.25, Y: 0.28, Z: 8.46 m/s^2
Rotation X: 0.15, Y: 0.03, Z: 0.00 rad/s
Temperature: 21.77 degC

Acceleration X: 1.18, Y: 0.35, Z: 8.61 m/s^2
Rotation X: 0.15, Y: 0.01, Z: -0.07 rad/s
Temperature: 21.83 degC

Acceleration X: 5.30, Y: -0.58, Z: -6.91 m/s^2
Rotation X: -0.76, Y: -0.26, Z: -0.93 rad/s
Temperature: 21.89 degC

Acceleration X: -2.21, Y: -8.76, Z: -7.30 m/s^2
Rotation X: -1.10, Y: 1.63, Z: -0.47 rad/s
Temperature: 21.88 degC
Acceleration X: 0.32, Y: 0.23, Z: 8.39 m/s^2
Rotation X: 0.15, Y: 0.03, Z: 0.00 rad/s
Temperature: 21.89 degC

Acceleration X: 0.33, Y: 0.24, Z: 8.43 m/s^2
Rotation X: 0.15, Y: 0.03, Z: 0.00 rad/s
Temperature: 21.89 degC

Acceleration X: 0.31, Y: 0.25, Z: 8.43 m/s^2
Rotation X: 0.15, Y: 0.03, Z: 0.00 rad/s
Temperature: 21.89 degC

Acceleration X: 0.30, Y: 0.23, Z: 8.44 m/s^2
Rotation X: 0.15, Y: 0.03, Z: 0.00 rad/s
Temperature: 21.89 degC

Acceleration X: 0.29, Y: 0.24, Z: 8.42 m/s^2
Rotation X: 0.15, Y: 0.03, Z: 0.00 rad/s
Temperature: 21.90 degC

Acceleration X: -0.37, Y: 0.20, Z: 8.41 m/s^2
Rotation X: 0.16, Y: 0.08, Z: 0.00 rad/s
Temperature: 23.33 degC

Acceleration X: -0.24, Y: 0.26, Z: 8.43 m/s^2
Rotation X: 0.15, Y: 0.03, Z: 0.00 rad/s
Temperature: 23.07 degC

The adafruit library for the mpu6050 works so I'll use that, thanks though!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.