College Project
Dependencies: mbed MPU9250_SPI_Test MPU9250-XCLIN
main.cpp@5:5839d1b118bc, 2014-07-01 (annotated)
- Committer:
- kylongmu
- Date:
- Tue Jul 01 14:16:04 2014 +0000
- Revision:
- 5:5839d1b118bc
- Parent:
- 4:6bfddd447c27
- Child:
- 6:cc0a54642cdb
Add calibration magnetometer function.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kylongmu | 3:ad2ef67e7f72 | 1 | /*CODED by Qiyong Mu on 21/06/2014 |
kylongmu | 3:ad2ef67e7f72 | 2 | kylongmu@msn.com |
kylongmu | 3:ad2ef67e7f72 | 3 | */ |
kylongmu | 0:58f9d4556df7 | 4 | #include "mbed.h" |
kylongmu | 0:58f9d4556df7 | 5 | #include "MPU9250.h" //Include library |
kylongmu | 0:58f9d4556df7 | 6 | |
kylongmu | 0:58f9d4556df7 | 7 | DigitalOut myled(LED1); |
kylongmu | 0:58f9d4556df7 | 8 | Serial pc(SERIAL_TX, SERIAL_RX); |
kylongmu | 0:58f9d4556df7 | 9 | SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); |
kylongmu | 0:58f9d4556df7 | 10 | mpu9250_spi imu(spi,SPI_CS); //define the mpu9250 object |
kylongmu | 0:58f9d4556df7 | 11 | int main(){ |
kylongmu | 0:58f9d4556df7 | 12 | pc.baud(115200); |
kylongmu | 5:5839d1b118bc | 13 | if(imu.init(1,BITS_DLPF_CFG_188HZ)){ //INIT the mpu9250 |
kylongmu | 1:7497c7952470 | 14 | printf("\nCouldn't initialize MPU9250 via SPI!"); |
kylongmu | 0:58f9d4556df7 | 15 | } |
kylongmu | 2:6de3660a1f92 | 16 | printf("\nWHOAMI=0x%2x\n",imu.whoami()); //output the I2C address to know if SPI is working, it should be 104 |
kylongmu | 1:7497c7952470 | 17 | wait(1); |
kylongmu | 2:6de3660a1f92 | 18 | printf("Gyro_scale=%u\n",imu.set_gyro_scale(BITS_FS_2000DPS)); //Set full scale range for gyros |
kylongmu | 0:58f9d4556df7 | 19 | wait(1); |
kylongmu | 2:6de3660a1f92 | 20 | printf("Acc_scale=%u\n",imu.set_acc_scale(BITS_FS_16G)); //Set full scale range for accs |
kylongmu | 1:7497c7952470 | 21 | wait(1); |
kylongmu | 2:6de3660a1f92 | 22 | printf("AK8963 WHIAM=0x%2x\n",imu.AK8963_whoami()); |
kylongmu | 1:7497c7952470 | 23 | wait(0.1); |
kylongmu | 5:5839d1b118bc | 24 | imu.AK8963_calib_Magnetometer(); |
kylongmu | 0:58f9d4556df7 | 25 | while(1) { |
kylongmu | 0:58f9d4556df7 | 26 | //myled = 1; |
kylongmu | 0:58f9d4556df7 | 27 | wait(0.1); |
kylongmu | 4:6bfddd447c27 | 28 | /* |
kylongmu | 0:58f9d4556df7 | 29 | imu.read_temp(); |
kylongmu | 0:58f9d4556df7 | 30 | imu.read_acc(); |
kylongmu | 0:58f9d4556df7 | 31 | imu.read_rot(); |
kylongmu | 1:7497c7952470 | 32 | imu.AK8963_read_Magnetometer(); |
kylongmu | 4:6bfddd447c27 | 33 | */ |
kylongmu | 4:6bfddd447c27 | 34 | imu.read_all(); |
kylongmu | 2:6de3660a1f92 | 35 | printf("%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f\n", |
kylongmu | 0:58f9d4556df7 | 36 | imu.Temperature, |
kylongmu | 0:58f9d4556df7 | 37 | imu.gyroscope_data[0], |
kylongmu | 0:58f9d4556df7 | 38 | imu.gyroscope_data[1], |
kylongmu | 0:58f9d4556df7 | 39 | imu.gyroscope_data[2], |
kylongmu | 0:58f9d4556df7 | 40 | imu.accelerometer_data[0], |
kylongmu | 0:58f9d4556df7 | 41 | imu.accelerometer_data[1], |
kylongmu | 1:7497c7952470 | 42 | imu.accelerometer_data[2], |
kylongmu | 1:7497c7952470 | 43 | imu.Magnetometer[0], |
kylongmu | 1:7497c7952470 | 44 | imu.Magnetometer[1], |
kylongmu | 1:7497c7952470 | 45 | imu.Magnetometer[2] |
kylongmu | 1:7497c7952470 | 46 | ); |
kylongmu | 0:58f9d4556df7 | 47 | //myled = 0; |
kylongmu | 0:58f9d4556df7 | 48 | //wait(0.5); |
kylongmu | 0:58f9d4556df7 | 49 | } |
kylongmu | 0:58f9d4556df7 | 50 | } |
kylongmu | 0:58f9d4556df7 | 51 |