MPU6050 SparkFun Breakout to Arduino Uno - No Communication

To whom it may concern, First-off, thank you for taking the time and reading this. I am doing a school project that will keep a servo level by using an MPU6050 SparkFun Break out board. I am developing this by first experimenting through an Arduino UNO and, in the future, planing to connect it to a ProMini. My problem is that the MPU6050 is not producing any readings when connected (directly) to the UNO. Connections: MPU6050 - Arduino UNO VDD - 3.3V GND - GND INT - DIGITAL 2 SCL - A5 SDA - A4

I am using code and libraries from here: https://github.com/jrowberg/i2cdevlib/tree/master/MPU6050 And have also received an MPU_Test code from Jeff to basically test for the WHO_AM_I Register which worked for him.

These are the reading I get in the Serial Monitor when trying the DMP6, RAW, & MPU_TEST examples respectively: [u]DMP[/u]

o 0...
d flag...
.


Resetting MPU6050...?H
2
g
?H
2
g
i
êbG¤õ    êi
Checking hardware revision...
Revision @ user[16][6] = 0
Resetting m        êi
Reading OTP bank valid flag...
OTP bank is valid!

1
1
1




1929
ERROR! DMP code veri??H

[u]RAW:[/u]

Initializing I2C devices...
Testing device connections...
MPU6050 connection failed
a/g:    0   0   0   0   0   0
a/g:    0   0   0   0   0   0
a/g:    0   0   0   0   0   0
a/g:    0   0   0   0   0   0
a/g:    0   0   0   0   0   0
a/g:    0   0   0   0   0   0
a/g:    0   0   0   0   0   0
a/g:    0   0   0   0   0   0

[u]MPU_Test:[/u]

I2C bus connected.
Checking WHO_AM_I register contents: 0xFF
Disabling sleep mode...
-1  -1  -1  -1  -1  -1
-1  -1  -1  -1  -1  -1
-1  -1  -1  -1  -1  -1
-1  -1  -1  -1  -1  -1
-1  -1  -1  -1  -1  -1

