3 axis gyroscope & 3 axis accelerometer
Dependents: sgam-lib sgam_mdw_NUCLEOF429ZI_impl
Fork of MPU6050 by
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); } }
Diff: I2Cdev.h
- Revision:
- 2:8c562a8fed36
- Parent:
- 0:662207e34fba
--- a/I2Cdev.h Wed May 08 00:34:55 2013 +0000 +++ b/I2Cdev.h Fri Sep 12 09:28:14 2014 +0800 @@ -9,16 +9,12 @@ #include "mbed.h" -#define I2C_SDA p28 -#define I2C_SCL p27 class I2Cdev { private: I2C i2c; - Serial debugSerial; public: - I2Cdev(); - I2Cdev(PinName i2cSda, PinName i2cScl); + I2Cdev(I2C &interface); int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); @@ -41,4 +37,4 @@ static uint16_t readTimeout(void); }; -#endif \ No newline at end of file +#endif