Problem getting GY-521 to work! (MPU 6050)

Hello everyone.

I’m trying to use GY-521 with Arduino pro mini.

This is the sketch that I upload to the Arduino pro mini 5V:

#include<Wire.h>
const int MPU=0x68; 
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B); 
  Wire.write(0);    
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,12,true);  
  AcX=Wire.read()<<8|Wire.read();    
  AcY=Wire.read()<<8|Wire.read();  
  AcZ=Wire.read()<<8|Wire.read();  
  GyX=Wire.read()<<8|Wire.read();  
  GyY=Wire.read()<<8|Wire.read();  
  GyZ=Wire.read()<<8|Wire.read();  
  
  Serial.print("Accelerometer: ");
  Serial.print("X = "); Serial.print(AcX);
  Serial.print(" | Y = "); Serial.print(AcY);
  Serial.print(" | Z = "); Serial.println(AcZ); 
  
  Serial.print("Gyroscope: ");
  Serial.print("X = "); Serial.print(GyX);
  Serial.print(" | Y = "); Serial.print(GyY);
  Serial.print(" | Z = "); Serial.println(GyZ);
  Serial.println(" ");
  delay(333);
}

And this is the schematic:

And here is the serial output:

As you can see all values are Zero all the time.

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.

One other thing, the nRF24L01 module works well.

And this is the result of I2C scanner:

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)

100 ohm resistors, is it safe to use them as pullup resistors?

No. Use 2.2 K or greater. You can usually salvage resistors from PCBs on junked toys, radios, etc.

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.

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.

gy521.jpg

gy521.jpg

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.

gy521.jpg

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.

Do you know if I have to use level shifter if I'm using a 5V arduino?

Yes, you do, even though lots of bad tutorials and forum posts say otherwise.

The MPU-6050 is a 3.3V device. The very best approach with 3.3V devices is to use a 3.3V MCU to control them.

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?
https://github.com/RobTillaart/GY521

KrisKasprzak:
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?
https://github.com/RobTillaart/GY521

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:

  // Get the data
  int8_t n = Wire.requestFrom(_address, (uint8_t)14);
  if (n != 14) return GY521_ERROR_READ;
  // ACCELEROMETER
  _ax = _WireRead2();  // ACCEL_XOUT_H  ACCEL_XOUT_L
  _ay = _WireRead2();  // ACCEL_YOUT_H  ACCEL_YOUT_L
  _az = _WireRead2();  // ACCEL_ZOUT_H  ACCEL_ZOUT_L
  // TEMPERATURE
  _temperature = _WireRead2(); // TEMP_OUT_H    TEMP_OUT_L
  // GYROSCOPE
  _gx = _WireRead2();  // GYRO_XOUT_H   GYRO_XOUT_L
  _gy = _WireRead2();  // GYRO_YOUT_H   GYRO_YOUT_L
  _gz = _WireRead2();  // GYRO_ZOUT_H   GYRO_ZOUT_L

to:

  // Get the data
  int8_t n = Wire.requestFrom(_address, (uint8_t)14);
  if (n != 14) return GY521_ERROR_READ;
  // ACCELEROMETER
  _ax = (int16_t)(((int16_t)Wire.read() <<  8 ) | Wire.read());  // ACCEL_XOUT_H  ACCEL_XOUT_L
  _ay = (int16_t)(((int16_t)Wire.read() <<  8 ) | Wire.read());  // ACCEL_YOUT_H  ACCEL_YOUT_L
  _az = (int16_t)(((int16_t)Wire.read() <<  8 ) | Wire.read());  // ACCEL_ZOUT_H  ACCEL_ZOUT_L
  // TEMPERATURE
  _temperature = _WireRead2(); // TEMP_OUT_H    TEMP_OUT_L
  // GYROSCOPE
  _gx = (int16_t)(((int16_t)Wire.read() <<  8 ) | Wire.read());  // GYRO_XOUT_H   GYRO_XOUT_L
  _gy = (int16_t)(((int16_t)Wire.read() <<  8 ) | Wire.read());  // GYRO_YOUT_H   GYRO_YOUT_L
  _gz = (int16_t)(((int16_t)Wire.read() <<  8 ) | Wire.read());  // GYRO_ZOUT_H   GYRO_ZOUT_L

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

