MPU6050 I2C Can't even get the basics to run

Hello experts,

I’m tryin to get a GY-521 module with a mpu6050 to run. I’m using the standard wiring and the original “MPU6050 class using DMP (MotionApps v6.12)” -example. Version is from 2019-07-10. Serial output is ypr

The output on the serial monitor always stops and the program hangs after between 20 and 100 seconds. I already tried the following:

  • change the arduino (UNO and Nano)
  • change the GY-521
  • change the wiring
  • reduce serial speed to 38400
  • reduce I2C speed to 100 kHz

Does anybody have a hint, where to search next?

Please execute the following sketch to check that the MPU6050 is found by the MCU on the I2C Bus.

#include<Wire.h>

void setup()
{
    Serial.begin(9600);
    Wire.begin():
    Wire.beginTransmission(0x68);    //MPU's address is 0x68 when AD0-pin is tied to LOW.
    byte busStatus = Wire.endTransmission();
    if(busStatus !=0)
    {
       Serial.print("The device is not found...!");
       while(1);    //wait for ever
    }
    Serial.print("The device is found.");
}

void loop()
{

}

Please, report the result.

Hello,
yes, the MPU6050 is found by the MCU. A typical output of the "MPU6050 class using DMP (MotionApps v6.12)" -example is:

17:09:01.496 -> Initializing I2C devices...
17:09:01.496 -> Testing device connections...
17:09:01.496 -> MPU6050 connection successful
17:09:01.496 -> 
17:09:01.496 -> Send any character to begin DMP programming and demo: 
17:09:12.537 -> Initializing DMP...
17:09:13.076 -> >*......>......
17:09:15.033 -> 
17:09:15.033 -> //           X Accel  Y Accel  Z Accel   X Gyro   Y Gyro   Z Gyro
17:09:15.033 -> //OFFSETS      260,   -1566,    1908,      67,     -33,     -17
17:09:15.033 -> Enabling DMP...
17:09:15.033 -> Enabling interrupt detection (Arduino external interrupt 0)...
17:09:15.080 -> DMP ready! Waiting for first interrupt...
17:09:15.080 -> ypr -0.01 -0.06 0.62
17:09:15.080 -> ypr -0.01 -0.06 0.61
17:09:15.080 -> ypr -0.01 -0.07 0.60
17:09:15.080 -> ypr -0.01 -0.07 0.60
17:09:15.080 -> ypr -0.01 -0.07 0.59
17:09:15.127 -> ypr -0.01 -0.07 0.59
17:09:15.127 -> ypr -0.01 -0.07 0.59
17:09:15.127 -> ypr -0.01 -0.07 0.58
17:09:15.127 -> ypr -0.01 -0.07 0.57
17:09:15.127 -> ypr -0.01 -0.07 0.57
17:09:15.127 -> ypr -0.01 -0.07 0.57
17:09:15.174 -> ypr -0.01 -0.07 0.57
(...)
17:09:32.446 -> ypr -1.11 0.07 -0.00
17:09:32.446 -> ypr -1.11 0.07 -0.00
17:09:32.446 -> ypr -1.11 0.06 0.01

then the program hangs. It runs 17 seconds, then it stops

Please, upload the following sketch which measures the temperature using MPU6050’s internal temperature sensor. This is to isolate the problem.

#include <MPU6050.h>
MPU6050 mpu;   //device address 0x68 keyed in the library

void setup()
{
  Serial.begin(9600);
  Serial.println("Initialize MPU6050");
  while (!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
  {
    Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
    delay(1000);
  }
}

void loop()
{
  float temp = mpu.readTemperature();
  Serial.print("Temp = ");
  Serial.print(temp, 2);
  Serial.println(" *C");
  //-------------------------
  delay(1000);
}

Your sketch isn't compiled:

D:\Arduino\MPU6050_Temp\MPU6050_Temp.ino: In function 'void setup()':

MPU6050_Temp:8:15: error: 'class MPU6050' has no member named 'begin'

   while (!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))

               ^

MPU6050_Temp:8:21: error: 'MPU6050_SCALE_2000DPS' was not declared in this scope

   while (!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))

                     ^

MPU6050_Temp:8:44: error: 'MPU6050_RANGE_2G' was not declared in this scope

   while (!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))

                                            ^

D:\Arduino\MPU6050_Temp\MPU6050_Temp.ino: In function 'void loop()':

MPU6050_Temp:17:20: error: 'class MPU6050' has no member named 'readTemperature'

   float temp = mpu.readTemperature();

                    ^

exit status 1
'class MPU6050' has no member named 'begin'

I use MPU6050.h version from 2019-07-08

th_her:
Your sketch isn't compiled:

The sketch of Post#3 well is compiled, uploaded, and executed in my UNO.
smMPU.png

This is the MPU6050.h (attached file) that I have used.

smMPU.png

Arduino-MPU6050-master.zip (27.7 KB)

Ok, now your sketch runs and things become complicated, because You use the MPU6050.h from

(c) 2014-2015 Korneliusz Jarzebski

, but in my context, I want to use the one from the

I2CDevLib-collection

comig from here: GitHub - jrowberg/i2cdevlib: I2C device library collection for AVR/Arduino or other C++-based MCUs

Output of Your sketch is:

21:53:04.845 -> Initialize MPU6050
21:53:04.845 -> Temp = 27.38 *C
21:53:05.854 -> Temp = 27.38 *C
21:53:06.891 -> Temp = 27.38 *C
21:53:07.876 -> Temp = 27.39 *C
21:53:08.879 -> Temp = 27.37 *C
21:53:09.864 -> Temp = 27.38 *C
21:53:10.868 -> Temp = 27.36 *C
21:53:11.899 -> Temp = 27.37 *C
21:53:12.903 -> Temp = 27.37 *C
21:53:13.887 -> Temp = 27.36 *C
21:53:14.869 -> Temp = 27.37 *C
21:53:15.864 -> Temp = 27.35 *C
21:53:16.878 -> Temp = 27.38 *C
21:53:17.903 -> Temp = 27.36 *C
21:53:18.899 -> Temp = 27.36 *C
21:53:19.888 -> Temp = 27.36 *C
21:53:20.865 -> Temp = 27.37 *C
21:53:21.896 -> Temp = 27.35 *C
21:53:22.900 -> Temp = 27.37 *C

Now, try to run your system using the library that I have provided to check that your system works and then play around with the library that you own.

Yes, many thanks for helping, I believe that the attached examples of the I2CDevLib are buggy, at least for Arduino, except the one for the MPU6050_6AxisMotion20-one.

Further more I discovered some electrical flaws in my project.

Regard this problem as solved.

Good night and thanks again.

You are welcomed.