And here is some photos of what I have done: (as you see I have glued the two boards to each other using hot glue.
I checked every connection with my multimeter and there weren’t any shorts between pins, and all 4 connections between arduino and GY-521 were okay. But when I measured resistance between SCL and SDA (A4 and A5 on arduino board), it showed 4.4 kilo ohms, which I guess it should be like what it is.
Also another example sketch from GY-521 library would give me such an error: couldn’t connect to GY-521.
Try adding 4.7K pullup resistors from SDA and SCL to 3.3V.
It has been reported that the voltage regulator on some of those MPU-6050 modules is intended for use with a 5V supply and is not low dropout, so the MPU-6050 supply voltage may be too low.
You may need to remove it and bypass it. If you do, BE SURE to connect the module and the processor to regulated 3.3V, not directly to the battery.
Other possibilities include defective module and one or more bad connections.
Finally, the posted code would not read out the module correctly in any case. The gyro values are all wrong, because the gyro "X" value would in fact be a temperature value.
Try this instead:
// MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
const int MPU_addr = 0x68; // I2C address of the MPU-6050
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
void setup() {
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 14, true); // request a total of 14 registers
int t = Wire.read();
AcX = (t << 8) | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
t = Wire.read();
AcY = (t << 8) | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
t = Wire.read();
AcZ = (t << 8) | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
t = Wire.read();
Tmp = (t << 8) | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
t = Wire.read();
GyX = (t << 8) | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
t = Wire.read();
GyY = (t << 8) | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
t = Wire.read();
GyZ = (t << 8) | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
t = Wire.read();
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp / 340.00 + 36.53); //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);
delay(333);
}
jremington:
Try adding 4.7K pullup resistors from SDA and SCL to 3.3V.
It has been reported that the voltage regulator on some of those MPU-6050 modules is intended for use with a 5V supply and is not low dropout, so the MPU-6050 supply voltage may be too low.
You may need to remove it and bypass it. If you do, BE SURE to connect the module and the processor to regulated 3.3V, not directly to the battery.
Other possibilities include defective module and one or more bad connections.
Finally, the posted code would not read out the module correctly in any case. The gyro values are all wrong, because the gyro "X" value would in fact be a temperature value.
Try this instead:
// MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
const int MPU_addr = 0x68; // I2C address of the MPU-6050
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
void setup() {
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 14, true); // request a total of 14 registers
int t = Wire.read();
AcX = (t << 8) | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
t = Wire.read();
AcY = (t << 8) | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
t = Wire.read();
AcZ = (t << 8) | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
t = Wire.read();
Tmp = (t << 8) | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
t = Wire.read();
GyX = (t << 8) | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
t = Wire.read();
GyY = (t << 8) | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
t = Wire.read();
GyZ = (t << 8) | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
t = Wire.read();
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp / 340.00 + 36.53); //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);
delay(333);
}
Thank you so much for your reply.
Right now I have only a few 100 ohm resistors, is it safe to use them as pullup resistors? (Temporary just to see if the pullup resistor solve the problem, I buy 4.7K ohm resistors tomorrow and if it doesn't solve the problem, I go to the next possible solution)
jremington:
Try adding 4.7K pullup resistors from SDA and SCL to 3.3V.
It has been reported that the voltage regulator on some of those MPU-6050 modules is intended for use with a 5V supply and is not low dropout, so the MPU-6050 supply voltage may be too low.
You may need to remove it and bypass it. If you do, BE SURE to connect the module and the processor to regulated 3.3V, not directly to the battery.
Other possibilities include defective module and one or more bad connections.
Finally, the posted code would not read out the module correctly in any case. The gyro values are all wrong, because the gyro "X" value would in fact be a temperature value.
Try this instead:
// MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
const int MPU_addr = 0x68; // I2C address of the MPU-6050
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
void setup() {
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 14, true); // request a total of 14 registers
int t = Wire.read();
AcX = (t << 8) | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
t = Wire.read();
AcY = (t << 8) | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
t = Wire.read();
AcZ = (t << 8) | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
t = Wire.read();
Tmp = (t << 8) | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
t = Wire.read();
GyX = (t << 8) | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
t = Wire.read();
GyY = (t << 8) | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
t = Wire.read();
GyZ = (t << 8) | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
t = Wire.read();
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp / 340.00 + 36.53); //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);
delay(333);
}
Hello. I just tried addidng pullup resistors, I connect one 4.7K ohm resistor to each of SDA and SCL pins and connected each resistor to 3.3V output of an regulator. (All components have common ground). And sadly it didn’t work and behaves like before.
As you said about the gy521 regulator, I have connected the gy521 to 5V, so how likely is that the regulator is causing the problem?
I have read that we should use a logic level converter with arduino uno and gy521, can it be the solution to my problem too? I’m using 5V arduino pro mini. (16MHz, 328P). Or if it’s not, would you suggest me to bypass the regulator or check for a bad connection?
If the MPU-6050 I2C or AD0 pins have ever been connected to 5V, the module may have been destroyed.
With a 5V Arduino, use a level shifter to connect to the module, or best, use a 3.3V Pro Mini with the sensor and connect the I2C pins directly. You still need pullup resistors connected to SDA and SCL.
bluejets:
Most of these gy521 I've ever used have 2k2 pullups already on the board.
(two surface mount 222 resistors adjacent to SCL)
I did notice this in your first post ........ But when I measured resistance between SCL and SDA (A4 and A5 on arduino board
You do know SDA is A4 and SCL is A5...??? your quote says back to front.
Wiring diagram too small and blurry to make out any detail.
Hello
Thank you for your reply
I tried connecting gy521 to an Arduino nano.
I connected nano to usb for power supply and for reading serial output.
Nano. Gy521
VIN. VCC
GND. GND
A5. SCL
A4. SDA
Just these connections and nothing else. But I still got t same output and I had the same problem.
My Gy521 has 2 2k2 resistors too.
I also tried adding extra pull-up resistors but it didn’t change anything.
Do you know if I have to use level shifter if I’m using a 5V arduino? Like a nano or a 5V pro mini. Because as I read in blogs and tutorials, it should be ok if I don’t use a level shifter with 5V pro mini or nano.
If the regulator is causing the problem, what is the pinout of the regulator so I know how to bypass it. I couldn’t figure it out. It is a 4B2X regulator. It has 5 pins, I measured their voltage, two of them were 0 volt, one of them was about 5 volts and two of them Were about 5.9 volts.
And this is a photo of this regulator but I don’t know which pin is what.
I had a similar issue. Try recasting your bit shift to uint_16 and recast the whole thing
_ax = (int16_t)(((int16_t)Wire.read() << 8 ) | Wire.read()) ; // ACCEL_XOUT_H ACCEL_XOUT_L
...do the same for the rest
I use this approach for NANO's and Teensy and it works. Maybe try this library?
Thanks a lot. I downloaded this library and added it to Arduino libraries, then I opened "C:\Users\erfan\Documents\Arduino\libraries\GY521-master\GY521.cpp" and changed these lines:
Did I do it right?
Then I uploaded "GY521_pitch_roll_yaw.ino" example to Arduino nano and this was the result:
18:38:27.595 -> 102 Could not connect to GY5
So I changed this line "GY521 sensor(0x69);" to "GY521 sensor(0x68); and this is the result:
18:40:06.036 -> CNT PITCH ROLL YAW
18:40:06.036 -> 680 nan nan 0.000
18:40:06.036 -> 681 nan nan 0.000
18:40:06.036 -> 682 nan nan 0.000
18:40:06.036 -> 683 nan nan 0.000
18:40:06.036 -> 684 nan nan 0.000
18:40:06.036 -> 685 nan nan 0.000
18:40:06.036 -> 686 nan nan 0.000
18:40:06.036 -> 687 nan nan 0.000
18:40:06.036 -> 688 nan nan 0.000
18:40:06.036 -> 689 nan nan 0.000
What I usually do first is confirming that the hardware connection between Arduino and I2C slave device is working. That can be done by this simple I2C scanner sketch from Nick Gammon.
// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011
#include <Wire.h>
void setup() {
Serial.begin (115200);
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 8; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
hmeijdam:
What I usually do first is confirming that the hardware connection between Arduino and I2C slave device is working. That can be done by this simple I2C scanner sketch from Nick Gammon.
// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011
#include <Wire.h>
void setup() {
Serial.begin (115200);
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Wire.begin();
for (byte i = 8; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
[Creative Commons Attribution 3.0 Australia License](https://creativecommons.org/licenses/by/3.0/au/)
Hello thank you for your reply. I bought a new mpu6050 and tested with another Arduino nano and still all the results are the same as before.
I couldn't find a logic level shifter or Arduino pro mini 3.3V for now at local stores.
Here is the I2C scanner result:
16:57:59.341 -> Scanning...
16:57:59.341 -> I2C device found at address 0x68 !
16:57:59.341 -> done
I bought a 3.3V Arduino pro mini and tested with both GY-521 modules that I have but the results are exactly the same -_-
I think the problem should be with modules but what problem can both of them have?!
I think you indeed have a HW problem in your sensors. I hooked up a GY-521 and loaded your sketch from post #1 works perfect and the library from Rob Tillaart also.
BTW I use a 5V Nano connected with the GY-521, and did not fry it yet by doing so.
Output from your sketch:
Accelerometer: X = -2368 | Y = -589 | Z = -3334
Gyroscope: X = -3168 | Y = -118 | Z = 108
Accelerometer: X = -2381 | Y = -599 | Z = -3386
Gyroscope: X = -3168 | Y = -126 | Z = 110
Accelerometer: X = -2391 | Y = -603 | Z = -3345
Gyroscope: X = -3136 | Y = -72 | Z = 78
Accelerometer: X = -2369 | Y = -568 | Z = -3351
Gyroscope: X = -3184 | Y = -118 | Z = 103
Accelerometer: X = -2354 | Y = -595 | Z = -3313
Gyroscope: X = -3168 | Y = -157 | Z = 76
Accelerometer: X = -2387 | Y = -583 | Z = -3335
Gyroscope: X = -3168 | Y = -106 | Z = 84
Accelerometer: X = -2399 | Y = -588 | Z = -3368
Gyroscope: X = -3168 | Y = -129 | Z = 100
hmeijdam:
I think you indeed have a HW problem in your sensors. I hooked up a GY-521 and loaded your sketch from post #1 works perfect and the library from Rob Tillaart also.
BTW I use a 5V Nano connected with the GY-521, and did not fry it yet by doing so.
Output from your sketch:
Accelerometer: X = -2368 | Y = -589 | Z = -3334
Gyroscope: X = -3168 | Y = -118 | Z = 108
Accelerometer: X = -2381 | Y = -599 | Z = -3386
Gyroscope: X = -3168 | Y = -126 | Z = 110
Accelerometer: X = -2391 | Y = -603 | Z = -3345
Gyroscope: X = -3136 | Y = -72 | Z = 78
Accelerometer: X = -2369 | Y = -568 | Z = -3351
Gyroscope: X = -3184 | Y = -118 | Z = 103
Accelerometer: X = -2354 | Y = -595 | Z = -3313
Gyroscope: X = -3168 | Y = -157 | Z = 76
Accelerometer: X = -2387 | Y = -583 | Z = -3335
Gyroscope: X = -3168 | Y = -106 | Z = 84
Accelerometer: X = -2399 | Y = -588 | Z = -3368
Gyroscope: X = -3168 | Y = -129 | Z = 100
Thanks a lot. I connected the GY521 to my raspberry pi and again, all values are zero! To ensure that there isn't any wiring or soldering problem, I tried reading the "WHO_AM_I" register and it returned 104 as it is supposed to.
So if anyone has any idea like if I should reset the MPU6050 or awake it or configure it or ... Please tell me. Otherwise I consider it a hardware problem and have to buy another module.