I have spoken to SarkFun, Jeff, and got an ADXL345 to test the I2C connection on the UNO (which worked). After thinking that it was a faulty MPU, I received another one (tested at SparkFun's location). Note: From what I know, Jeff tested the MPU on a MEGA1280 and an veal board from InvenSense. I really appreciate your help. Thank you,

Roman

That breakout board is this one right http://www.sparkfun.com/products/11028 ??

It cannot be directly connected to the Uno, its a 3.3V board. You may have fried it.

Ya I had the same issue with the MPU6000 and an UNO except SPI. I was able to get away with some low resistance voltage dividers to bring the voltage down to 3.3 V. You probably didn't fry it though since I believe it can handle 5V on the data lines. I would also try tieing VIO to VDD if you have the sparkfun breakout board.

Just plugged it in and it works with the Uno at 5V I2C... I thought it wouldn't but then again I never really looked at the datasheet. I was using the latest I2C dev library off of github, using example code raw data, pin connections SCL-A5 SDA-A4 GND-GND VDD-3.3V VIO-3.3V, make sure the serial monitor is at 38400 and you should see streaming data. Good luck!

taylorapgar: Ya I had the same issue with the MPU6000 and an UNO except SPI. I was able to get away with some low resistance voltage dividers to bring the voltage down to 3.3 V. You probably didn't fry it though since I believe it can handle 5V on the data lines. I would also try tieing VIO to VDD if you have the sparkfun breakout board.

inputs have to be between -0.5V and Vdd+0.5V, not 5V compatible. resistive dividers or level shifter needed.

I think that I’m having the same no communication problem. I’m using an Arduino Duemilanove. I get the same error:
MPU6050 connection failed
a/g: 0 0 0 0 0 0

I’m not using any resistors.

I think that the problem might be with my installation of the mpu6050 library.
I’ve noticed that when I import the mpu6050 library the mpu6050 part stays black. Whereas the all the other libraries’ text turns red.
For example
#include <MPU6050.h>
instead of
#include <I2Cdev.h>

Once I accidentally configured USER_CONFIG register to disable I2C, while using I2C, and then the MPU never responded, kind of like what you appear to show.

You need pull-up resistors, probably should disable the internal 5V resistors and use your own 4K7 resistors to 3.3V

I finally got around to using the external 4k7 Ohm resistors. I still get the same error. I'm using the same code as the original poster so I don't know if it has anything to do with USER CONFIG. I think that I'm making some noob mistake with the installation of the library. Out of all of my libraries the MPU6050 doesn't red text where all the others do.

chazm, did you check this link?

http://www.i2cdevlib.com/devices/mpu6050#help

Thank you mixx. I checked out the link and I think that it's a step closer to the solution. From the link the problem that I'm having the solution to the problem are posted:

I connected my MPU-6050 breakout board and it seems to be responding correctly, but all I get are zeros from the accel/gyro sensor registers! What's wrong? This is a very common problem, and fortunately one that is very easy to fix. When the device powers on, it starts up in sleep mode, which must be explicitly disabled in order to begin normal operations. To do this, simply write a 0 to the PWR_MGMT_1 (0x6B) register. If you are using the I2Cdev MPU6050 class, calling device.setSleepEnabled(false) will set the correct bit for you.

I didn't know how to use the command: calling device.setSleepEnabled(false)

So I decided to write 0 to PWR_MGMT_1 (0x6B) 0x6B turns out to be 107 in decimal so i added the following code to void setup(); Wire.beginTransmission(107); Wire.send(0); Wire.endTransmission();

I still get the same error, but when I looked at the registry map for the mpu6050, I notice that bit number 6 of 0x6B controls the sleep settings. I think that I just need to write 0 to that individual bit. I don't know how to do this yet, I'm still searching to figure out how to write this individual bit instead of the whole PWR_MGMT_1. Thanks again mixx for setting me in the right direction.

Hi.

I was having the same problem, but finally found the solution.
Forget about resistors, what you need to do with SparkFun’s MPU-6050 is to connect the VIO pin to the same 3.3v supply that VDD is connected to.

The sleep settings in SparkFun’s board are correct from default, so you don’t need to change the sleep bit value.

Also the I2C bus is a bit tricky, you must write the registry address you want to write to or read from to the I2C address which is 0x68 by default, and then do the Wire.requestFrom to this address.

VDD ----> 3.3v
GND ----> GND
SDA ----> A4
SCL ----> A5
VIO ----> 3.3v (same VDD supply)

And you are ready to go, the following code should read the WHO AM I registry with a 0x68 output.

#include <Wire.h>

#define MPU6050_WHO_AM_I    0x75  
#define MPU6050_I2C_ADDRESS 0x68  //The I2C default address for MPU-6050

void setup() {
  
  Serial.begin(9600);
  Wire.begin();
    
  Serial.println("Who am i?");
  
  //This part, tells the I2C default address you want to read from
  //MPU6050_WHO_AM_I registry
  Wire.beginTransmission(MPU6050_I2C_ADDRESS);
  Wire.write(MPU6050_WHO_AM_I);
  Wire.endTransmission(false);

  //You read the data in MPU6050_WHO_AM_I registry through I2C default
  //address, set in the previous step.
  Wire.requestFrom(MPU6050_I2C_ADDRESS, 1, true);
  while(Wire.available()) { 
    Serial.print("0x");
    Serial.println(Wire.read(), HEX);
  }
}

void loop() {
}

I’m starting to think that my sensor may actually be broken. I tried your code Obakemono, and all I saw on the Serial Monitor was:

Who am i?
Who am i?

I think that I may have broken it by not using resistors when I first got the device. I didn’t use resistors for about a couple weeks, then I hooked up 4k7s on the I2C lines.

No resistors are needed if you power the board with 3.3v.
I have had it running with 5v by mistake for a while and it isn’t fried.

¿Can you post a picture of your wiring please?
I’ll do the same in a couple of hours, i can’t right now.

I’m having the same problem as you. I’ve loaded Obakemono code on my duemilanove nano, wiring just like you said, only my board has different pins, actualy has a 5v pin, 3.3v, GNd, SCL, SDA, INT.
Everithing should work but I only see “who am I?” on the serial monitor.

just looking at the code, the addres shoul be x68 or x6B???

The mpu 6050 is connected to an Arduino Duemilanove through a SparkFun ProtoShield.
The VDD and VIO are connected together with the yellow wire and then to the 3.3v.
The Gnd is connected to the CLK and they are then both grounded with a grey wire.
The SCL is connected to Analog pin5 through a 4k7 Ohm resistor.
The SDA is connected to Analog pin4 through a 4k7 Ohm resistor.
INT is connected to Digital pin2.

Ok, I’ve made some progress.
I Found the code for a I2C Scanner, the problem is that the library twi.h was updated so I’ve added some code there to make it work. Here It is

/**

*/

#include “Wire.h”
extern “C” {
#include “utility/twi.h” // from Wire library, so we can do bus scanning
}

// Scan the I2C bus between addresses from_addr and to_addr.
// On each address, call the callback function with the address and result.
// If result==0, address was found, otherwise, address wasn’t found
// (can use result to potentially get other status on the I2C bus, see twi.c)
// Assumes Wire.begin() has already been called
void scanI2CBus(byte from_addr, byte to_addr,
void(*callback)(byte address, byte result) )
{
byte rc;
byte data = 0; // not used, just an address to feed to twi_writeTo()
for( byte addr = from_addr; addr <= to_addr; addr++ ) {
rc = twi_writeTo(addr, &data, 0, 1, 0);
callback( addr, rc );
}
}

// Called when address is found in scanI2CBus()
// Feel free to change this as needed
// (like adding I2C comm code to figure out what kind of I2C device is there)
void scanFunc( byte addr, byte result ) {
Serial.print(“addr: “);
Serial.print(addr,DEC);
Serial.print( (result==0) ? " found!”:” “);
Serial.print( (addr%4) ? “\t”:”\n");
}

byte start_address = 1;
byte end_address = 200;

// standard Arduino setup()
void setup()
{
Wire.begin();

Serial.begin(19200);
Serial.println("\nI2CScanner ready!");

Serial.print(“starting scanning of I2C bus from “);
Serial.print(start_address,DEC);
Serial.print(” to “);
Serial.print(end_address,DEC);
Serial.println(”…”);

// start the scan, will call “scanFunc()” on result from each address
scanI2CBus( start_address, end_address, scanFunc );

Serial.println("\ndone");
}

// standard Arduino loop()
void loop()
{
// Nothing to do here, so we’ll just blink the built-in LED
digitalWrite(13,HIGH);
delay(300);
digitalWrite(13,LOW);
delay(300);
}

ok, this scan tell me that my device it’s actually in the por 105, meaning, 0x69 not 0x68. Now I need to make everithing else work, but it’s a start.

Ah, another thing, My board can be suplied with 5v or 3.3v, it’s the same thing, but you need the pullup resistors to 3.3v to make it work, otherwise the scan doesn’t detect the device. Douh!!

now I need a nice piece of code thar takes all the raw data and sends it back to me :wink: over serial.

ok, noy I want to use this code

// 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 GitHub - jrowberg/i2cdevlib: I2C device library collection for AVR/Arduino or other C++-based MCUs
//
// Changelog:
// 2011-10-07 - initial release

/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2011 Jeff Rowberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*/

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include “Wire.h”

// 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
#include “I2Cdev.h”
#include “MPU6050.h”

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

#define LED_PIN 13
bool blinkState = false;

void setup() {
// join I2C bus (I2Cdev library doesn’t do this automatically)
Wire.begin();

Serial.begin(9600);

// initialize device
Serial.println(“Initializing I2C devices…”);
accelgyro.initialize();

// verify connection
Serial.println(“Testing device connections…”);
Serial.println(accelgyro.testConnection() ? “MPU6050 connection successful” : “MPU6050 connection failed”);

// configure Arduino LED for
pinMode(LED_PIN, OUTPUT);
}

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(“a/g:\t”);
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");
Serial.println(gz);

// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}

from https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/Examples/MPU6050_raw/MPU6050_raw.ino

but I don’t know how to change the address to 0x69. any ideas?

I ran the port scanner code. None of my ports were found. Does that mean that my chip is fried?

I2CScanner ready! starting scanning of I2C bus from 1 to 200... addr: 1 addr: 2 addr: 3 addr: 4 addr: 5 addr: 6 addr: 7 addr: 8 addr: 9 addr: 10 addr: 11 addr: 12 addr: 13 addr: 14 addr: 15 addr: 16 addr: 17 addr: 18 addr: 19 addr: 20 addr: 21 addr: 22 addr: 23 addr: 24 addr: 25 addr: 26 addr: 27 addr: 28 addr: 29 addr: 30 addr: 31 addr: 32 addr: 33 addr: 34 addr: 35 addr: 36 addr: 37 addr: 38 addr: 39 addr: 40 addr: 41 addr: 42 addr: 43 addr: 44 addr: 45 addr: 46 addr: 47 addr: 48 addr: 49 addr: 50 addr: 51 addr: 52 addr: 53 addr: 54 addr: 55 addr: 56 addr: 57 addr: 58 addr: 59 addr: 60 addr: 61 addr: 62 addr: 63 addr: 64 addr: 65 addr: 66 addr: 67 addr: 68 addr: 69 addr: 70 addr: 71 addr: 72 addr: 73 addr: 74 addr: 75 addr: 76 addr: 77 addr: 78 addr: 79 addr: 80 addr: 81 addr: 82 addr: 83 addr: 84 addr: 85 addr: 86 addr: 87 addr: 88 addr: 89 addr: 90 addr: 91 addr: 92 addr: 93 addr: 94 addr: 95 addr: 96 addr: 97 addr: 98 addr: 99 addr: 100 addr: 101 addr: 102 addr: 103 addr: 104 addr: 105 addr: 106 addr: 107 addr: 108 addr: 109 addr: 110 addr: 111 addr: 112 addr: 113 addr: 114 addr: 115 addr: 116 addr: 117 addr: 118 addr: 119 addr: 120 addr: 121 addr: 122 addr: 123 addr: 124 addr: 125 addr: 126 addr: 127 addr: 128 addr: 129 addr: 130 addr: 131 addr: 132 addr: 133 addr: 134 addr: 135 addr: 136 addr: 137 addr: 138 addr: 139 addr: 140 addr: 141 addr: 142 addr: 143 addr: 144 addr: 145 addr: 146 addr: 147 addr: 148 addr: 149 addr: 150 addr: 151 addr: 152 addr: 153 addr: 154 addr: 155 addr: 156 addr: 157 addr: 158 addr: 159 addr: 160 addr: 161 addr: 162 addr: 163 addr: 164 addr: 165 addr: 166 addr: 167 addr: 168 addr: 169 addr: 170 addr: 171 addr: 172 addr: 173 addr: 174 addr: 175 addr: 176 addr: 177 addr: 178 addr: 179 addr: 180 addr: 181 addr: 182 addr: 183 addr: 184 addr: 185 addr: 186 addr: 187 addr: 188 addr: 189 addr: 190 addr: 191 addr: 192 addr: 193 addr: 194 addr: 195 addr: 196 addr: 197 addr: 198 addr: 199 addr: 200

done

Check your wiring once more. AD0 must be connected to ground or 3.3V (with solder jumper). Connect it to ground for I2C address 0x68. SCL and SDA are connected directly to the Arduino, but you could add extra pull-up resistors to the 3.3V. The resistors could be 4k7 or 10k (the board already has 10k pull-up resistors, but I prefer 4k7). You don't need the INT, you could leave it open. The CLKIN and FSYNC can be tied to ground, because they are not used.

If you have all this, the scanner sketch should be able to find it.

I'm confused ! Is this crossposting ? http://arduino.cc/forum/index.php/topic,111698.0.html If you bought a new sensor module, and started a new topic, you should have mentioned at the beginning that you made this posting before. It's okay, as long as you let us know.

This is my wiring, all direct connections, no resistors. The simplest wiring possible i think.

VDD ----> 3.3v
GND ----> GND
SDA ----> A4
SCL ----> A5
VIO ----> 3.3v (same VDD supply)

chazm try this exactly this wiring, take out the resistors, and try to disconnect not mentioned pins.
I may be wrong about the sleep bit, so this is a little more complex code which solves that, it should output accelerometer x values.

This is a video of me executing this code.

#include <Wire.h>

#define MPU6050_ACCEL_XOUT_H  0x3B
#define MPU6050_ACCEL_XOUT_L  0x3C
#define MPU6050_ACCEL_YOUT_H  0x3D
#define MPU6050_ACCEL_YOUT_L  0x3E
#define MPU6050_ACCEL_ZOUT_H  0x3F
#define MPU6050_ACCEL_ZOUT_L  0x40
#define MPU6050_GYRO_XOUT_H   0x43
#define MPU6050_GYRO_XOUT_L   0x44
#define MPU6050_GYRO_YOUT_H   0x45
#define MPU6050_GYRO_YOUT_L   0x46
#define MPU6050_GYRO_ZOUT_H   0x47
#define MPU6050_GYRO_ZOUT_L   0x48
#define MPU6050_PWR_MGMT_1    0x6B

#define MPU6050_I2C_ADDRESS   0x68

uint16_t ax, ay, az, gx, gy, gz;

void setup() {
  uint8_t c = 0;
  
  Serial.begin(9600);
  Wire.begin();
  
  MPU6050_write(MPU6050_PWR_MGMT_1, &c, 1); //Stop device from reseting/sleeping

  Serial.println("START");
}

void loop() {
  
  ax = calculate_value(MPU6050_ACCEL_XOUT_H, MPU6050_ACCEL_XOUT_L, 1);
  ax = (ax-32500)/8.192;
  
  Serial.println(ax);
}

uint16_t calculate_value(int address_h, int address_l, int size) {
  
  uint8_t hi, lo;
  uint16_t value;
  
  hi = MPU6050_read(address_h, size);
  lo = MPU6050_read(address_l, size);
  
  value = ((hi)<<8);
  value |= lo;
  
  return(value);
  
}

uint8_t MPU6050_read(int address, int size) {
  
  uint8_t value;
  
  Wire.beginTransmission(MPU6050_I2C_ADDRESS);
  Wire.write(address);
  Wire.endTransmission(false);

  Wire.requestFrom(MPU6050_I2C_ADDRESS, size, true);
  while(Wire.available()) {
    value = Wire.read();
  }
  
  return (value);
}

int MPU6050_write(int address, uint8_t *data, int size) {
  
  Wire.beginTransmission(MPU6050_I2C_ADDRESS);
  
  Wire.write(address);        // write the start address

  Wire.write(data, size);  // write data bytes

  Wire.endTransmission(true); // release the I2C-bus
  
  return (0);         // return : no error
}