I've been trying to get the MPU-6050 accelerometer/gyro to work with an Arduino Uno using the I2C protocol. The I2C Scanner script recognizes the board (GY-521 if I'm not mistaken, the name isn't on the board but the layout looks exactly the same) but if I try to read the data using the MPU6050_raw script (from this library), all data are zeroes.
I've tried using a logic level converter inbetween the data pins (SCL and SDA) but then the board doesn't even get recognized by the scanner script.
I've tried using the 5V pin aswell as the 3V3 pin on the Arduino, both to no avail. The LED on the sensor lights at both voltages though.
I'm at a loss here and feel like I've tried everything. I feel like the sensor is broken, is there any way I can check this?
your MPU-6050 might be starting by default in sleep mode(i know mine does). Since you are getting the device address properly, that is a good thing. Try this:
(i haven't used i2c on arduino, but have used this module with raspberry pi, so send these commands looking at the i2c reference)
Initialize i2c with mpu-6050 address(0x68 if you haven't connected anything to the address pin/ default address)
Read register 65
Read register 66
Print the values in serial monitor
Write byte 0 to the register 107
Read register 65
Read register 66
Print the values in serial monitor
The first 2 values should come 0 and for the next 2 there should be some value !=0; writing byte 0 to 107 reg(pw reg 1) makes the mpu6050 get out of sleep mode if it is in there and then you can read values(65 and 66 regs are for temperature sensor in the device). If this doesn't work then there is some other problem with your device.
Thanks for your response.
I'm afraid the sleep mode shouldn't be the issue. I've tried multiple sketches and i think most of them had code that disabled sleep mode. This sketch for examples includes a few lines in the setup that should disable sleep mode right?
Tomorrow I'll receive another board, hopefully I don't run into these problems with that one. I'll update here then.
Jimmmz:
Thanks for your response.
I'm afraid the sleep mode shouldn't be the issue. I've tried multiple sketches and i think most of them had code that disabled sleep mode. This sketch for examples includes a few lines in the setup that should disable sleep mode right?
Tomorrow I'll receive another board, hopefully I don't run into these problems with that one. I'll update here then.
Yep, the sketch you linked has everything with proper setup if there are no changes in the mpu-6050 module, what is the mpu-6050 address that you can see on i2c?
you don't level converter nor do you need pull up resisters with the GY-521
the onboard 3.3V regulator is connected to the scl and sda pins through pull up resisters.
The only pin you need to be careful with is the AD0 pin
attach VCC to 5V and attach SCL and SDA to the arduino directly
also connect the int pin to pin 2 if you want to use the Digital Motion Processing on board with the MPU6050
Attached is the I2c Scanner to check connections
the MPU6050_Latest_Code.ino (of mine works great requires pin 2 and INT to be connected)
use the calibration code to get offsets to use in the "latest code" sketch to compensate for manufacturing differences
Latest Code uses the following library