Thanks Erik Olieman for his beta library, that saved me a huge amount of time when getting Raw data from MPU6050 module! I was able to update this library by adding additional functions, which would allow a fast angle calculation by using complementary filter. I will probably be updating this library more soon to add additional functionality or make some changes that would look sensible.
Dependents: QuadcopterProgram 3DTracking ControlYokutan2017 Gyro ... more
Fork of MPU6050 by
Revision 8:b1570b99df9e, committed 2015-02-13
- Comitter:
- moklumbys
- Date:
- Fri Feb 13 01:16:00 2015 +0000
- Parent:
- 7:56e591a74939
- Child:
- 9:898effccce30
- Commit message:
- Added one more function, which allows enabling interrupts on Int pin. Now we can gather data only when it is received. Next maybe possible to define time period for getting data...
Changed in this revision
MPU6050.cpp | Show annotated file Show diff for this revision Revisions of this file |
MPU6050.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MPU6050.cpp Fri Feb 13 01:04:17 2015 +0000 +++ b/MPU6050.cpp Fri Feb 13 01:16:00 2015 +0000 @@ -202,6 +202,21 @@ angle[Z_AXIS] = angle[Z_AXIS] + GYRO_SCALE*gyro[Z_AXIS]*(*currTime-*prevTime); //this is Yaw hopefully :D //Y = atan2(rawY,rawZ) * 180 / PI; //This spits out values between -180 to 180 (360 degrees) } + +void MPU6050::enableInt( void ) +{ + char temp; + temp = this->read(MPU6050_RA_INT_ENABLE); + temp |= 0x01; + this->write(MPU6050_RA_INT_ENABLE, temp); +} +void MPU6050::disableInt ( void ) +{ + char temp; + temp = this->read(MPU6050_RA_INT_ENABLE); + temp &= 0xFE; + this->write(MPU6050_RA_INT_ENABLE, temp); +} //-------------------------------------------------- //------------------Gyroscope----------------------- //--------------------------------------------------
--- a/MPU6050.h Fri Feb 13 01:04:17 2015 +0000 +++ b/MPU6050.h Fri Feb 13 01:16:00 2015 +0000 @@ -73,6 +73,9 @@ #define MPU6050_GYRO_RANGE_1000 2 #define MPU6050_GYRO_RANGE_2000 3 + +#define MPU6050_RA_INT_ENABLE 0x38 //interrupt address + //define how the accelerometer is placed on surface #define X_AXIS 1 #define Y_AXIS 2 @@ -271,7 +274,10 @@ void getAcceleroAngle( float *data ); void getOffset(float *accOffset, float *gyroOffset, int sampleSize); void computeAngle (float *angle, float *accOffset, float *gyroOffset, float *currTime, float *prevTime); - + void enableInt( void ); + void disableInt( void ); + + private: I2C connection;