Have I done everythong correctly?

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() {}

Creative Commons Attribution 3.0 Australia License

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)
   {
   }

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() {}



[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 found this tutorial in Arduino website and I do it step by step but still don't get any results. I really don't know what is wrong!

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

And Jremmingtons' improved sketch output

AcX = -1344 | AcY = -2065 | AcZ = -3337 | Tmp = 27.02 | GyX = -131 | GyY = 99 | GyZ = 135
AcX = -1330 | AcY = -2087 | AcZ = -3355 | Tmp = 26.88 | GyX = -129 | GyY = 102 | GyZ = 132
AcX = -1314 | AcY = -2098 | AcZ = -3354 | Tmp = 26.98 | GyX = -125 | GyY = 100 | GyZ = 128
AcX = -1326 | AcY = -2087 | AcZ = -3322 | Tmp = 27.02 | GyX = -130 | GyY = 104 | GyZ = 127
AcX = -1362 | AcY = -2100 | AcZ = -3349 | Tmp = 27.02 | GyX = -130 | GyY = 96 | GyZ = 133
AcX = -1335 | AcY = -2102 | AcZ = -3363 | Tmp = 26.88 | GyX = -127 | GyY = 103 | GyZ = 135
AcX = -1351 | AcY = -2091 | AcZ = -3379 | Tmp = 27.02 | GyX = -129 | GyY = 97 | GyZ = 140
AcX = -1351 | AcY = -2097 | AcZ = -3344 | Tmp = 26.93 | GyX = -127 | GyY = 103 | GyZ = 132
AcX = -1389 | AcY = -2075 | AcZ = -3409 | Tmp = 26.98 | GyX = -124 | GyY = 74 | GyZ = 67
AcX = -1348 | AcY = -2095 | AcZ = -3363 | Tmp = 27.02 | GyX = -118 | GyY = 102 | GyZ = 138
AcX = -1337 | AcY = -2098 | AcZ = -3350 | Tmp = 27.02 | GyX = -119 | GyY = 93 | GyZ = 127
AcX = -1325 | AcY = -2082 | AcZ = -3351 | Tmp = 26.88 | GyX = -126 | GyY = 105 | GyZ = 133

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




And Jremmingtons' improved sketch output



AcX = -1344 | AcY = -2065 | AcZ = -3337 | Tmp = 27.02 | GyX = -131 | GyY = 99 | GyZ = 135
AcX = -1330 | AcY = -2087 | AcZ = -3355 | Tmp = 26.88 | GyX = -129 | GyY = 102 | GyZ = 132
AcX = -1314 | AcY = -2098 | AcZ = -3354 | Tmp = 26.98 | GyX = -125 | GyY = 100 | GyZ = 128
AcX = -1326 | AcY = -2087 | AcZ = -3322 | Tmp = 27.02 | GyX = -130 | GyY = 104 | GyZ = 127
AcX = -1362 | AcY = -2100 | AcZ = -3349 | Tmp = 27.02 | GyX = -130 | GyY = 96 | GyZ = 133
AcX = -1335 | AcY = -2102 | AcZ = -3363 | Tmp = 26.88 | GyX = -127 | GyY = 103 | GyZ = 135
AcX = -1351 | AcY = -2091 | AcZ = -3379 | Tmp = 27.02 | GyX = -129 | GyY = 97 | GyZ = 140
AcX = -1351 | AcY = -2097 | AcZ = -3344 | Tmp = 26.93 | GyX = -127 | GyY = 103 | GyZ = 132
AcX = -1389 | AcY = -2075 | AcZ = -3409 | Tmp = 26.98 | GyX = -124 | GyY = 74 | GyZ = 67
AcX = -1348 | AcY = -2095 | AcZ = -3363 | Tmp = 27.02 | GyX = -118 | GyY = 102 | GyZ = 138
AcX = -1337 | AcY = -2098 | AcZ = -3350 | Tmp = 27.02 | GyX = -119 | GyY = 93 | GyZ = 127
AcX = -1325 | AcY = -2082 | AcZ = -3351 | Tmp = 26.88 | GyX = -126 | GyY = 105 | GyZ = 133

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.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.