Uses NXP tutorial over 6 Axis Sensor and extends it to writing to csv files on the onboard sd-card.

Dependencies:   FXOS8700Q SDFileSystem mbed

Fork of FRDMK64_SDCard by NXP

Files at this revision

API Documentation at this revision

Comitter:
rahutchinson
Date:
Sat Nov 12 03:47:46 2016 +0000
Parent:
3:98c49df25889
Commit message:
Updated with new files

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 98c49df25889 -r e68880ae8048 main.cpp
--- a/main.cpp	Sat Oct 29 06:58:28 2016 +0000
+++ b/main.cpp	Sat Nov 12 03:47:46 2016 +0000
@@ -1,82 +1,71 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
+#include "FXOS8700Q.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "mbed.h"
-#include "FXOS8700Q.h"
 
-
-//FXOS8700Q acc( A4, A5, FXOS8700CQ_SLAVE_ADDR0); // Proper Ports and I2C address for Freescale Multi Axis shield
-//FXOS8700Q mag( A4, A5, FXOS8700CQ_SLAVE_ADDR0); // Proper Ports and I2C address for Freescale Multi Axis shield
+//Port Assignments________________________________________________________________________________________________
 FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
 FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
 
+
 Serial pc(USBTX, USBRX);
-
+//MotionSensor Data given in terms of gravity
 MotionSensorDataUnits mag_data;
 MotionSensorDataUnits acc_data;
-
+//MotionSensor Data Raw - Meaning that it gives in non 'Gs'
 MotionSensorDataCounts mag_raw;
 MotionSensorDataCounts acc_raw;
-
+//SD card initialization  "sd" is what the directory is called. to access it is "/sd"
 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
-
-FILE *fp;
+//File initialization
+FILE *fp_raw;
+FILE *fp_;
+FILE *fp_log;
 
 int main()
 {
-    float faX, faY, faZ;
-    float fmX, fmY, fmZ;
-    int16_t raX, raY, raZ;
-    int16_t rmX, rmY, rmZ;
-    acc.enable();
-    pc.printf("Initializing \n");
+
+    
+    
+    acc.enable(); //Enable Motion Sensor
+    
+    //pc.printf("Initializing \n");
     mkdir("/sd/test", 0777);
-   
-    fp = fopen("/sd/test/testing.txt", "a+");
-    if (fp == NULL) {
-        pc.printf("Unable to write the file \n");
+    fp_log = fopen("/sd/log.txt", "w");
+    fp_= fopen("/sd/test/testing.csv", "a+");
+    fp_raw = fopen("/sd/test/testing_raw.csv", "a+");
+    if (fp_ == NULL) {
+        fprintf(fp_log,"Unable to write the file \n");
+    fclose(fp_log);
     } else {
-        fprintf(fp, "\nTesting Reset _________________________________\n");
-        fprintf(fp, "Data goes here\n");
-        fclose(fp);
+        fprintf(fp_,"Begin Here _______________________________________________");
+        fprintf(fp_raw, "Begin Here _____________________________________________");
+        fclose(fp_);
+        fclose(fp_raw);
         int count = 0;
         while(true){
             count =0;
-            fp = fopen("/sd/test/testing.txt", "a+");
-            while (count <1000) {
+            fp_ = fopen("/sd/test/testing.csv", "a+");
+            fp_raw = fopen("/sd/test/testing_raw.csv","a+");
+            while (count <100) {
                 acc.getAxis(acc_data);
                 mag.getAxis(mag_data);
-                fprintf(fp,"FXOS8700Q ACC:__ X=%1.4f Y=%1.4f Z=%1.4f ", acc_data.x, acc_data.y, acc_data.z);
-                fprintf(fp,"    MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag_data.x, mag_data.y, mag_data.z);
-                acc.getX(&faX);
-                acc.getY(&faY);
-                acc.getZ(&faZ);
-                mag.getX(&fmX);
-                mag.getY(&fmY);
-                mag.getZ(&fmZ);
-                fprintf(fp,"FXOS8700Q ACC:__ X=%1.4f Y=%1.4f Z=%1.4f  ", faX, faY, faZ);
-                fprintf(fp,"    MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", fmX, fmY, fmZ);
+                fprintf(fp_,"%1.5f,%1.5f,%1.5f, ", acc_data.x, acc_data.y, acc_data.z);
+                fprintf(fp_,"%4.3f, %4.3f, %4.3f\r\n", mag_data.x, mag_data.y, mag_data.z);
                 acc.getAxis(acc_raw);
                 mag.getAxis(mag_raw);
-                fprintf(fp,"FXOS8700Q ACC: X=%d Y=%d Z=%d  ", acc_raw.x, acc_raw.y, acc_raw.z);
-                fprintf(fp,"    MAG: X=%d Y=%d Z=%d\r\n", mag_raw.x, mag_raw.y, mag_raw.z);
-                acc.getX(&raX);
-                acc.getY(&raY);
-                acc.getZ(&raZ);
-                mag.getX(&rmX);
-                mag.getY(&rmY);
-                mag.getZ(&rmZ);                
-                fprintf(fp,"FXOS8700Q ACC: X=%d Y=%d Z=%d  ", raX, raY, raZ);
-                fprintf(fp,"    MAG: X=%d Y=%d Z=%d\r\n\n", rmX, rmY, rmZ);    
+                fprintf(fp_raw,"%d,%d,%d,", acc_raw.x, acc_raw.y, acc_raw.z);
+                fprintf(fp_raw,"%d, %d,%d\r\n", mag_raw.x, mag_raw.y, mag_raw.z);
                 wait(.001);
                 count = count +1;
             }
-            fclose(fp);
+            fclose(fp_);
+            fclose(fp_raw);
         }
         
     }
     
 
-}
+}
\ No newline at end of file