This is an example program for the Freescale multi-sensor shield, part number FRDM-FXS-MULTI

Dependencies:   FXAS21000 FXLS8471Q FXOS8700Q MAG3110 MMA8652 MPL3115A2 mbed

Revision:
1:d3ecb4ecdfda
Parent:
0:e5337522df6f
--- a/main.cpp	Sat Apr 19 01:30:29 2014 +0000
+++ b/main.cpp	Mon Jun 02 19:05:04 2014 +0000
@@ -1,6 +1,24 @@
+/* Copyright (c) 2010-2011 mbed.org, MIT License
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+* and associated documentation files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
 #include "mbed.h"
 #include "MAG3110.h"
-#include "MPL3115A2.h"
+#include "MPL3115A2.h" // May only be used on a Freescale platform, comment out for others
 #include "FXOS8700Q.h"
 #include "MMA8652.h"
 #include "FXLS8471Q.h"
@@ -9,16 +27,15 @@
 #define MPL3115A2_I2C_ADDRESS (0x60<<1)
 
 
-DigitalOut  red(LED_RED);
-
-MAG3110   mag1(A4, A5);
-MAG3110   mag2(PTE25, PTE24); // Magnetometer on KL46 board
+DigitalOut  red(LED1);
 
 FXLS8471Q acc1(D11, D12, D13, D10);
-MMA8652   acc2( A4, A5);
-MPL3115A2 alt( A4, A5, MPL3115A2_I2C_ADDRESS);
-FXOS8700Q combo( A4, A5, FXOS8700CQ_SLAVE_ADDR0);
-FXAS21000 gyro( A4, A5);
+MMA8652   acc2(A4, A5);
+FXOS8700Q_acc combo_acc(A4, A5, FXOS8700CQ_SLAVE_ADDR0);
+FXOS8700Q_mag combo_mag(A4, A5, FXOS8700CQ_SLAVE_ADDR0);
+MAG3110   mag2(A4, A5);
+FXAS21000 gyro(A4, A5);
+MPL3115A2 alt(A4, A5, MPL3115A2_I2C_ADDRESS);  // May only be used on a Freescale platform, comment out for others
 
 Serial pc(USBTX, USBRX);
 
@@ -33,7 +50,7 @@
     * dt[0] = Bits 12-19 of 20-bit real-time Altitude sample. (b7-b0)
     * dt[1] = Bits 4-11 of 20-bit real-time Altitude sample. (b7-b0)
     * dt[2] = Bits 0-3 of 20-bit real-time Altitude sample (b7-b4)
-    */    
+    */
     altm = (dt[0]<<8) | dt[1];
     //
     if ( dt[0] > 0x7F) {
@@ -51,7 +68,7 @@
 {
     unsigned short temp;
     float ftemp;
-    
+
     /*
     * dt[0] = Bits 4-11 of 16-bit real-time temperature sample. (b7-b0)
     * dt[1] = Bits 0-3 of 16-bit real-time temperature sample. (b7-b4)
@@ -71,47 +88,57 @@
 }
 
 
-int main() {
-    //int who;
+int main()
+{
     float acc_data[3], mag_data[3], gyro_data[3];
+    MotionSensorDataUnits adata;
+    MotionSensorDataUnits mdata;
     int16_t acc_raw[3];
     unsigned char raw_data[8];
-    pc.baud(115200);
+
+    printf("\r\nStarting\r\n\r\n");
+
     red = 1;
-    printf("\r\n\r\n\r\n");
+    combo_acc.enable();
+    combo_mag.enable();
+    mag2.enable();
     alt.Altimeter_Mode();
-    printf("MMA8652   Who Am I= %X\r\n", acc2.getWhoAmI());
-    printf("FXOS8700  Who Am I= %X\r\n", combo.getWhoAmI());
-    printf("FXLS8471  Who Am I= %X\r\n", acc1.getWhoAmI());
-    printf("FXAS21000 Who Am I= %X\r\n", gyro.getWhoAmI());
-    wait(5.0);
+    printf("FXLS8471 Acc   = %X\r\n", acc1.getWhoAmI());
+    printf("MMA8652 Acc    = %X\r\n", acc2.getWhoAmI());
+    printf("FXOS8700 Combo = %X\r\n", combo_acc.whoAmI());
+    printf("MAG3110 Mag    = %X\r\n", mag2.whoAmI());
+    printf("FXAS21000 Gyro = %X\r\n", gyro.getWhoAmI());
+    printf("MPL3115A2 Alt  = %X\r\n", alt.getDeviceID());  // May only be used on a Freescale platform, comment out for others
+    wait(3);
+    
     while(1) {
+        acc1.ReadXYZ(acc_data);
+        acc1.ReadXYZraw(acc_raw);
+        printf("FXLS8471 Acc: X:%1.3f Y:%1.3f Z:%1.3f (Raw X:%3d Y:%3d Z:%3d)\r\n", acc_data[0], acc_data[1], acc_data[2], acc_raw[0], acc_raw[1], acc_raw[2]);
 
-        acc1.ReadXYZ(acc_data);
-        printf("FXLS8471      X=%1.5f Y=%1.5f Z=%1.5f\r\n", acc_data[0], acc_data[1], acc_data[2]);
         acc2.ReadXYZ(acc_data);
-        printf("MMA8652       X=%1.5f Y=%1.5f Z=%1.5f\r\n", acc_data[0], acc_data[1], acc_data[2]);        
-        combo.getAccAllAxis( acc_data);
-        combo.getMagAllAxis( mag_data);
-        printf("FXOS8700 Acc: X=%1.5f Y=%1.5f Z=%1.5f", acc_data[0], acc_data[1], acc_data[2]);
-        printf(" Mag: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag_data[0], mag_data[1], mag_data[2]);
-        mag1.ReadXYZ(mag_data);
-        printf("                                            ");
-        printf(" Mag1: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag_data[0], mag_data[1], mag_data[2]);
-        mag2.ReadXYZ(mag_data);
-        printf("                                            ");
-        printf(" Mag2: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag_data[0], mag_data[1], mag_data[2]);
-        alt.getAllDataRaw( &raw_data[0]);
-        printf("\r\nAlt: %5.1f\tT: %3.1f\r\n", print_AltimiterValue( &raw_data[0]), print_TemperatureValue( &raw_data[3]));
+        acc2.ReadXYZraw(acc_raw);
+        printf("MMA8652 Acc:  X:%1.3f Y:%1.3f Z:%1.3f (Raw X:%3d Y:%3d Z:%3d)\r\n", acc_data[0], acc_data[1], acc_data[2], acc_raw[0], acc_raw[1], acc_raw[2]);
+
+        combo_acc.getAxis(adata);
+        combo_mag.getAxis(mdata);
+        printf("FXOS8700 Acc: X:%1.3f Y:%1.3f Z:%1.3f (Mag X:%4.1f Y:%4.1f Z:%4.1f)\r\n", adata.x, adata.y, adata.z, mdata.x, mdata.y, mdata.z);
+        
         gyro.ReadXYZ(gyro_data);
-        printf("FXAS21000      X=%4.2f Y=%4.2f Z=%4.1f\r\n", gyro_data[0], gyro_data[1], gyro_data[2]);
-        acc1.ReadXYZraw(acc_raw);
-        printf("FXLS8471: X= %d Y= %d Z= %d\r\n\n\n", acc_raw[0], acc_raw[1], acc_raw[2]);
-        acc2.ReadXYZraw(acc_raw);
-        printf("MMA8652: X= %d Y= %d Z= %d\r\n\n\n", acc_raw[0], acc_raw[1], acc_raw[2]);
+        printf("FXAS21000 Gyro: X:%4.2f Y:%4.2f Z:%4.1f\r\n", gyro_data[0], gyro_data[1], gyro_data[2]);
+        
+        mag2.getAxis(mdata);
+        printf("MAG3110 Mag:    X:%4.1f Y:%4.1f Z:%4.1f\r\n", mdata.x, mdata.y, mdata.z);
+
+        alt.getAllDataRaw(&raw_data[0]);  // May only be used on a Freescale platform, comment out for others
+        printf("MPL3115A2 Alt:  %5.1f\r\n", print_AltimiterValue(&raw_data[0]));  // May only be used on a Freescale platform, comment out for others
+        printf("MPL3115A2 Temp: %3.1f\r\n", print_TemperatureValue(&raw_data[3]));  // May only be used on a Freescale platform, comment out for others
+
+        printf("\r\n");
+        
         red = 1;
         wait(0.5);
         red = 0;
         wait(0.5);
-        }
+    }
 }