This program use the STM32L152 developement board and the MPU-9250 9-axis InvenSense movement sensor. The communication between both devices is made through I2C serial interface. This algorithm calibrates and reads data from accelerometer, gyroscope, magnetometer and the internal temperature sensor. The lecture is made each time has a new meassured value (both gyro and accel data). A comunication with a computer is made using serial interface. The user can see the data measured with 1 second update rate.
Dependents: 2_MPU9250_attitude
Diff: main.cpp
- Revision:
- 2:bb20d5091065
- Parent:
- 1:61bf659e4a1f
diff -r 61bf659e4a1f -r bb20d5091065 main.cpp --- a/main.cpp Sun Jun 07 16:48:13 2015 +0000 +++ b/main.cpp Tue Sep 01 14:06:00 2015 +0000 @@ -26,6 +26,7 @@ uint32_t sumCount = 0; char buffer[14]; uint8_t dato_leido[2]; +uint8_t whoami; int main() { @@ -37,7 +38,7 @@ t.start(); // Timer ON // Read the WHO_AM_I register, this is a good test of communication - uint8_t whoami = mpu9250.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); + whoami = mpu9250.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); pc.printf("I AM 0x%x\n\r", whoami); pc.printf("I SHOULD BE 0x71\n\r"); if (I2Cstate != 0) // error on I2C @@ -107,8 +108,7 @@ // If intPin goes high, all data registers have new data if(mpu9250.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) { // On interrupt, check if data ready interrupt - - wait(5); + mpu9250.readAccelData(accelCount); // Read the x/y/z adc values // Now we'll calculate the accleration value into actual g's if (I2Cstate != 0) //error on I2C @@ -120,7 +120,6 @@ az = (float)accelCount[2]*aRes - accelBias[2]; } - wait(5); mpu9250.readGyroData(gyroCount); // Read the x/y/z adc values // Calculate the gyro value into actual degrees per second if (I2Cstate != 0) //error on I2C @@ -132,7 +131,6 @@ gz = (float)gyroCount[2]*gRes - gyroBias[2]; } - wait(5); mpu9250.readMagData(magCount); // Read the x/y/z adc values // Calculate the magnetometer values in milliGauss // Include factory calibration per data sheet and user environmental corrections @@ -144,8 +142,7 @@ my = (float)magCount[1]*mRes*magCalibration[1] - magbias[1]; mz = (float)magCount[2]*mRes*magCalibration[2] - magbias[2]; } - - wait(5); + mpu9250.getCompassOrientation(orientation); }