Richard Kuo
/
NTOUEE-mbed-I2C_MPU6500_LCD
mbed I2C IMU+LCD
main.cpp@0:73a95126993e, 2016-10-20 (annotated)
- Committer:
- rkuo2000
- Date:
- Thu Oct 20 13:16:22 2016 +0000
- Revision:
- 0:73a95126993e
- Child:
- 1:efa4c7817836
mbed I2C MPU6500
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rkuo2000 | 0:73a95126993e | 1 | // using NuMaker-PFM-NUC472 I2C0 to read 3-axis accelerometer & 3-axis gyroscope (MPU6500) |
rkuo2000 | 0:73a95126993e | 2 | #include "mbed.h" |
rkuo2000 | 0:73a95126993e | 3 | #include "mpu6500.h" |
rkuo2000 | 0:73a95126993e | 4 | |
rkuo2000 | 0:73a95126993e | 5 | I2C i2c0(PC_9, PA_15); // I2C0_SDA, I2C0_SCL |
rkuo2000 | 0:73a95126993e | 6 | |
rkuo2000 | 0:73a95126993e | 7 | MPU6500 IMU; // on-board IMU is MPU6500 |
rkuo2000 | 0:73a95126993e | 8 | |
rkuo2000 | 0:73a95126993e | 9 | int main() { |
rkuo2000 | 0:73a95126993e | 10 | int16_t accX, accY, accZ; |
rkuo2000 | 0:73a95126993e | 11 | int16_t gyroX, gyroY, gyroZ; |
rkuo2000 | 0:73a95126993e | 12 | |
rkuo2000 | 0:73a95126993e | 13 | i2c0.frequency(400000); |
rkuo2000 | 0:73a95126993e | 14 | IMU.initialize(); |
rkuo2000 | 0:73a95126993e | 15 | |
rkuo2000 | 0:73a95126993e | 16 | while(true) { |
rkuo2000 | 0:73a95126993e | 17 | accX = IMU.getAccelXvalue(); |
rkuo2000 | 0:73a95126993e | 18 | accY = IMU.getAccelYvalue(); |
rkuo2000 | 0:73a95126993e | 19 | accZ = IMU.getAccelZvalue(); |
rkuo2000 | 0:73a95126993e | 20 | gyroX= IMU.getGyroXvalue(); |
rkuo2000 | 0:73a95126993e | 21 | gyroY= IMU.getGyroYvalue(); |
rkuo2000 | 0:73a95126993e | 22 | gyroZ= IMU.getGyroZvalue(); |
rkuo2000 | 0:73a95126993e | 23 | printf("Acc: %6d, %6d, %6d, ", accX, accY, accZ); |
rkuo2000 | 0:73a95126993e | 24 | printf("Gyro:%6d, %6d, %6d\n\r", gyroX, gyroY, gyroZ); |
rkuo2000 | 0:73a95126993e | 25 | } |
rkuo2000 | 0:73a95126993e | 26 | } |