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

Committer:
rahutchinson
Date:
Sat Nov 12 03:47:46 2016 +0000
Revision:
4:e68880ae8048
Parent:
3:98c49df25889
Updated with new files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 0:e1c215fe231c 1 #include "mbed.h"
Kojto 0:e1c215fe231c 2 #include "SDFileSystem.h"
rahutchinson 4:e68880ae8048 3 #include "FXOS8700Q.h"
rahutchinson 3:98c49df25889 4 #include <stdio.h>
rahutchinson 3:98c49df25889 5 #include <stdlib.h>
rahutchinson 3:98c49df25889 6 #include <string.h>
rahutchinson 3:98c49df25889 7
rahutchinson 4:e68880ae8048 8 //Port Assignments________________________________________________________________________________________________
rahutchinson 3:98c49df25889 9 FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
rahutchinson 3:98c49df25889 10 FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
rahutchinson 3:98c49df25889 11
rahutchinson 4:e68880ae8048 12
rahutchinson 3:98c49df25889 13 Serial pc(USBTX, USBRX);
rahutchinson 4:e68880ae8048 14 //MotionSensor Data given in terms of gravity
rahutchinson 3:98c49df25889 15 MotionSensorDataUnits mag_data;
rahutchinson 3:98c49df25889 16 MotionSensorDataUnits acc_data;
rahutchinson 4:e68880ae8048 17 //MotionSensor Data Raw - Meaning that it gives in non 'Gs'
rahutchinson 3:98c49df25889 18 MotionSensorDataCounts mag_raw;
rahutchinson 3:98c49df25889 19 MotionSensorDataCounts acc_raw;
rahutchinson 4:e68880ae8048 20 //SD card initialization "sd" is what the directory is called. to access it is "/sd"
Kojto 0:e1c215fe231c 21 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
rahutchinson 4:e68880ae8048 22 //File initialization
rahutchinson 4:e68880ae8048 23 FILE *fp_raw;
rahutchinson 4:e68880ae8048 24 FILE *fp_;
rahutchinson 4:e68880ae8048 25 FILE *fp_log;
Kojto 0:e1c215fe231c 26
Kojto 0:e1c215fe231c 27 int main()
Kojto 0:e1c215fe231c 28 {
rahutchinson 4:e68880ae8048 29
rahutchinson 4:e68880ae8048 30
rahutchinson 4:e68880ae8048 31
rahutchinson 4:e68880ae8048 32 acc.enable(); //Enable Motion Sensor
rahutchinson 4:e68880ae8048 33
rahutchinson 4:e68880ae8048 34 //pc.printf("Initializing \n");
rahutchinson 3:98c49df25889 35 mkdir("/sd/test", 0777);
rahutchinson 4:e68880ae8048 36 fp_log = fopen("/sd/log.txt", "w");
rahutchinson 4:e68880ae8048 37 fp_= fopen("/sd/test/testing.csv", "a+");
rahutchinson 4:e68880ae8048 38 fp_raw = fopen("/sd/test/testing_raw.csv", "a+");
rahutchinson 4:e68880ae8048 39 if (fp_ == NULL) {
rahutchinson 4:e68880ae8048 40 fprintf(fp_log,"Unable to write the file \n");
rahutchinson 4:e68880ae8048 41 fclose(fp_log);
Kojto 0:e1c215fe231c 42 } else {
rahutchinson 4:e68880ae8048 43 fprintf(fp_,"Begin Here _______________________________________________");
rahutchinson 4:e68880ae8048 44 fprintf(fp_raw, "Begin Here _____________________________________________");
rahutchinson 4:e68880ae8048 45 fclose(fp_);
rahutchinson 4:e68880ae8048 46 fclose(fp_raw);
rahutchinson 3:98c49df25889 47 int count = 0;
rahutchinson 3:98c49df25889 48 while(true){
rahutchinson 3:98c49df25889 49 count =0;
rahutchinson 4:e68880ae8048 50 fp_ = fopen("/sd/test/testing.csv", "a+");
rahutchinson 4:e68880ae8048 51 fp_raw = fopen("/sd/test/testing_raw.csv","a+");
rahutchinson 4:e68880ae8048 52 while (count <100) {
rahutchinson 3:98c49df25889 53 acc.getAxis(acc_data);
rahutchinson 3:98c49df25889 54 mag.getAxis(mag_data);
rahutchinson 4:e68880ae8048 55 fprintf(fp_,"%1.5f,%1.5f,%1.5f, ", acc_data.x, acc_data.y, acc_data.z);
rahutchinson 4:e68880ae8048 56 fprintf(fp_,"%4.3f, %4.3f, %4.3f\r\n", mag_data.x, mag_data.y, mag_data.z);
rahutchinson 3:98c49df25889 57 acc.getAxis(acc_raw);
rahutchinson 3:98c49df25889 58 mag.getAxis(mag_raw);
rahutchinson 4:e68880ae8048 59 fprintf(fp_raw,"%d,%d,%d,", acc_raw.x, acc_raw.y, acc_raw.z);
rahutchinson 4:e68880ae8048 60 fprintf(fp_raw,"%d, %d,%d\r\n", mag_raw.x, mag_raw.y, mag_raw.z);
rahutchinson 3:98c49df25889 61 wait(.001);
rahutchinson 3:98c49df25889 62 count = count +1;
rahutchinson 3:98c49df25889 63 }
rahutchinson 4:e68880ae8048 64 fclose(fp_);
rahutchinson 4:e68880ae8048 65 fclose(fp_raw);
rahutchinson 3:98c49df25889 66 }
rahutchinson 3:98c49df25889 67
Kojto 0:e1c215fe231c 68 }
rahutchinson 3:98c49df25889 69
Kojto 0:e1c215fe231c 70
rahutchinson 4:e68880ae8048 71 }