Library containing functions to talk with both the MPU6050 IMUs on the Limbic Controller.
Fork of MPU6050 by
MPU6050.h@4:d1262cdbcf9d, 2016-04-05 (annotated)
- Committer:
- zork
- Date:
- Tue Apr 05 16:19:06 2016 +0000
- Revision:
- 4:d1262cdbcf9d
- Parent:
- 3:16cb051b0702
Mouse changed to absolute;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 1:a3366f09e95c | 1 | /*Use #define MPU6050_ES before you include this file if you have an engineering sample (older EVBs will have them), to find out if you have one, check your accelerometer output. |
Sissors | 0:6757f7363a9f | 2 | If it is half of what you expected, and you still are on the correct planet, you got an engineering sample |
Sissors | 0:6757f7363a9f | 3 | */ |
Sissors | 0:6757f7363a9f | 4 | |
Sissors | 0:6757f7363a9f | 5 | |
Sissors | 0:6757f7363a9f | 6 | #ifndef MPU6050_H |
Sissors | 0:6757f7363a9f | 7 | #define MPU6050_H |
Sissors | 0:6757f7363a9f | 8 | |
Sissors | 0:6757f7363a9f | 9 | /** |
Sissors | 0:6757f7363a9f | 10 | * Includes |
Sissors | 0:6757f7363a9f | 11 | */ |
Sissors | 0:6757f7363a9f | 12 | #include "mbed.h" |
Sissors | 1:a3366f09e95c | 13 | |
Sissors | 0:6757f7363a9f | 14 | |
Sissors | 0:6757f7363a9f | 15 | /** |
Sissors | 0:6757f7363a9f | 16 | * Defines |
Sissors | 0:6757f7363a9f | 17 | */ |
Sissors | 1:a3366f09e95c | 18 | #ifndef MPU6050_ADDRESS |
majik | 3:16cb051b0702 | 19 | #define MPU6050_ADDRESS 0x68 // address pin low (GND), default for InvenSense evaluation board |
Sissors | 1:a3366f09e95c | 20 | #endif |
Sissors | 1:a3366f09e95c | 21 | |
Sissors | 0:6757f7363a9f | 22 | #ifdef MPU6050_ES |
Sissors | 0:6757f7363a9f | 23 | #define DOUBLE_ACCELERO |
Sissors | 0:6757f7363a9f | 24 | #endif |
Sissors | 0:6757f7363a9f | 25 | |
Sissors | 0:6757f7363a9f | 26 | /** |
Sissors | 0:6757f7363a9f | 27 | * Registers |
Sissors | 0:6757f7363a9f | 28 | */ |
Sissors | 0:6757f7363a9f | 29 | |
zork | 4:d1262cdbcf9d | 30 | #define MPU6050_XGOFFS_TC 0x00 // Bit 7 PWR_MODE, bits 6:1 XG_OFFS_TC, bit 0 OTP_BNK_VLD |
zork | 4:d1262cdbcf9d | 31 | #define MPU6050_YGOFFS_TC 0x01 |
zork | 4:d1262cdbcf9d | 32 | #define MPU6050_ZGOFFS_TC 0x02 |
zork | 4:d1262cdbcf9d | 33 | #define MPU6050_X_FINE_GAIN 0x03 // [7:0] fine gain |
zork | 4:d1262cdbcf9d | 34 | #define MPU6050_Y_FINE_GAIN 0x04 |
zork | 4:d1262cdbcf9d | 35 | #define MPU6050_Z_FINE_GAIN 0x05 |
zork | 4:d1262cdbcf9d | 36 | #define MPU6050_XA_OFFSET_H 0x06 // User-defined trim values for accelerometer |
zork | 4:d1262cdbcf9d | 37 | #define MPU6050_XA_OFFSET_L_TC 0x07 |
zork | 4:d1262cdbcf9d | 38 | #define MPU6050_YA_OFFSET_H 0x08 |
zork | 4:d1262cdbcf9d | 39 | #define MPU6050_YA_OFFSET_L_TC 0x09 |
zork | 4:d1262cdbcf9d | 40 | #define MPU6050_ZA_OFFSET_H 0x0A |
zork | 4:d1262cdbcf9d | 41 | #define MPU6050_ZA_OFFSET_L_TC 0x0B |
zork | 4:d1262cdbcf9d | 42 | #define MPU6050_SELF_TEST_X 0x0D |
zork | 4:d1262cdbcf9d | 43 | #define MPU6050_SELF_TEST_Y 0x0E |
zork | 4:d1262cdbcf9d | 44 | #define MPU6050_SELF_TEST_Z 0x0F |
zork | 4:d1262cdbcf9d | 45 | #define MPU6050_SELF_TEST_A 0x10 |
zork | 4:d1262cdbcf9d | 46 | #define MPU6050_XG_OFFS_USRH 0x13 // User-defined trim values for gyroscope; supported in MPU-6050? |
zork | 4:d1262cdbcf9d | 47 | #define MPU6050_XG_OFFS_USRL 0x14 |
zork | 4:d1262cdbcf9d | 48 | #define MPU6050_YG_OFFS_USRH 0x15 |
zork | 4:d1262cdbcf9d | 49 | #define MPU6050_YG_OFFS_USRL 0x16 |
zork | 4:d1262cdbcf9d | 50 | #define MPU6050_ZG_OFFS_USRH 0x17 |
zork | 4:d1262cdbcf9d | 51 | #define MPU6050_ZG_OFFS_USRL 0x18 |
zork | 4:d1262cdbcf9d | 52 | #define MPU6050_SMPLRT_DIV 0x19 |
zork | 4:d1262cdbcf9d | 53 | #define MPU6050_CONFIG 0x1A |
zork | 4:d1262cdbcf9d | 54 | |
zork | 4:d1262cdbcf9d | 55 | // Filter bandwidth of accelerometer setting |
zork | 4:d1262cdbcf9d | 56 | #define MPU6050_EXT_FSYNC_TEMP 0x08 |
zork | 4:d1262cdbcf9d | 57 | #define MPU6050_DLPF_CFG_260 0x00 |
zork | 4:d1262cdbcf9d | 58 | #define MPU6050_DLPF_CFG_184 0x01 |
zork | 4:d1262cdbcf9d | 59 | #define MPU6050_DLPF_CFG_94 0x02 |
zork | 4:d1262cdbcf9d | 60 | #define MPU6050_DLPF_CFG_44 0x03 |
zork | 4:d1262cdbcf9d | 61 | #define MPU6050_DLPF_CFG_21 0x04 |
zork | 4:d1262cdbcf9d | 62 | #define MPU6050_DLPF_CFG_10 0x05 |
zork | 4:d1262cdbcf9d | 63 | #define MPU6050_DLPF_CFG_5 0x06 |
zork | 4:d1262cdbcf9d | 64 | |
zork | 4:d1262cdbcf9d | 65 | #define MPU6050_GYRO_CONFIG 0x1B |
zork | 4:d1262cdbcf9d | 66 | #define MPU6050_ACCEL_CONFIG 0x1C |
zork | 4:d1262cdbcf9d | 67 | #define MPU6050_FF_THR 0x1D // Free-fall |
zork | 4:d1262cdbcf9d | 68 | #define MPU6050_FF_DUR 0x1E // Free-fall |
zork | 4:d1262cdbcf9d | 69 | #define MPU6050_MOT_THR 0x1F // Motion detection threshold bits [7:0] |
zork | 4:d1262cdbcf9d | 70 | #define MPU6050_MOT_DUR 0x20 // Duration counter threshold for motion interrupt generation, 1 kHz rate, LSB = 1 ms |
zork | 4:d1262cdbcf9d | 71 | #define MPU6050_ZMOT_THR 0x21 // Zero-motion detection threshold bits [7:0] |
zork | 4:d1262cdbcf9d | 72 | #define MPU6050_ZRMOT_DUR 0x22 // Duration counter threshold for zero motion interrupt generation, 16 Hz rate, LSB = 64 ms |
zork | 4:d1262cdbcf9d | 73 | #define MPU6050_FIFO_EN 0x23 |
zork | 4:d1262cdbcf9d | 74 | #define MPU6050_I2C_MST_CTRL 0x24 |
zork | 4:d1262cdbcf9d | 75 | #define MPU6050_I2C_SLV0_ADDR 0x25 |
zork | 4:d1262cdbcf9d | 76 | #define MPU6050_I2C_SLV0_REG 0x26 |
zork | 4:d1262cdbcf9d | 77 | #define MPU6050_I2C_SLV0_CTRL 0x27 |
zork | 4:d1262cdbcf9d | 78 | #define MPU6050_I2C_SLV1_ADDR 0x28 |
zork | 4:d1262cdbcf9d | 79 | #define MPU6050_I2C_SLV1_REG 0x29 |
zork | 4:d1262cdbcf9d | 80 | #define MPU6050_I2C_SLV1_CTRL 0x2A |
zork | 4:d1262cdbcf9d | 81 | #define MPU6050_I2C_SLV2_ADDR 0x2B |
zork | 4:d1262cdbcf9d | 82 | #define MPU6050_I2C_SLV2_REG 0x2C |
zork | 4:d1262cdbcf9d | 83 | #define MPU6050_I2C_SLV2_CTRL 0x2D |
zork | 4:d1262cdbcf9d | 84 | #define MPU6050_I2C_SLV3_ADDR 0x2E |
zork | 4:d1262cdbcf9d | 85 | #define MPU6050_I2C_SLV3_REG 0x2F |
zork | 4:d1262cdbcf9d | 86 | #define MPU6050_I2C_SLV3_CTRL 0x30 |
zork | 4:d1262cdbcf9d | 87 | #define MPU6050_I2C_SLV4_ADDR 0x31 |
zork | 4:d1262cdbcf9d | 88 | #define MPU6050_I2C_SLV4_REG 0x32 |
zork | 4:d1262cdbcf9d | 89 | #define MPU6050_I2C_SLV4_DO 0x33 |
zork | 4:d1262cdbcf9d | 90 | #define MPU6050_I2C_SLV4_CTRL 0x34 |
zork | 4:d1262cdbcf9d | 91 | #define MPU6050_I2C_SLV4_DI 0x35 |
zork | 4:d1262cdbcf9d | 92 | #define MPU6050_I2C_MST_STATUS 0x36 |
zork | 4:d1262cdbcf9d | 93 | #define MPU6050_INT_PIN_CFG 0x37 |
zork | 4:d1262cdbcf9d | 94 | #define MPU6050_INT_ENABLE 0x38 |
zork | 4:d1262cdbcf9d | 95 | #define MPU6050_DMP_INT_STATUS 0x39 // Check DMP interrupt |
zork | 4:d1262cdbcf9d | 96 | #define MPU6050_INT_STATUS 0x3A |
zork | 4:d1262cdbcf9d | 97 | #define MPU6050_ACCEL_XOUT_H 0x3B |
zork | 4:d1262cdbcf9d | 98 | #define MPU6050_ACCEL_XOUT_L 0x3C |
zork | 4:d1262cdbcf9d | 99 | #define MPU6050_ACCEL_YOUT_H 0x3D |
zork | 4:d1262cdbcf9d | 100 | #define MPU6050_ACCEL_YOUT_L 0x3E |
zork | 4:d1262cdbcf9d | 101 | #define MPU6050_ACCEL_ZOUT_H 0x3F |
zork | 4:d1262cdbcf9d | 102 | #define MPU6050_ACCEL_ZOUT_L 0x40 |
zork | 4:d1262cdbcf9d | 103 | #define MPU6050_TEMP_OUT_H 0x41 |
zork | 4:d1262cdbcf9d | 104 | #define MPU6050_TEMP_OUT_L 0x42 |
zork | 4:d1262cdbcf9d | 105 | #define MPU6050_GYRO_XOUT_H 0x43 |
zork | 4:d1262cdbcf9d | 106 | #define MPU6050_GYRO_XOUT_L 0x44 |
zork | 4:d1262cdbcf9d | 107 | #define MPU6050_GYRO_YOUT_H 0x45 |
zork | 4:d1262cdbcf9d | 108 | #define MPU6050_GYRO_YOUT_L 0x46 |
zork | 4:d1262cdbcf9d | 109 | #define MPU6050_GYRO_ZOUT_H 0x47 |
zork | 4:d1262cdbcf9d | 110 | #define MPU6050_GYRO_ZOUT_L 0x48 |
zork | 4:d1262cdbcf9d | 111 | #define MPU6050_EXT_SENS_DATA_00 0x49 |
zork | 4:d1262cdbcf9d | 112 | #define MPU6050_EXT_SENS_DATA_01 0x4A |
zork | 4:d1262cdbcf9d | 113 | #define MPU6050_EXT_SENS_DATA_02 0x4B |
zork | 4:d1262cdbcf9d | 114 | #define MPU6050_EXT_SENS_DATA_03 0x4C |
zork | 4:d1262cdbcf9d | 115 | #define MPU6050_EXT_SENS_DATA_04 0x4D |
zork | 4:d1262cdbcf9d | 116 | #define MPU6050_EXT_SENS_DATA_05 0x4E |
zork | 4:d1262cdbcf9d | 117 | #define MPU6050_EXT_SENS_DATA_06 0x4F |
zork | 4:d1262cdbcf9d | 118 | #define MPU6050_EXT_SENS_DATA_07 0x50 |
zork | 4:d1262cdbcf9d | 119 | #define MPU6050_EXT_SENS_DATA_08 0x51 |
zork | 4:d1262cdbcf9d | 120 | #define MPU6050_EXT_SENS_DATA_09 0x52 |
zork | 4:d1262cdbcf9d | 121 | #define MPU6050_EXT_SENS_DATA_10 0x53 |
zork | 4:d1262cdbcf9d | 122 | #define MPU6050_EXT_SENS_DATA_11 0x54 |
zork | 4:d1262cdbcf9d | 123 | #define MPU6050_EXT_SENS_DATA_12 0x55 |
zork | 4:d1262cdbcf9d | 124 | #define MPU6050_EXT_SENS_DATA_13 0x56 |
zork | 4:d1262cdbcf9d | 125 | #define MPU6050_EXT_SENS_DATA_14 0x57 |
zork | 4:d1262cdbcf9d | 126 | #define MPU6050_EXT_SENS_DATA_15 0x58 |
zork | 4:d1262cdbcf9d | 127 | #define MPU6050_EXT_SENS_DATA_16 0x59 |
zork | 4:d1262cdbcf9d | 128 | #define MPU6050_EXT_SENS_DATA_17 0x5A |
zork | 4:d1262cdbcf9d | 129 | #define MPU6050_EXT_SENS_DATA_18 0x5B |
zork | 4:d1262cdbcf9d | 130 | #define MPU6050_EXT_SENS_DATA_19 0x5C |
zork | 4:d1262cdbcf9d | 131 | #define MPU6050_EXT_SENS_DATA_20 0x5D |
zork | 4:d1262cdbcf9d | 132 | #define MPU6050_EXT_SENS_DATA_21 0x5E |
zork | 4:d1262cdbcf9d | 133 | #define MPU6050_EXT_SENS_DATA_22 0x5F |
zork | 4:d1262cdbcf9d | 134 | #define MPU6050_EXT_SENS_DATA_23 0x60 |
zork | 4:d1262cdbcf9d | 135 | #define MPU6050_MOT_DETECT_STATUS 0x61 |
zork | 4:d1262cdbcf9d | 136 | #define MPU6050_I2C_SLV0_DO 0x63 |
zork | 4:d1262cdbcf9d | 137 | #define MPU6050_I2C_SLV1_DO 0x64 |
zork | 4:d1262cdbcf9d | 138 | #define MPU6050_I2C_SLV2_DO 0x65 |
zork | 4:d1262cdbcf9d | 139 | #define MPU6050_I2C_SLV3_DO 0x66 |
zork | 4:d1262cdbcf9d | 140 | #define MPU6050_I2C_MST_DELAY_CTRL 0x67 |
zork | 4:d1262cdbcf9d | 141 | #define MPU6050_SIGNAL_PATH_RESET 0x68 |
zork | 4:d1262cdbcf9d | 142 | #define MPU6050_MOT_DETECT_CTRL 0x69 |
zork | 4:d1262cdbcf9d | 143 | #define MPU6050_USER_CTRL 0x6A // Bit 7 enable DMP, bit 3 reset DMP |
zork | 4:d1262cdbcf9d | 144 | #define MPU6050_PWR_MGMT_1 0x6B // Device defaults to the SLEEP mode |
zork | 4:d1262cdbcf9d | 145 | #define MPU6050_PWR_MGMT_2 0x6C |
zork | 4:d1262cdbcf9d | 146 | #define MPU6050_DMP_BANK 0x6D // Activates a specific bank in the DMP |
zork | 4:d1262cdbcf9d | 147 | #define MPU6050_DMP_RW_PNT 0x6E // Set read/write pointer to a specific start address in specified DMP bank |
zork | 4:d1262cdbcf9d | 148 | #define MPU6050_DMP_REG 0x6F // Register in DMP from which to read or to which to write |
zork | 4:d1262cdbcf9d | 149 | #define MPU6050_DMP_REG_1 0x70 |
zork | 4:d1262cdbcf9d | 150 | #define MPU6050_DMP_REG_2 0x71 |
zork | 4:d1262cdbcf9d | 151 | #define MPU6050_FIFO_COUNTH 0x72 |
zork | 4:d1262cdbcf9d | 152 | #define MPU6050_FIFO_COUNTL 0x73 |
zork | 4:d1262cdbcf9d | 153 | #define MPU6050_FIFO_R_W 0x74 |
zork | 4:d1262cdbcf9d | 154 | #define MPU6050_WHO_AM_I 0x75 // Should return 0x68 |
Sissors | 0:6757f7363a9f | 155 | |
Sissors | 0:6757f7363a9f | 156 | /** |
Sissors | 0:6757f7363a9f | 157 | * Definitions |
Sissors | 0:6757f7363a9f | 158 | */ |
Sissors | 0:6757f7363a9f | 159 | #define MPU6050_SLP_BIT 6 |
Sissors | 0:6757f7363a9f | 160 | #define MPU6050_BYPASS_BIT 1 |
Sissors | 0:6757f7363a9f | 161 | |
Sissors | 0:6757f7363a9f | 162 | #define MPU6050_BW_256 0 |
Sissors | 0:6757f7363a9f | 163 | #define MPU6050_BW_188 1 |
Sissors | 0:6757f7363a9f | 164 | #define MPU6050_BW_98 2 |
Sissors | 0:6757f7363a9f | 165 | #define MPU6050_BW_42 3 |
Sissors | 0:6757f7363a9f | 166 | #define MPU6050_BW_20 4 |
Sissors | 0:6757f7363a9f | 167 | #define MPU6050_BW_10 5 |
Sissors | 0:6757f7363a9f | 168 | #define MPU6050_BW_5 6 |
Sissors | 0:6757f7363a9f | 169 | |
Sissors | 0:6757f7363a9f | 170 | #define MPU6050_ACCELERO_RANGE_2G 0 |
Sissors | 0:6757f7363a9f | 171 | #define MPU6050_ACCELERO_RANGE_4G 1 |
Sissors | 0:6757f7363a9f | 172 | #define MPU6050_ACCELERO_RANGE_8G 2 |
Sissors | 0:6757f7363a9f | 173 | #define MPU6050_ACCELERO_RANGE_16G 3 |
Sissors | 0:6757f7363a9f | 174 | |
Sissors | 0:6757f7363a9f | 175 | #define MPU6050_GYRO_RANGE_250 0 |
Sissors | 0:6757f7363a9f | 176 | #define MPU6050_GYRO_RANGE_500 1 |
Sissors | 0:6757f7363a9f | 177 | #define MPU6050_GYRO_RANGE_1000 2 |
Sissors | 0:6757f7363a9f | 178 | #define MPU6050_GYRO_RANGE_2000 3 |
Sissors | 0:6757f7363a9f | 179 | |
Sissors | 0:6757f7363a9f | 180 | |
Sissors | 2:5c63e20c50f3 | 181 | /** MPU6050 IMU library. |
Sissors | 2:5c63e20c50f3 | 182 | * |
Sissors | 2:5c63e20c50f3 | 183 | * Example: |
Sissors | 2:5c63e20c50f3 | 184 | * @code |
Sissors | 2:5c63e20c50f3 | 185 | * Later, maybe |
Sissors | 2:5c63e20c50f3 | 186 | * @endcode |
Sissors | 2:5c63e20c50f3 | 187 | */ |
Sissors | 0:6757f7363a9f | 188 | class MPU6050 { |
Sissors | 0:6757f7363a9f | 189 | public: |
Sissors | 0:6757f7363a9f | 190 | /** |
Sissors | 0:6757f7363a9f | 191 | * Constructor. |
Sissors | 0:6757f7363a9f | 192 | * |
Sissors | 0:6757f7363a9f | 193 | * Sleep mode of MPU6050 is immediatly disabled |
Sissors | 0:6757f7363a9f | 194 | * |
Sissors | 0:6757f7363a9f | 195 | * @param sda - mbed pin to use for the SDA I2C line. |
Sissors | 0:6757f7363a9f | 196 | * @param scl - mbed pin to use for the SCL I2C line. |
Sissors | 0:6757f7363a9f | 197 | */ |
Sissors | 0:6757f7363a9f | 198 | MPU6050(PinName sda, PinName scl); |
Sissors | 0:6757f7363a9f | 199 | |
Sissors | 0:6757f7363a9f | 200 | |
Sissors | 0:6757f7363a9f | 201 | /** |
Sissors | 0:6757f7363a9f | 202 | * Tests the I2C connection by reading the WHO_AM_I register. |
Sissors | 0:6757f7363a9f | 203 | * |
Sissors | 0:6757f7363a9f | 204 | * @return True for a working connection, false for an error |
Sissors | 0:6757f7363a9f | 205 | */ |
majik | 3:16cb051b0702 | 206 | char testConnection( void ); |
Sissors | 0:6757f7363a9f | 207 | |
Sissors | 0:6757f7363a9f | 208 | /** |
Sissors | 0:6757f7363a9f | 209 | * Sets the bandwidth of the digital low-pass filter |
Sissors | 0:6757f7363a9f | 210 | * |
Sissors | 0:6757f7363a9f | 211 | * Macros: MPU6050_BW_256 - MPU6050_BW_188 - MPU6050_BW_98 - MPU6050_BW_42 - MPU6050_BW_20 - MPU6050_BW_10 - MPU6050_BW_5 |
Sissors | 0:6757f7363a9f | 212 | * Last number is the gyro's BW in Hz (accelero BW is virtually identical) |
Sissors | 0:6757f7363a9f | 213 | * |
Sissors | 0:6757f7363a9f | 214 | * @param BW - The three bits that set the bandwidth (use the predefined macros) |
Sissors | 0:6757f7363a9f | 215 | */ |
Sissors | 0:6757f7363a9f | 216 | void setBW( char BW ); |
Sissors | 0:6757f7363a9f | 217 | |
Sissors | 0:6757f7363a9f | 218 | /** |
Sissors | 0:6757f7363a9f | 219 | * Sets the auxiliary I2C bus in bypass mode to read the sensors behind the MPU6050 (useful for eval board, otherwise just connect them to primary I2C bus) |
Sissors | 0:6757f7363a9f | 220 | * |
Sissors | 0:6757f7363a9f | 221 | * @param state - Enables/disables the I2C bypass mode |
Sissors | 0:6757f7363a9f | 222 | */ |
Sissors | 0:6757f7363a9f | 223 | void setI2CBypass ( bool state ); |
Sissors | 0:6757f7363a9f | 224 | |
Sissors | 0:6757f7363a9f | 225 | /** |
Sissors | 0:6757f7363a9f | 226 | * Sets the Accelero full-scale range |
Sissors | 0:6757f7363a9f | 227 | * |
Sissors | 0:6757f7363a9f | 228 | * Macros: MPU6050_ACCELERO_RANGE_2G - MPU6050_ACCELERO_RANGE_4G - MPU6050_ACCELERO_RANGE_8G - MPU6050_ACCELERO_RANGE_16G |
Sissors | 0:6757f7363a9f | 229 | * |
Sissors | 0:6757f7363a9f | 230 | * @param range - The two bits that set the full-scale range (use the predefined macros) |
Sissors | 0:6757f7363a9f | 231 | */ |
Sissors | 0:6757f7363a9f | 232 | void setAcceleroRange(char range); |
Sissors | 0:6757f7363a9f | 233 | |
zork | 4:d1262cdbcf9d | 234 | |
zork | 4:d1262cdbcf9d | 235 | void setAcceleroFilter(char bandwidth); |
zork | 4:d1262cdbcf9d | 236 | |
zork | 4:d1262cdbcf9d | 237 | |
Sissors | 0:6757f7363a9f | 238 | /** |
Sissors | 0:6757f7363a9f | 239 | * Reads the accelero x-axis. |
Sissors | 0:6757f7363a9f | 240 | * |
Sissors | 0:6757f7363a9f | 241 | * @return 16-bit signed integer x-axis accelero data |
Sissors | 0:6757f7363a9f | 242 | */ |
Sissors | 0:6757f7363a9f | 243 | int getAcceleroRawX( void ); |
Sissors | 0:6757f7363a9f | 244 | |
Sissors | 0:6757f7363a9f | 245 | /** |
Sissors | 0:6757f7363a9f | 246 | * Reads the accelero y-axis. |
Sissors | 0:6757f7363a9f | 247 | * |
Sissors | 0:6757f7363a9f | 248 | * @return 16-bit signed integer y-axis accelero data |
Sissors | 0:6757f7363a9f | 249 | */ |
Sissors | 0:6757f7363a9f | 250 | int getAcceleroRawY( void ); |
Sissors | 0:6757f7363a9f | 251 | |
Sissors | 0:6757f7363a9f | 252 | /** |
Sissors | 0:6757f7363a9f | 253 | * Reads the accelero z-axis. |
Sissors | 0:6757f7363a9f | 254 | * |
Sissors | 0:6757f7363a9f | 255 | * @return 16-bit signed integer z-axis accelero data |
Sissors | 0:6757f7363a9f | 256 | */ |
Sissors | 0:6757f7363a9f | 257 | int getAcceleroRawZ( void ); |
Sissors | 0:6757f7363a9f | 258 | |
Sissors | 0:6757f7363a9f | 259 | /** |
Sissors | 0:6757f7363a9f | 260 | * Reads all accelero data. |
Sissors | 0:6757f7363a9f | 261 | * |
Sissors | 0:6757f7363a9f | 262 | * @param data - pointer to signed integer array with length three: data[0] = X, data[1] = Y, data[2] = Z |
Sissors | 0:6757f7363a9f | 263 | */ |
Sissors | 0:6757f7363a9f | 264 | void getAcceleroRaw( int *data ); |
Sissors | 0:6757f7363a9f | 265 | |
Sissors | 0:6757f7363a9f | 266 | /** |
Sissors | 0:6757f7363a9f | 267 | * Reads all accelero data, gives the acceleration in m/s2 |
Sissors | 0:6757f7363a9f | 268 | * |
Sissors | 0:6757f7363a9f | 269 | * Function uses the last setup value of the full scale range, if you manually set in another range, this won't work. |
Sissors | 0:6757f7363a9f | 270 | * |
Sissors | 0:6757f7363a9f | 271 | * @param data - pointer to float array with length three: data[0] = X, data[1] = Y, data[2] = Z |
Sissors | 0:6757f7363a9f | 272 | */ |
Sissors | 0:6757f7363a9f | 273 | void getAccelero( float *data ); |
Sissors | 0:6757f7363a9f | 274 | |
Sissors | 0:6757f7363a9f | 275 | /** |
Sissors | 0:6757f7363a9f | 276 | * Sets the Gyro full-scale range |
Sissors | 0:6757f7363a9f | 277 | * |
Sissors | 0:6757f7363a9f | 278 | * Macros: MPU6050_GYRO_RANGE_250 - MPU6050_GYRO_RANGE_500 - MPU6050_GYRO_RANGE_1000 - MPU6050_GYRO_RANGE_2000 |
Sissors | 0:6757f7363a9f | 279 | * |
Sissors | 0:6757f7363a9f | 280 | * @param range - The two bits that set the full-scale range (use the predefined macros) |
Sissors | 0:6757f7363a9f | 281 | */ |
Sissors | 0:6757f7363a9f | 282 | void setGyroRange(char range); |
Sissors | 0:6757f7363a9f | 283 | |
Sissors | 0:6757f7363a9f | 284 | /** |
Sissors | 0:6757f7363a9f | 285 | * Reads the gyro x-axis. |
Sissors | 0:6757f7363a9f | 286 | * |
Sissors | 0:6757f7363a9f | 287 | * @return 16-bit signed integer x-axis gyro data |
Sissors | 0:6757f7363a9f | 288 | */ |
Sissors | 0:6757f7363a9f | 289 | int getGyroRawX( void ); |
Sissors | 0:6757f7363a9f | 290 | |
Sissors | 0:6757f7363a9f | 291 | /** |
Sissors | 0:6757f7363a9f | 292 | * Reads the gyro y-axis. |
Sissors | 0:6757f7363a9f | 293 | * |
Sissors | 0:6757f7363a9f | 294 | * @return 16-bit signed integer y-axis gyro data |
Sissors | 0:6757f7363a9f | 295 | */ |
Sissors | 0:6757f7363a9f | 296 | int getGyroRawY( void ); |
Sissors | 0:6757f7363a9f | 297 | |
Sissors | 0:6757f7363a9f | 298 | /** |
Sissors | 0:6757f7363a9f | 299 | * Reads the gyro z-axis. |
Sissors | 0:6757f7363a9f | 300 | * |
Sissors | 0:6757f7363a9f | 301 | * @return 16-bit signed integer z-axis gyro data |
Sissors | 0:6757f7363a9f | 302 | */ |
Sissors | 0:6757f7363a9f | 303 | int getGyroRawZ( void ); |
Sissors | 0:6757f7363a9f | 304 | |
Sissors | 0:6757f7363a9f | 305 | /** |
Sissors | 0:6757f7363a9f | 306 | * Reads all gyro data. |
Sissors | 0:6757f7363a9f | 307 | * |
Sissors | 0:6757f7363a9f | 308 | * @param data - pointer to signed integer array with length three: data[0] = X, data[1] = Y, data[2] = Z |
Sissors | 0:6757f7363a9f | 309 | */ |
Sissors | 0:6757f7363a9f | 310 | void getGyroRaw( int *data ); |
Sissors | 0:6757f7363a9f | 311 | |
Sissors | 0:6757f7363a9f | 312 | /** |
Sissors | 0:6757f7363a9f | 313 | * Reads all gyro data, gives the gyro in rad/s |
Sissors | 0:6757f7363a9f | 314 | * |
Sissors | 0:6757f7363a9f | 315 | * Function uses the last setup value of the full scale range, if you manually set in another range, this won't work. |
Sissors | 0:6757f7363a9f | 316 | * |
Sissors | 0:6757f7363a9f | 317 | * @param data - pointer to float array with length three: data[0] = X, data[1] = Y, data[2] = Z |
Sissors | 0:6757f7363a9f | 318 | */ |
Sissors | 0:6757f7363a9f | 319 | void getGyro( float *data); |
Sissors | 0:6757f7363a9f | 320 | |
Sissors | 0:6757f7363a9f | 321 | /** |
Sissors | 0:6757f7363a9f | 322 | * Reads temperature data. |
Sissors | 0:6757f7363a9f | 323 | * |
Sissors | 0:6757f7363a9f | 324 | * @return 16 bit signed integer with the raw temperature register value |
Sissors | 0:6757f7363a9f | 325 | */ |
Sissors | 0:6757f7363a9f | 326 | int getTempRaw( void ); |
Sissors | 0:6757f7363a9f | 327 | |
Sissors | 0:6757f7363a9f | 328 | /** |
Sissors | 0:6757f7363a9f | 329 | * Returns current temperature |
Sissors | 0:6757f7363a9f | 330 | * |
Sissors | 0:6757f7363a9f | 331 | * @returns float with the current temperature |
Sissors | 0:6757f7363a9f | 332 | */ |
Sissors | 0:6757f7363a9f | 333 | float getTemp( void ); |
Sissors | 0:6757f7363a9f | 334 | |
Sissors | 0:6757f7363a9f | 335 | /** |
Sissors | 0:6757f7363a9f | 336 | * Sets the sleep mode of the MPU6050 |
Sissors | 0:6757f7363a9f | 337 | * |
Sissors | 0:6757f7363a9f | 338 | * @param state - true for sleeping, false for wake up |
Sissors | 0:6757f7363a9f | 339 | */ |
Sissors | 0:6757f7363a9f | 340 | void setSleepMode( bool state ); |
Sissors | 0:6757f7363a9f | 341 | |
Sissors | 0:6757f7363a9f | 342 | |
Sissors | 0:6757f7363a9f | 343 | /** |
Sissors | 0:6757f7363a9f | 344 | * Writes data to the device, could be private, but public is handy so you can transmit directly to the MPU. |
Sissors | 0:6757f7363a9f | 345 | * |
Sissors | 0:6757f7363a9f | 346 | * @param adress - register address to write to |
Sissors | 0:6757f7363a9f | 347 | * @param data - data to write |
Sissors | 0:6757f7363a9f | 348 | */ |
Sissors | 0:6757f7363a9f | 349 | void write( char address, char data); |
Sissors | 0:6757f7363a9f | 350 | |
Sissors | 0:6757f7363a9f | 351 | /** |
Sissors | 0:6757f7363a9f | 352 | * Read data from the device, could be private, but public is handy so you can transmit directly to the MPU. |
Sissors | 0:6757f7363a9f | 353 | * |
Sissors | 0:6757f7363a9f | 354 | * @param adress - register address to write to |
Sissors | 0:6757f7363a9f | 355 | * @return - data from the register specified by RA |
Sissors | 0:6757f7363a9f | 356 | */ |
Sissors | 0:6757f7363a9f | 357 | char read( char adress); |
Sissors | 0:6757f7363a9f | 358 | |
Sissors | 0:6757f7363a9f | 359 | /** |
Sissors | 0:6757f7363a9f | 360 | * Read multtiple regigsters from the device, more efficient than using multiple normal reads. |
Sissors | 0:6757f7363a9f | 361 | * |
Sissors | 0:6757f7363a9f | 362 | * @param adress - register address to write to |
Sissors | 0:6757f7363a9f | 363 | * @param length - number of bytes to read |
Sissors | 0:6757f7363a9f | 364 | * @param data - pointer where the data needs to be written to |
Sissors | 0:6757f7363a9f | 365 | */ |
Sissors | 0:6757f7363a9f | 366 | void read( char adress, char *data, int length); |
Sissors | 0:6757f7363a9f | 367 | |
Sissors | 0:6757f7363a9f | 368 | |
Sissors | 0:6757f7363a9f | 369 | |
Sissors | 0:6757f7363a9f | 370 | |
Sissors | 0:6757f7363a9f | 371 | private: |
Sissors | 0:6757f7363a9f | 372 | |
Sissors | 1:a3366f09e95c | 373 | I2C connection; |
Sissors | 0:6757f7363a9f | 374 | char currentAcceleroRange; |
Sissors | 0:6757f7363a9f | 375 | char currentGyroRange; |
Sissors | 0:6757f7363a9f | 376 | |
Sissors | 0:6757f7363a9f | 377 | |
Sissors | 0:6757f7363a9f | 378 | }; |
Sissors | 0:6757f7363a9f | 379 | |
Sissors | 0:6757f7363a9f | 380 | |
Sissors | 0:6757f7363a9f | 381 | |
Sissors | 0:6757f7363a9f | 382 | #endif |