MPU6050, not detecting mpu?

So, this is the 1st time I’m using a MPU6050. I want to control a servo via an mpu6050 First I decided to look at the examples and try one of them out before even attempting to write the code to control the servo.
Here it is:

/*
    MPU6050 Triple Axis Gyroscope & Accelerometer. Simple Gyroscope Example.
    Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
    GIT: https://github.com/jarzebski/Arduino-MPU6050
    Web: http://www.jarzebski.pl
    (c) 2014 by Korneliusz Jarzebski
*/


#include <Wire.h>
#include <MPU6050.h>


MPU6050 mpu;


void setup() 
{
  Serial.begin(115200);


  // Initialize MPU6050
  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(500);
  }
  
  // If you want, you can set gyroscope offsets
  // mpu.setGyroOffsetX(155);
  // mpu.setGyroOffsetY(15);
  // mpu.setGyroOffsetZ(15);
  
  // Calibrate gyroscope. The calibration must be at rest.
  // If you don't want calibrate, comment this line.
  mpu.calibrateGyro();


  // Set threshold sensivty. Default 3.
  // If you don't want use threshold, comment this line or set 0.
  mpu.setThreshold(3);
  
  // Check settings
  checkSettings();
}


void checkSettings()
{
  Serial.println();
  
  Serial.print(" * Sleep Mode:        ");
  Serial.println(mpu.getSleepEnabled() ? "Enabled" : "Disabled");
  
  Serial.print(" * Clock Source:      ");
  switch(mpu.getClockSource())
  {
    case MPU6050_CLOCK_KEEP_RESET:     Serial.println("Stops the clock and keeps the timing generator in reset"); break;
    case MPU6050_CLOCK_EXTERNAL_19MHZ: Serial.println("PLL with external 19.2MHz reference"); break;
    case MPU6050_CLOCK_EXTERNAL_32KHZ: Serial.println("PLL with external 32.768kHz reference"); break;
    case MPU6050_CLOCK_PLL_ZGYRO:      Serial.println("PLL with Z axis gyroscope reference"); break;
    case MPU6050_CLOCK_PLL_YGYRO:      Serial.println("PLL with Y axis gyroscope reference"); break;
    case MPU6050_CLOCK_PLL_XGYRO:      Serial.println("PLL with X axis gyroscope reference"); break;
    case MPU6050_CLOCK_INTERNAL_8MHZ:  Serial.println("Internal 8MHz oscillator"); break;
  }
  
  Serial.print(" * Gyroscope:         ");
  switch(mpu.getScale())
  {
    case MPU6050_SCALE_2000DPS:        Serial.println("2000 dps"); break;
    case MPU6050_SCALE_1000DPS:        Serial.println("1000 dps"); break;
    case MPU6050_SCALE_500DPS:         Serial.println("500 dps"); break;
    case MPU6050_SCALE_250DPS:         Serial.println("250 dps"); break;
  } 
  
  Serial.print(" * Gyroscope offsets: ");
  Serial.print(mpu.getGyroOffsetX());
  Serial.print(" / ");
  Serial.print(mpu.getGyroOffsetY());
  Serial.print(" / ");
  Serial.println(mpu.getGyroOffsetZ());
  
  Serial.println();
}


void loop()
{
  Vector rawGyro = mpu.readRawGyro();
  Vector normGyro = mpu.readNormalizeGyro();


  Serial.print(" Xraw = ");
  Serial.print(rawGyro.XAxis);
  Serial.print(" Yraw = ");
  Serial.print(rawGyro.YAxis);
  Serial.print(" Zraw = ");
  Serial.println(rawGyro.ZAxis);


  Serial.print(" Xnorm = ");
  Serial.print(normGyro.XAxis);
  Serial.print(" Ynorm = ");
  Serial.print(normGyro.YAxis);
  Serial.print(" Znorm = ");
  Serial.println(normGyro.ZAxis);
  
  delay(10);
}

The serial monitor is stuck at “Could not find a valid MPU6050 sensor, check wiring!”
I’ve checked with my DMM the resistance between the pin on the mega2560 and the SDA and SCL pins and they both read <5ohms.
The code is fine due to it being an example and the wiring is fine due to measuring the resistance between the connections. Could the problem be that the wires are too long?
To put into context:
(~1m, this is due for it being attached to the end of a robot arm, this is the last part of coding that I need to finish my project, I’m creating a new thread because, this does not relate to any other part of the project.)

I tested it with my Arduino micro and still the same result.
I realize that this is a silly question, but it has me stumped…

Also, could someone explain what this segment means? I assume this is the cause?

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

You should run the I2cScanner sketch and see what it thinks is on the bus.

Where does the 3.3V 5V level shift for all the MPU pins happen?

blh64:
You should run the I2cScanner sketch and see what it thinks is on the bus.

I ran an I2c scanner, and it says that it detects nothing.
For this project I'm going to exclude the MPU, and just use the other servo for angle reference.
I assume that it is all in the wiring somehow...
Nevertheless this problem must be resolved. I'll test it again on a breadboard and report back later on to see if the MPU is in good shape.

Whandall:
Where does the 3.3V 5V level shift for all the MPU pins happen?

I just plugged the SDA and SCL directly into the mega A4 and A5. If I indeed need a level shifter for it to work, I will do what I stated above and just use the other servo as reference. I have spent enough money on this project already.
Like I said, it is my 1st time using the mpu, I am also still in the process of learning how to use Arduino (learning as I go).

thanks
if this message is duplicating, I got a timeout error while posting...

You have to look at the exact part you purchased. Some modules tolerate 3.3V to 5V for Vin, others only can handle 3.3V. This impacts the i2c as well.

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