Gyro & Accelerometer outputing random values

Hello!

for the last week i had been trying to get my arduino gyroscope ( MPU-6050 ) to work, all attempts to do it on my self have failed, so i decided to follow a tutorial, to be precise this one now i have followed it and did everything as said, but the gyro still outputs values that are random. Shaking, moving or rotating the device has no effect on the output ( the output values range from ~-1,3 to ~1,3. I pinned the code below, if anyone would just take a look and see if i did everything correctly i would really appreciate it.

Dmajster

#define accSens 0 // 0 = 2g, 1 = 4g, 2 = 8g, 3 = 16g
#define gyroSens 0 // 0 = 250rad/s, 1 = 500rad/s, 2 1000rad/s, 3 = 2000rad/s

#include<Wire.h>
#include<math.h>

const int MPU=0x68;  // I2C address of the MPU-6050 int16_t

int gyroState = 0;
int calibrationStep = 0;
int temp;

float axCal = 0 , ayCal = 0, azCal = 0;
float gxCal = 0, gyCal = 0, gzCal = 0; 

float axRaw = 0, ayRaw = 0, azRaw = 0;
float gxRaw = 0, gyRaw = 0, gzRaw = 0;

float xTilt = 0, yTilt = 0, zTilt = 0;
float pitch = 0, roll = 0, yaw = 0;

float samplingRate = 0.04;
float timeConstant = 1.00;
float alpha = 0;

void setup(){

	Wire.begin();
	Wire.beginTransmission(MPU);
	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(){
	switch(gyroState){
	
		case 0:
			Wire.beginTransmission(MPU);
			Wire.write(0x3B);
			Wire.endTransmission(false);
			Wire.requestFrom(MPU,14,true); //EDIT1

		
			if (calibrationStep < 10){
			
				axCal += Wire.read()<<8|Wire.read();
				ayCal += Wire.read()<<8|Wire.read(); 
				azCal += Wire.read()<<8|Wire.read();
				
				temp = Wire.read()<<8|Wire.read();
				
				gxCal += Wire.read()<<8|Wire.read();
				gyCal += Wire.read()<<8|Wire.read();
				gzCal += Wire.read()<<8|Wire.read();
				
                                calibrationStep ++;
			}
			else{
			
				axCal /= 10;
				ayCal /= 10;
				azCal /= 10;
				
				gxCal /= 10;
				gyCal /= 10;
				gzCal /= 10;
				
				gyroState = 1;
			}
		break;
		
		case 1:
                        Wire.beginTransmission(MPU);
                        Wire.write(0x3B);
                        Wire.endTransmission(false);
                        Wire.requestFrom(MPU,14,true); //EDIT1 
                        
			axRaw = float(Wire.read()<<8|Wire.read()) - axCal;
			ayRaw = float(Wire.read()<<8|Wire.read()) - ayCal;
			azRaw = float(Wire.read()<<8|Wire.read()) - azCal;

			temp = float(Wire.read()<<8|Wire.read()) /340.00 + 36.53;

			gxRaw = float(Wire.read()<<8|Wire.read()) - gxCal;
			gyRaw = float(Wire.read()<<8|Wire.read()) - gyCal;
			gzRaw = float(Wire.read()<<8|Wire.read()) - gzCal;

			xTilt = atan( axRaw / sqrt( pow( gyRaw, 2 ) + pow( gzRaw, 2 ) ) );
			yTilt = atan( ayRaw / sqrt( pow( gxRaw, 2 ) + pow( gzRaw, 2 ) ) );
			zTilt = atan( sqrt( pow( axRaw, 2 ) + pow( ayRaw, 2 ) ) / azRaw );
			
			alpha = timeConstant / (timeConstant + samplingRate);

			pitch = alpha * ( pitch + (gxRaw/131) * millis()) + (1 - alpha) * (xTilt);
			roll = alpha * ( roll + (gyRaw/131) * millis()) + (1 - alpha) * (yTilt);
			yaw = alpha * (yaw + (gzRaw/131) * millis()) + (1 - alpha) * (zTilt);

                        Serial.print("\n>>Pitch is: ");Serial.print(pitch);
                        Serial.print(", Roll is: ");Serial.print(roll);
                        Serial.print(", Yaw is: ");Serial.print(yaw);
		break;

        }
}
			Wire.requestFrom(MPU,8,true);
		
			if (calibrationStep < 10){
			
				axCal += Wire.read()<<8|Wire.read();
				ayCal += Wire.read()<<8|Wire.read(); 
				azCal += Wire.read()<<8|Wire.read();
				
				temp = Wire.read()<<8|Wire.read();
				
				gxCal += Wire.read()<<8|Wire.read();
				gyCal += Wire.read()<<8|Wire.read();
				gzCal += Wire.read()<<8|Wire.read();

Do you know what the second argument to requestFrom() means? Asking for 8 bytes and then reading 14 doesn’t make sense.

Ah! yes i do know, i copied this from another of my scripts where i only tried to get the gyro and the temperature working, and forgot to change it back, as it stands now the gyro does respond to tilting but incorrectly.

EDIT This is the serial port log, if i try to rotate it in yaw to 90° than to 0° as quickly as possible.

>>Pitch is: 0.01, Roll is: -0.30, Yaw is: -0.03
>>Pitch is: 0.00, Roll is: -0.58, Yaw is: -0.05
>>Pitch is: 0.03, Roll is: -0.63, Yaw is: -0.09
>>Pitch is: 0.07, Roll is: -1.01, Yaw is: -0.11
>>Pitch is: 0.08, Roll is: -1.19, Yaw is: -0.13
>>Pitch is: 0.08, Roll is: -1.36, Yaw is: -0.14
>>Pitch is: 0.13, Roll is: -1.25, Yaw is: -0.15
>>Pitch is: 0.14, Roll is: -1.37, Yaw is: -0.16
>>Pitch is: 0.15, Roll is: -1.70, Yaw is: -0.40
>>Pitch is: 0.15, Roll is: -1.91, Yaw is: -0.69
>>Pitch is: 0.14, Roll is: -3.90, Yaw is: -0.77
>>Pitch is: 0.25, Roll is: -12.19, Yaw is: -0.69
>>Pitch is: -0.02, Roll is: -21.47, Yaw is: -1.83
>>Pitch is: -0.28, Roll is: -30.44, Yaw is: -1.86
>>Pitch is: -0.13, Roll is: -37.83, Yaw is: -1.75
>>Pitch is: 0.24, Roll is: -41.75, Yaw is: -1.60
>>Pitch is: 0.60, Roll is: -40.78, Yaw is: -1.56
>>Pitch is: 0.65, Roll is: -35.92, Yaw is: -1.53
>>Pitch is: -0.21, Roll is: -25.49, Yaw is: -1.73
>>Pitch is: 0.09, Roll is: -17.93, Yaw is: -1.55
>>Pitch is: -0.53, Roll is: -7.81, Yaw is: -2.11
>>Pitch is: -0.53, Roll is: 1.86, Yaw is: -1.81
>>Pitch is: -0.58, Roll is: 1.26, Yaw is: -1.79
>>Pitch is: -0.60, Roll is: 0.98, Yaw is: -1.81
>>Pitch is: -0.57, Roll is: 0.68, Yaw is: -1.76
>>Pitch is: -0.55, Roll is: 0.49, Yaw is: -1.64
>>Pitch is: -0.46, Roll is: 0.33, Yaw is: -1.09
>>Pitch is: -0.44, Roll is: 0.13, Yaw is: -0.98
>>Pitch is: -0.39, Roll is: -0.00, Yaw is: -0.96
>>Pitch is: -0.38, Roll is: -0.11, Yaw is: -0.87
>>Pitch is: -0.38, Roll is: -0.30, Yaw is: -0.84
>>Pitch is: -0.34, Roll is: -0.48, Yaw is: -0.83
>>Pitch is: -0.30, Roll is: -0.54, Yaw is: -0.82
>>Pitch is: -0.27, Roll is: -0.54, Yaw is: -0.80
>>Pitch is: -0.21, Roll is: -0.49, Yaw is: -0.74
>>Pitch is: -0.19, Roll is: -0.59, Yaw is: -0.74
>>Pitch is: -0.18, Roll is: -0.69, Yaw is: -0.72
>>Pitch is: -0.17, Roll is: -0.73, Yaw is: -0.68
>>Pitch is: -0.16, Roll is: -0.9

Ah! yes i do know, i copied this from another of my scripts where i only tried to get the gyro and the temperature working, and forgot to change it back, as it stands now the gyro does respond to tilting but incorrectly.

So post the code that you are actually having trouble with. Posting code you know contains errors is just winding us up.

this is the script im having the problems with, that script was just the foundation i used to make this script and that error slipped by me.

Dmajster:
this is the script im having the problems with, that script was just the foundation i used to make this script and that error slipped by me.

So that is a no then I suppose.
Good luck
bye