Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MPU9250_SPI mbed
Fork of MPU9250_AHRS by
Diff: main.cpp
- Revision:
- 8:03f9b5289083
- Parent:
- 7:758a94e02aa7
- Child:
- 9:e700b2d586d6
--- a/main.cpp Fri Jun 17 05:31:40 2016 +0000
+++ b/main.cpp Fri Jun 17 05:46:08 2016 +0000
@@ -1,6 +1,6 @@
/**
* Masahiro FURUKAWA - m.furukawa@ist.osaka-u.ac.jp
- *
+ *
* June 17, 2016
*
* MPU9250 9DoF Sensor (Extended to Ch1 ~ Ch2)
@@ -10,7 +10,7 @@
#include "mbed.h"
#include "MPU9250.h"
-
+
/*
MOSI (Master Out Slave In) p5
MISO (Master In Slave Out p6
@@ -20,71 +20,71 @@
// https://developer.mbed.org/users/kylongmu/code/MPU9250_SPI_Test/file/5839d1b118bc/main.cpp
-int main() {
+int main()
+{
Serial pc(USBTX, USBRX);
pc.baud(115200);
-
+
SPI spi(p5, p6, p7);
//define the mpu9250 object
mpu9250_spi *imu[2];
-
+
imu[0] = new mpu9250_spi(spi, p8);
imu[1] = new mpu9250_spi(spi, p9);
-
- for(int i=0;i<2;i++){
-
+
+ for(int i=0; i<2; i++) {
+
imu[0]->deselect();
imu[1]->deselect();
imu[i]->select();
-
- if(imu[i]->init(1,BITS_DLPF_CFG_188HZ)){ //INIT the mpu9250
+
+ if(imu[i]->init(1,BITS_DLPF_CFG_188HZ)) { //INIT the mpu9250
printf("\nCouldn't initialize MPU9250 via SPI!");
- }
+ }
printf("\nWHOAMI=0x%2x\n",imu[i]->whoami()); //output the I2C address to know if SPI is working, it should be 104
- wait(1);
+ wait(1);
printf("Gyro_scale=%u\n",imu[i]->set_gyro_scale(BITS_FS_2000DPS)); //Set full scale range for gyros
- wait(1);
+ wait(1);
printf("Acc_scale=%u\n",imu[i]->set_acc_scale(BITS_FS_16G)); //Set full scale range for accs
wait(1);
printf("AK8963 WHIAM=0x%2x\n",imu[i]->AK8963_whoami());
- wait(0.1);
+ wait(0.1);
imu[i]->AK8963_calib_Magnetometer();
+ wait(0.1);
}
imu[0]->select();
imu[1]->deselect();
while(1) {
-
-
+
//myled = 1;
+
wait_us(1);
- /*
- imu[i]->read_temp();
- imu[i]->read_acc();
- imu[i]->read_rot();
- imu[i]->AK8963_read_Magnetometer();
- */
- for(int i=0;i<2;i++){
+
+ for(int i=0; i<2; i++) {
+
imu[0]->deselect();
imu[1]->deselect();
+
imu[i]->select();
imu[i]->read_all();
- printf("%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f ",
- imu[i]->Temperature,
- imu[i]->gyroscope_data[0],
- imu[i]->gyroscope_data[1],
- imu[i]->gyroscope_data[2],
- imu[i]->accelerometer_data[0],
- imu[i]->accelerometer_data[1],
- imu[i]->accelerometer_data[2],
- imu[i]->Magnetometer[0],
- imu[i]->Magnetometer[1],
- imu[i]->Magnetometer[2]
- );
- //myled = 0;
- //wait(0.5);
+
+ printf("%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f ",
+ imu[i]->Temperature,
+ imu[i]->gyroscope_data[0],
+ imu[i]->gyroscope_data[1],
+ imu[i]->gyroscope_data[2],
+ imu[i]->accelerometer_data[0],
+ imu[i]->accelerometer_data[1],
+ imu[i]->accelerometer_data[2],
+ imu[i]->Magnetometer[0],
+ imu[i]->Magnetometer[1],
+ imu[i]->Magnetometer[2]
+ );
+ //myled = 0;
+ //wait(0.5);
}
- printf("\n");
+ printf("\n");
}
}
