3 axis gyroscope & 3 axis accelerometer

Dependents:   sgam-lib sgam_mdw_NUCLEOF429ZI_impl

Fork of MPU6050 by Yihui Xiong

Usage

#include "mbed.h"
#include "MPU6050.h"

DigitalOut myled(LED1);
Serial pc(USBTX, USBRX);
I2C    i2c(I2C_SDA, I2C_SCL);
MPU6050 mpu(i2c);
 
int16_t ax, ay, az;
int16_t gx, gy, gz;
 
int main()
{
    pc.printf("MPU6050 test\n\n");
    pc.printf("MPU6050 initialize \n");
 
    mpu.initialize();
    
    pc.printf("MPU6050 testConnection \n");
 
    bool mpu6050TestResult = mpu.testConnection();
    if(mpu6050TestResult) {
        pc.printf("MPU6050 test passed \n");
    } else {
        pc.printf("MPU6050 test failed \n");
    }
   
    while(1) {
        wait(1);
        mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
        //writing current accelerometer and gyro position 
        pc.printf("%d;%d;%d;%d;%d;%d\n",ax,ay,az,gx,gy,gz);
    }
}
Revision:
2:8c562a8fed36
Parent:
1:1e0baaf91e96
--- a/MPU6050.h	Wed May 08 00:34:55 2013 +0000
+++ b/MPU6050.h	Fri Sep 12 09:28:14 2014 +0800
@@ -48,7 +48,7 @@
 
 #define MPU6050_ADDRESS_AD0_LOW     0x68 // address pin low (GND), default for InvenSense evaluation board
 #define MPU6050_ADDRESS_AD0_HIGH    0x69 // address pin high (VCC)
-#define MPU6050_DEFAULT_ADDRESS     MPU6050_ADDRESS_AD0_LOW
+#define MPU6050_DEFAULT_ADDRESS     MPU6050_ADDRESS_AD0_HIGH
 
 #define MPU6050_RA_XG_OFFS_TC       0x00 //[7] PWR_MODE, [6:1] XG_OFFS_TC, [0] OTP_BNK_VLD
 #define MPU6050_RA_YG_OFFS_TC       0x01 //[7] PWR_MODE, [6:1] YG_OFFS_TC, [0] OTP_BNK_VLD
@@ -405,10 +405,8 @@
 class MPU6050 {
     private:
         I2Cdev i2Cdev;
-        Serial debugSerial;
     public:
-        MPU6050();
-        MPU6050(uint8_t address);
+        MPU6050(I2C &i2c, uint8_t address = MPU6050_DEFAULT_ADDRESS);
 
         void initialize();
         bool testConnection();
@@ -991,4 +989,4 @@
         uint8_t buffer[14];
 };
 
-#endif /* _MPU6050_H_ */
\ No newline at end of file
+#endif /* _MPU6050_H_ */