NM500 / NeuroShield

Dependents:   NeuroShield_SimpleScript NeuroShield_andIMU NeuroShield_Gesture_Recognition

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mpu6050.h Source File

mpu6050.h

00001 #ifndef MPU6050_H
00002 #define MPU6050_H
00003 
00004 #include "mbed.h"
00005 
00006 #define MPU6050_DEFAULT_ADDRESS     0x68
00007 
00008 // register
00009 #define MPU6050_XA_OFFS_H_REG       0x06
00010 #define MPU6050_YA_OFFS_H_REG       0x08
00011 #define MPU6050_ZA_OFFS_H_REG       0x0A
00012 #define MPU6050_XG_OFFS_USRH_REG    0x13
00013 #define MPU6050_YG_OFFS_USRH_REG    0x15
00014 #define MPU6050_ZG_OFFS_USRH_REG    0x17
00015 #define MPU6050_CONFIG_REG          0x1A
00016 #define MPU6050_GYRO_CONFIG_REG     0x1B
00017 #define MPU6050_ACCEL_CONFIG_REG    0x1C
00018 #define MPU6050_INT_PIN_CFG         0x37
00019 #define MPU6050_ACCEL_XOUT_H_REG    0x3B
00020 #define MPU6050_ACCEL_YOUT_H_REG    0x3D
00021 #define MPU6050_ACCEL_ZOUT_H_REG    0x3F
00022 #define MPU6050_TEMP_H_REG          0x41
00023 #define MPU6050_GYRO_XOUT_H_REG     0x43
00024 #define MPU6050_GYRO_YOUT_H_REG     0x45
00025 #define MPU6050_GYRO_ZOUT_H_REG     0x47
00026 #define MPU6050_PWR_MGMT_1_REG      0x6B
00027 #define MPU6050_WHO_AM_I_REG        0x75
00028 
00029 #define MPU6050_CLOCK_INTERNAL      0x00
00030 #define MPU6050_CLOCK_PLL_XGYRO     0x01
00031 #define MPU6050_CLOCK_PLL_YGYRO     0x02
00032 #define MPU6050_CLOCK_PLL_ZGYRO     0x03
00033 #define MPU6050_CLOCK_PLL_EXT32K    0x04
00034 #define MPU6050_CLOCK_PLL_EXT19M    0x05
00035 #define MPU6050_CLOCK_KEEP_RESET    0x07
00036 
00037 #define MPU6050_GYRO_FS_250         0x00
00038 #define MPU6050_GYRO_FS_500         0x01
00039 #define MPU6050_GYRO_FS_1000        0x02
00040 #define MPU6050_GYRO_FS_2000        0x03
00041 
00042 #define MPU6050_ACCEL_FS_2          0x00
00043 #define MPU6050_ACCEL_FS_4          0x01
00044 #define MPU6050_ACCEL_FS_8          0x02
00045 #define MPU6050_ACCEL_FS_16         0x03
00046 
00047 class MPU6050 {
00048     public:
00049         MPU6050();
00050         MPU6050(uint8_t address);
00051         MPU6050(uint8_t address, PinName sda, PinName scl);
00052         
00053         void initialize();
00054         bool testConnection();
00055         uint8_t getDeviceID();
00056         
00057         void write(char address, char data);
00058         void writeWord(char address, int16_t data);
00059         char read(char address);
00060         void read(char address, char* data, int length);
00061         
00062         void setClockSource(uint8_t source);
00063         void setSleepEnable(bool enabled);
00064         void setFullScaleGyroRange(int8_t range);
00065         void setFullScaleAccelRange(int8_t range);
00066         
00067         void setXAccelOffset(int16_t offset);
00068         void setYAccelOffset(int16_t offset);
00069         void setZAccelOffset(int16_t offset);
00070         void setXGyroOffset(int16_t offset);
00071         void setYGyroOffset(int16_t offset);
00072         void setZGyroOffset(int16_t offset);
00073         
00074         void getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz);
00075         
00076     private:
00077         uint8_t dev_addr;
00078         uint8_t buffer[14];
00079         I2C connection;
00080 };
00081 
00082 #endif