This is an example of a tilt compensated eCompass running on a K64F Freedom Platform using the on board FXOS8700 6 axis sensor and Freescale's eCompass software library in a linkable object library compiled for a FPU enabled Cortex M4. This version also used the LCD in an App Shield to display navigation data.

Dependencies:   C12832 FXOS8700Q eCompass_FPU_Lib mbed-rtos mbed

Fork of K64F_eCompass by Jim Carver

Files at this revision

API Documentation at this revision

Comitter:
JimCarver
Date:
Mon Apr 21 23:13:22 2014 +0000
Parent:
1:788e16551392
Commit message:
Another K64F eCompass that used the LCD on an app shield to display heading data

Changed in this revision

C12832.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 788e16551392 -r 770f77c92bab C12832.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Mon Apr 21 23:13:22 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/chris/code/C12832/#7de323fa46fe
diff -r 788e16551392 -r 770f77c92bab main.cpp
--- a/main.cpp	Mon Apr 14 17:17:00 2014 +0000
+++ b/main.cpp	Mon Apr 21 23:13:22 2014 +0000
@@ -2,13 +2,17 @@
 #include "FXOS8700Q.h"
 #include "eCompass_Lib.h"
 #include "rtos.h"
-
+#include "C12832.h"
 
-
+// Using Arduino pin notation
+C12832 lcd(D11, D13, D12, D7, D10); // App shield LCD
 FXOS8700Q combo1( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
 Serial pc(USBTX, USBRX);
 DigitalOut gpo(D0);
-DigitalOut led(LED_RED);
+DigitalOut red(LED_RED);
+DigitalOut led(D5);
+DigitalOut green(LED_GREEN);
+DigitalOut blue(LED_BLUE);
 eCompass compass;
 
 extern axis6_t axis6;
@@ -46,6 +50,45 @@
     printf("Quaternion: Q0= %1.4f Q1= %1.4f Q2= %1.4f Q3= %1.4f\r\n\r\n", axis6.q0, axis6.q1, axis6.q2, axis6.q3); 
 }
 
+void doRGB(void)
+{
+    int16_t h;
+    h = axis6.yaw;
+    if((h >= 358) || (h <= 2)) {
+        red = 1;
+        green = 0;
+        blue = 1;
+        return;
+        }
+    if((h >= 353) || (h <= 7)) {
+        red = 1;
+        green = 0;
+        blue = 0;
+        return;
+        }
+    if((h >=  85) && (h <=  95)) {
+        red = 0;
+        green = 1;
+        blue = 1;
+        return;
+        }
+    if((h >= 265) && (h <= 275)) {
+        red = 0;
+        green = 1;
+        blue = 1;
+        return;
+        }
+    if((h >= 175) && (h <= 185)) {
+        red = 0;
+        green = 1;
+        blue = 0;
+        return;
+        }
+    red = 1;
+    green = 1;
+    blue = 1;
+}
+    
 
 void compass_thread(void const *argument) {
     static int16_t acc_raw[3], mag_raw[3];
@@ -53,12 +96,14 @@
     combo1.AccXYZraw( acc_raw);
     combo1.MagXYZraw( mag_raw);
     if(tcount) compass.run( acc_raw, mag_raw); // calculate the eCompass
+    if(!l)      led = 0;
+        else    led = 1;
+    doRGB();
     if(l++ >= 50) { // take car of business once a second
         seconds++;
         debug_print();
         compass.calibrate(); // re-calibrate the eCompass every second
         l = 0;
-        led = !led;
         }
     tcount++;
 }
@@ -68,7 +113,13 @@
 uint8_t d[2];
 int16_t acc_raw[3], mag_raw[3];
 d[0] = 0;
+red = 1;
+green = 1;
+blue = 1;
 //cdebug = 1;  // uncomment to disable compass
+lcd.cls();
+lcd.locate(0,1);
+lcd.printf("K64F eCompass");
 printf("\r\n\n\n\n\n\n\n");
 combo1.enable();
 combo1.readRegs( FXOS8700Q_STATUS, d, 1);
@@ -89,5 +140,11 @@
 
 RtosTimer compass_timer(compass_thread, osTimerPeriodic);
 compass_timer.start(20); // Run the Compass every 20ms
-Thread::wait(osWaitForever);  
+while(1) {
+    lcd.locate(0,11);
+    lcd.printf("Seconds: %04d Heading: %03d", seconds, axis6.yaw);
+    lcd.locate(0,22);
+    lcd.printf("Roll   : %03d  Pitch: %02d", axis6.roll, axis6.pitch);
+    wait(0.1);
+    }
 }