MPU6050 library using i2c interface on LPC1768 - Complementary filter is added. Now program can calculate pitch and roll angles.

Fork of MPU6050 by Baser Kandehir

Committer:
BaserK
Date:
Mon Jul 13 13:18:34 2015 +0000
Revision:
1:a248e65a25cc
Parent:
0:954f15bd95f1
Child:
2:3e0dfce73a58
PI and dt added;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BaserK 0:954f15bd95f1 1 // Most of the code is adapted from Kris Winer's MPU6050 library
BaserK 0:954f15bd95f1 2
BaserK 0:954f15bd95f1 3 #ifndef MPU6050_H
BaserK 0:954f15bd95f1 4 #define MPU6050_H
BaserK 0:954f15bd95f1 5
BaserK 0:954f15bd95f1 6 #include "mbed.h"
BaserK 0:954f15bd95f1 7 #include "math.h"
BaserK 0:954f15bd95f1 8 #include "MPU6050RegDef.h"
BaserK 0:954f15bd95f1 9
BaserK 1:a248e65a25cc 10 #define PI 3.14159265359
BaserK 1:a248e65a25cc 11 #define dt 0.005 // 200 Hz sampling period
BaserK 1:a248e65a25cc 12
BaserK 0:954f15bd95f1 13 extern I2C i2c; // extern the i2c in order to able to use from other files
BaserK 0:954f15bd95f1 14 extern float aRes, gRes;
BaserK 0:954f15bd95f1 15
BaserK 0:954f15bd95f1 16 /* whoAmI func uses this func, variables etc */
BaserK 0:954f15bd95f1 17 extern Ticker toggler1;
BaserK 0:954f15bd95f1 18 extern Serial ftdi;
BaserK 0:954f15bd95f1 19 extern DigitalOut led2;
BaserK 0:954f15bd95f1 20 extern void toggle_led1();
BaserK 0:954f15bd95f1 21
BaserK 0:954f15bd95f1 22 /* Sensor datas to be used in main.cpp */
BaserK 0:954f15bd95f1 23 extern float ax,ay,az;
BaserK 0:954f15bd95f1 24 extern float gx,gy,gz;
BaserK 0:954f15bd95f1 25 extern int16_t accelData[3],gyroData[3],tempData;
BaserK 0:954f15bd95f1 26 extern float accelBias[3], gyroBias[3];
BaserK 0:954f15bd95f1 27
BaserK 0:954f15bd95f1 28 /* Function Prototypes */
BaserK 0:954f15bd95f1 29 class MPU6050
BaserK 0:954f15bd95f1 30 {
BaserK 0:954f15bd95f1 31 protected:
BaserK 0:954f15bd95f1 32 public:
BaserK 0:954f15bd95f1 33 void getAres();
BaserK 0:954f15bd95f1 34 void getGres();
BaserK 0:954f15bd95f1 35 void writeByte(uint8_t address, uint8_t subAddress, uint8_t data);
BaserK 0:954f15bd95f1 36 char readByte(uint8_t address, uint8_t subAddress);
BaserK 0:954f15bd95f1 37 void readBytes(uint8_t address, uint8_t subAddress, uint8_t byteNum, uint8_t* dest);
BaserK 0:954f15bd95f1 38 void whoAmI();
BaserK 0:954f15bd95f1 39 void init();
BaserK 0:954f15bd95f1 40 void reset();
BaserK 0:954f15bd95f1 41 void readAccelData(int16_t* dest);
BaserK 0:954f15bd95f1 42 void readGyroData(int16_t* dest);
BaserK 0:954f15bd95f1 43 int16_t readTempData();
BaserK 0:954f15bd95f1 44 void calibrate(float* dest1, float* dest2);
BaserK 0:954f15bd95f1 45 };
BaserK 0:954f15bd95f1 46
BaserK 0:954f15bd95f1 47 #endif