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: MotionDriver_6_1 SparkFunMPU9250-DMP mbed
main.cpp
- Committer:
- mbedoguz
- Date:
- 2017-08-08
- Revision:
- 2:7be1ac6eb8cb
- Parent:
- 0:c6daf7016b8c
- Child:
- 3:740f15b45cb8
File content as of revision 2:7be1ac6eb8cb:
/*#include "mbed.h"
#include "inv_mpu.h"
#include "mdcompat.h"
Serial pc(USBTX,USBRX);
DigitalOut led(LED1);
int main()
{
imu_init();
while(1){
led=1;
wait_ms(100);
led=0;
wait_ms(100);
}
}*/
#include "SparkFunMPU9250-DMP.h"
#include "mdcompat.h"
Serial pc(USBTX,USBRX);
DigitalOut led(LED1);
MPU9250_DMP imu;
char datax[1]={0};
long DEBUG[]={2,2,2,2};
int main()
{
pc.baud(115200);
pc.printf("Hello World\n");
// Call imu.begin() to verify communication and initialize
pc.printf("imu.begin()is being run\n");
if (imu.begin() != INV_SUCCESS){
pc.printf("imu.begin() have failed");
while (1){
pc.printf("Unable to communicate with MPU-9250");
pc.printf("Check connections, and try again.\n");
wait_ms(5000);
}
}
pc.printf("imu.begin() suceeded\n");
imu.dmpBegin(DMP_FEATURE_6X_LP_QUAT | // Enable 6-axis quat
DMP_FEATURE_GYRO_CAL, // Use gyro calibration
20); // Set DMP FIFO rate to 20 Hz
// DMP_FEATURE_LP_QUAT can also be used. It uses the
// accelerometer in low-power mode to estimate quat's.
// DMP_FEATURE_LP_QUAT and 6X_LP_QUAT are mutually exclusive
pc.printf("imu.dmpBegin() suceeded\n");
while(1){
// Check for new data in the FIFO
led=1;
wait_ms(500);
led=0;
wait_ms(500);
mbed_i2c_read((unsigned char)0x68,(unsigned char)0x75,1,datax);
pc.printf("%d",datax[0]);
if ( imu.fifoAvailable() ){//fifo is not being available
led=0;
wait_ms(100);
led=1;
wait_ms(100);
// Use dmpUpdateFifo to update the ax, gx, mx, etc. values
if ( imu.dmpUpdateFifo(DEBUG) == INV_SUCCESS){
// computeEulerAngles can be used -- after updating the
// quaternion values -- to estimate roll, pitch, and yaw
imu.computeEulerAngles();
//printIMUData();
#if 1
pc.printf("%lf",DEBUG[0]);
pc.printf("\t");
pc.printf("%lf",DEBUG[1]);
pc.printf("\t");
pc.printf("%lf",DEBUG[2]);
pc.printf("\t");
pc.printf("%lf\n ",DEBUG[3]);
#endif
}
}
}
return 0;
}
void printIMUData(void)
{
// After calling dmpUpdateFifo() the ax, gx, mx, etc. values
// are all updated.
// Quaternion values are, by default, stored in Q30 long
// format. calcQuat turns them into a float between -1 and 1
float q0 = imu.calcQuat(imu.qw);
float q1 = imu.calcQuat(imu.qx);
float q2 = imu.calcQuat(imu.qy);
float q3 = imu.calcQuat(imu.qz);
pc.printf("R:%lf P:%lf Y:%lf \n", imu.roll,imu.pitch,imu.yaw);
}