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: mbed Madgwickfilter MPU6050
Diff: main.cpp
- Revision:
- 3:9424c6493a75
- Parent:
- 0:07431908151a
- Child:
- 4:fdba5e452d36
diff -r 03deb0182a20 -r 9424c6493a75 main.cpp
--- a/main.cpp Fri Sep 08 02:51:46 2017 +0000
+++ b/main.cpp Fri Sep 08 18:01:40 2017 +0000
@@ -35,31 +35,34 @@
MPU6050 mpu6050;
Timer t;
+
+ Serial pc(USBTX, USBRX); // tx, rx
int main()
{
+ pc.baud(9600);
+
//Set up I2C
i2c.frequency(400000); // use fast (400 kHz) I2C
- t.start();
+ t.start();
// Read the WHO_AM_I register, this is a good test of communication
uint8_t whoami = mpu6050.readByte(MPU6050_ADDRESS, WHO_AM_I_MPU6050); // Read WHO_AM_I register for MPU-6050
- //pc.printf("I AM 0x%x\n\r", whoami); pc.printf("I SHOULD BE 0x68\n\r");
+ pc.printf("I AM 0x%x\n\r", whoami); pc.printf("I SHOULD BE 0x68\n\r");
if (whoami == 0x68) // WHO_AM_I should always be 0x68
{
+ pc.printf("MPU6050 is online...");
wait(1);
mpu6050.MPU6050SelfTest(SelfTest); // Start by performing self test and reporting values
- /*
pc.printf("x-axis self test: acceleration trim within : "); pc.printf("%f", SelfTest[0]); pc.printf("% of factory value \n\r");
pc.printf("y-axis self test: acceleration trim within : "); pc.printf("%f", SelfTest[1]); pc.printf("% of factory value \n\r");
pc.printf("z-axis self test: acceleration trim within : "); pc.printf("%f", SelfTest[2]); pc.printf("% of factory value \n\r");
pc.printf("x-axis self test: gyration trim within : "); pc.printf("%f", SelfTest[3]); pc.printf("% of factory value \n\r");
pc.printf("y-axis self test: gyration trim within : "); pc.printf("%f", SelfTest[4]); pc.printf("% of factory value \n\r");
pc.printf("z-axis self test: gyration trim within : "); pc.printf("%f", SelfTest[5]); pc.printf("% of factory value \n\r");
- */
wait(1);
if(SelfTest[0] < 1.0f && SelfTest[1] < 1.0f && SelfTest[2] < 1.0f && SelfTest[3] < 1.0f && SelfTest[4] < 1.0f && SelfTest[5] < 1.0f)
@@ -72,26 +75,15 @@
}
else
{
- /*
pc.printf("Device did not the pass self-test!\n\r");
- lcd.clear();
- lcd.printString("MPU6050", 0, 0);
- lcd.printString("no pass", 0, 1);
- lcd.printString("self test", 0, 2); */
}
}
else
{
- /*pc.printf("Could not connect to MPU6050: \n\r");
+ pc.printf("Could not connect to MPU6050: \n\r");
pc.printf("%#x \n", whoami);
- lcd.clear();
- lcd.printString("MPU6050", 0, 0);
- lcd.printString("no connection", 0, 1);
- lcd.printString("0x", 0, 2); lcd.setXYAddress(20, 2); lcd.printChar(whoami);
- */
-
while(1) ; // Loop forever if communication doesn't happen
}
@@ -140,7 +132,6 @@
delt_t = t.read_ms() - count;
if (delt_t > 500) { // update LCD once per half-second independent of read rate
- /*
pc.printf("ax = %f", 1000*ax);
pc.printf(" ay = %f", 1000*ay);
pc.printf(" az = %f mg\n\r", 1000*az);
@@ -156,14 +147,6 @@
pc.printf("q2 = %f\n\r", q[2]);
pc.printf("q3 = %f\n\r", q[3]);
- lcd.clear();
- lcd.printString("MPU6050", 0, 0);
- lcd.printString("x y z", 0, 1);
- lcd.setXYAddress(0, 2); lcd.printChar((char)(1000*ax));
- lcd.setXYAddress(20, 2); lcd.printChar((char)(1000*ay));
- lcd.setXYAddress(40, 2); lcd.printChar((char)(1000*az)); lcd.printString("mg", 66, 2);
- */
-
// Define output variables from updated quaternion---these are Tait-Bryan angles, commonly used in aircraft orientation.
// In this coordinate system, the positive z-axis is down toward Earth.
@@ -189,10 +172,10 @@
// pc.printf("%f\n\r", roll);
// pc.printf("average rate = "); pc.printf("%f", (sumCount/sum)); pc.printf(" Hz\n\r");
- //pc.printf("Yaw, Pitch, Roll: %f %f %f\n\r", yaw, pitch, roll);
- //pc.printf("average rate = %f\n\r", (float) sumCount/sum);
+ pc.printf("Yaw, Pitch, Roll: %f %f %f\n\r", yaw, pitch, roll);
+ pc.printf("average rate = %f\n\r", (float) sumCount/sum);
- //myled= !myled;
+ myled= !myled;
count = t.read_ms();
sum = 0;
sumCount = 0;