Connecting the MPU6050 via I2C

Hey there,
first: I havent spooken English in a while, but I need to solve this problem fast so I am counting on you english speaking people. =)

I am trying to use a MPU 6050 GY-521 Breakoutboard with my Arduino Uno to record Accelerations and save them on a SD-Card, but the common I2C scanner (code below) does not find the Accelerometer and the code linked below only gives nearly constant values for "DEL", alternating values for the acceleration and steady increasing values for "GYR" and "FIL".

I connected the board as following:

  • VCC <-> 3,3V (tried 5V aswell)
  • GND <-> GND
  • SCL <-> A5 (tried the SCL & SDA connections near the USB Port too)
  • SDA <-> A4
  • AOD <-> GND
  • INT <-> D2

http://www.geekmomprojects.com/?wpdmact=process&did=Mi5ob3RsaW5r

#include <Wire.h>


void setup()
{
  Wire.begin();

  Serial.begin(9600);
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ ) 
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4) 
    {
      Serial.print("Unknow error at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

While making this Picture of my Breakoutboard for you guys an idea came to my mind. Could it be, that I have to solder the pins into the board for the needed solid contact? Would be a problem, because I dont have a soldering iron at hand....

Thanks for reading and hopefully your suggestions =)

Greetings,
Max

Try my multispeed scanner - MultiSpeed I2C Scanner - 50,100,200,400 KHz. - Libraries - Arduino Forum -
it could be that the sensor only works at 100 KHZ?

And as always it is good to triple check the wiring...

Yes, it would be better to solder it. Or you can use this:

The address of the MPU6050 is 0x68 or 0x69, depending on your module supplier.

Hey!
thanks for you help guys and sorry for me not answering.
I bought a solderingiron yesterday and now the connection works flawlessly with ADO hanging and on 0x68.
As a thanks I will post my for now final code here, it might be an inspiration for slow people like me...

/* ============================================
Code by Max B. 06.07.2014 written for Arduino Uno R3 building up on the I2C library and example code and the ReadWriteSDdFat Library and example code.
No copyrights are claimed.
===============================================*/

/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 10/7/2011 by Jeff Rowberg <jeff@rowberg.net>

SD Library created   Nov 2010 by David A. Mellis, updated 2 Dec 2010 by Tom Igoe and modified by Bill Greiman 11 Apr 2011
The example code is in the public domain.
===============================================*/

//-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-MPU Init-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X
// 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
//Pins:  SCL - A5  SDA - A4  INT - D2    XDA,XCL,ADO hanging
    #include "I2Cdev.h"
    #include "MPU6050.h"
    // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation is used in I2Cdev.h
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    #include "Wire.h"
    #endif
    MPU6050 accelgyro;
    int16_t ax, ay, az;
//-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-SD-Writer Init-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X
//Pins:  MOSI -resistor- D11    MISO - D12    CLK -resistor- D13    CS -resistor- D4    5V,W/P,C/D hanging

    const int chipSelect = 10;
    #include <SdFat.h>
    SdFat sd;
    SdFile myFile;
//-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X
     int i=0;
     long startupmillis;
     long time;

void setup() {
    // join I2C bus (I2Cdev library doesn't do this automatically)
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif

    Serial.begin(38400);
    
          /*while (!Serial) {
          } 
          Serial.println("Type RAKATA to start");
          while (Serial.read() <= 0) {
          }
          delay(400);  // catch Due reset problem
          */
    
    // initialize Accelerometer
    Serial.println("Initializing accelerometer connection...");
    accelgyro.initialize();
    accelgyro.setFullScaleAccelRange(MPU6050_ACCEL_FS_8);
    // verify connection
    Serial.println("Testing connection...");
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
   // initialize SD-Card
    Serial.println("Initializing Connection to SD-Card...");
    if (!sd.begin(chipSelect, SPI_FULL_SPEED)){
      sd.initErrorHalt();
    }
    else{
    Serial.println("Connection seems to be okay.");
    } 
    if (!myFile.open("datalog.txt", O_RDWR | O_CREAT | O_AT_END)) {
       sd.errorHalt("SD Karte entfernt!");
    }
    Serial.println("Starting measurements...");
    startupmillis = millis();
    
    // use the code below to change accel/gyro offset values
    /*
    Serial.println("Updating internal sensor offsets...");
    accelgyro.setXAccelOffset(335);
    accelgyro.setYAccelOffset(-5631);
    accelgyro.setZAccelOffset(2250);
    Serial.print(accelgyro.getXAccelOffset()); Serial.print("\t"); // 335
    Serial.print(accelgyro.getYAccelOffset()); Serial.print("\t"); // -5631
    Serial.print(accelgyro.getZAccelOffset()); Serial.print("\t"); // 2250
    Serial.print("\n");
    */
}

void loop() {
  
  if(i==100){ myFile.sync(); i=0;}
  
  accelgyro.getAcceleration(&ax, &ay, &az);
  time = millis() - startupmillis;
  
  //Serial.print("t,ax,ay,az:\t");
  //Serial.print(time); Serial.print("\t");
  //Serial.print(ax); Serial.print("\t");
  //Serial.print(ay); Serial.print("\t");
  //Serial.println(az);
  
  myFile.print("t,ax,ay,az:\t");
  myFile.print(time); myFile.print("\t");
  myFile.print(ax); myFile.print("\t");
  myFile.print(ay); myFile.print("\t");
  myFile.println(az);        
  i++;
}

...and because there is always room for some improvement if some cross your mind =)

Room for improvement: buy another MPU-6050. This one has been connected to 5V and is no longer reliable :blush:

Peter_n:
Room for improvement: buy another MPU-6050. This one has been connected to 5V and is no longer reliable :blush:

What makes you think so? :astonished: I heard from a lot of people who connected their MPU6050 Breakoutobard to 5V because it was more reliable than 3.3V and mine seems to be alright too, atleast the accelerometer data which I need.
But that could explain a strange observation of mine XD
Somewhere I read with an Arduino and the normal libs you cant expect more than 100 values per second, but I am getting more than 300 per second. I must have overclocked the Chip :stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue: (Just a joke... I guess).

You are right ! Sorry, I forgot about the onboard voltage regulator.
The photo of the board shows an onboard voltage regulator.
It is indeed better to use 5V with that. The MPU-6050 will run at a good 3.3V from the onboard voltage regulator. Using 3.3V makes the output of the onboard voltage regulator about 3.2V, which could result into a less good I2C communication.