I'm trying to use an MPU-6050 with the Arduino library and not having a lot of luck. I've read similar threads here but none have resolved my issue. I have it wired correctly with 5v to the GY512 board, letting the onboard 3.3v regulator supply the chip. I have the I2C outputs going through a bi-directional level shifter before connection to the Arduino UNO I2C pins. When I run the I2C scanner it comes up with:
I2C Scanner
Scanning...
I2C device found at address 0x68 !
done
So it appears the I2C is working as it should and it finds the MPU 6050 at the expected default address (0x68).
However, when do the "WHOAMI" test (6050 register 0x75), it comes back with 0x98, not 0x68. This seriously screws up most of the sample sketches which are looking for a 0x68 response and enter into a fault mode if they don't find it. It's possible the 6050 libraries also do this check, because most of the sketches using the 6050 library don't work either.
The 6050 does indeed appear to be at 0x68 since I can talk to it there and get some sort of reasonable looking data back. Sketches that assume it's at 0x68 and talk directly to it without using 6050 libraries seem to yield numbers that respond in the way you might predict when the 6050 is rotated.
0x68 (1101000) and 0x98(100011000) don't seen to have a simple relationship other than having the 4 LSB the same.
Is it possible I have a bad (clone) MPU 6050? I have no idea how it generates it's WHOAM! response. The datasheet isn't a lot of help...
This register is used to verify the identity of the device.
The contents of WHO_AM_I are the upper 6 bits of the MPU-60X0’s 7-bit I2C address.
The least significant bit of the MPU-60X0’s I2C address is determined by the value of the AD0 pin. The value of the AD0 pin is not reflected in this register.
Description:
The default value of the register is 0x68.
Bits 0 and 7 are reserved. (Hard coded to 0)
According to that (Bit 0 and Bit 7 hard coded to zero), you can't get a 0x98 response!
Has anyone heard a 6050 acting in this way?I can't really think of any other explanation for WHOAMI returning the wrong address.
I was getting very frustrated with nothing working right until I looked at the WHOAMI response.
Here's the WHOAMI code:
#include <Wire.h>
#define MPU6050_I2C_ADDRESS 0x68 // Default MPU-6050 address
#define MPU6050_WHO_AM_I 0x75 // R Who am I address
void setup()
{
Wire.begin(); // Initiate wire library
Serial.begin(9600); // Initiate serial port
WhoAmI(); // Verifies identity of device
}
void loop()
{
//blank
}
void WhoAmI(){
uint8_t waiByte; // Data will go here
MPU6050_Read(MPU6050_WHO_AM_I, &waiByte); // Get data
Serial.print(F("Device WhoAmI reports as: 0x")); //
Serial.println(waiByte,HEX); // Report WhoAmI data
}
void MPU6050_Read(int address,uint8_t *data){ // Read from MPU6050. Needs register address, data array
int size = sizeof(*data); //
Wire.beginTransmission(MPU6050_I2C_ADDRESS); // Begin talking to MPU6050
Wire.write(address); // Set register address
Wire.endTransmission(false); // Hold the I2C-bus
Wire.requestFrom(MPU6050_I2C_ADDRESS, size, true); // Request bytes, release I2C-bus after data read
int i = 0; //
while(Wire.available()){ //
data[i++]=Wire.read(); // Add data to array
}
}
and here's what I get back
Device WhoAmI reports as: 0x98