MPU 6050 Arduino Library
The MPU-6050 IMU (Inertial Measurement Unit) is a 3-axis accelerometer and 3-axis gyroscope sensor. The accelerometer measures the gravitational acceleration, and the gyroscope measures the rotational velocity. Additionally, this module also measures temperature.
Required Arduino IDE Library

gyro.h
#include "MPU6050.h"
class GyroPacket {
public:
int16_t _ax, _ay, _az;
int16_t _gx, _gy, _gz;
int16_t _rx, _ry, _rz;
double t,tx,tf,_pitch,_roll,_yaw;
GyroPacket(int address, MPU6050 sensor);
bool isMoving();
// acceleration
int16_t ax();
int16_t ay();
int16_t az();
// gyro
int16_t gx();
int16_t gy();
int16_t gz();
// rotation
int16_t rx();
int16_t ry();
int16_t rz();
double pitch();
double roll();
double yaw();
private:
int address;
bool moving;
//convert the accel data to pitch/roll
void getAngle(int a, int b, int c);
};
gyro.cpp
#include <math.h>
#include <Wire.h>
#include "I2Cdev.h"
#include "MPU6050.h"
#include "gyro.h"
GyroPacket::GyroPacket(int address, MPU6050 sensor) {
this->address = address;
sensor.getMotion6(
&_ax, &_ay, &_az,
&_gx, &_gy, &_gz
);
sensor.getRotation(
&_rx, &_ry, &_rz
);
getAngle(_ax, _ay, _az);
this->t = ((sensor.getTemperature() - 1600) / 340) + 36.53;
this->tf = (this->t * 9 / 5) + 32;
}
int16_t GyroPacket::ax() {
return _ax;
}
int16_t GyroPacket::ay() {
return _ay;
}
int16_t GyroPacket::az() {
return _az;
}
int16_t GyroPacket::gx() {
return _gx;
}
int16_t GyroPacket::gy() {
return _gy;
}
int16_t GyroPacket::gz() {
return _gz;
}
int16_t GyroPacket::rx() {
return _rx;
}
int16_t GyroPacket::ry() {
return _ry;
}
int16_t GyroPacket::rz() {
return _rz;
}
//
////convert the accel data to pitch/roll
void GyroPacket::getAngle(int a, int b, int c) {
double x = (double)a;
double y = (double)b;
double z = (double)c;
double pitch = atan(x / sqrt((y * y) + (z * z)));
double roll = atan(y / sqrt((x * x) + (z * z)));
double yaw = atan(z / sqrt((x * x) + (y * y)));
//convert radians into degrees
this->_pitch = pitch * (180.0 / M_PI); //3.14159265359);
this->_roll = roll * (180.0 / M_PI); //3.14159265359) ;
this->_yaw = yaw * (180.0 / M_PI); //3.14159265359) ;
}
//convert the accel data to pitch/roll
double GyroPacket::pitch() {
return _pitch;
// double pitch = atan((double)_ax / sqrt(((double)_ay * _ay) + (_az, _az)));
// return pitch * (180.0/M_PI);
}
double GyroPacket::roll() {
return _roll;
// double roll = atan((double)_ay / sqrt(((double)_ax * _ax) + (_az * _az)));
// return roll * (180.0/M_PI);
}
double GyroPacket::yaw() {
return _yaw;
// double yaw = atan((double)_az / sqrt(((double)_ax * _ax) + (_ay * _ay)));
// return yaw * (180.0/M_PI);
}