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 Oct 29 06:58:28 2016 +0000
Revision:
3:98c49df25889
Parent:
0:e1c215fe231c
Child:
4:e68880ae8048
Initial Commit. Writing all data from 6-axis to sd card every .001 second.

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 3:98c49df25889 3 #include <stdio.h>
rahutchinson 3:98c49df25889 4 #include <stdlib.h>
rahutchinson 3:98c49df25889 5 #include <string.h>
rahutchinson 3:98c49df25889 6 #include "mbed.h"
rahutchinson 3:98c49df25889 7 #include "FXOS8700Q.h"
rahutchinson 3:98c49df25889 8
rahutchinson 3:98c49df25889 9
rahutchinson 3:98c49df25889 10 //FXOS8700Q acc( A4, A5, FXOS8700CQ_SLAVE_ADDR0); // Proper Ports and I2C address for Freescale Multi Axis shield
rahutchinson 3:98c49df25889 11 //FXOS8700Q mag( A4, A5, FXOS8700CQ_SLAVE_ADDR0); // Proper Ports and I2C address for Freescale Multi Axis shield
rahutchinson 3:98c49df25889 12 FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
rahutchinson 3:98c49df25889 13 FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
rahutchinson 3:98c49df25889 14
rahutchinson 3:98c49df25889 15 Serial pc(USBTX, USBRX);
rahutchinson 3:98c49df25889 16
rahutchinson 3:98c49df25889 17 MotionSensorDataUnits mag_data;
rahutchinson 3:98c49df25889 18 MotionSensorDataUnits acc_data;
rahutchinson 3:98c49df25889 19
rahutchinson 3:98c49df25889 20 MotionSensorDataCounts mag_raw;
rahutchinson 3:98c49df25889 21 MotionSensorDataCounts acc_raw;
Kojto 0:e1c215fe231c 22
Kojto 0:e1c215fe231c 23 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
rahutchinson 3:98c49df25889 24
Kojto 0:e1c215fe231c 25 FILE *fp;
Kojto 0:e1c215fe231c 26
Kojto 0:e1c215fe231c 27 int main()
Kojto 0:e1c215fe231c 28 {
rahutchinson 3:98c49df25889 29 float faX, faY, faZ;
rahutchinson 3:98c49df25889 30 float fmX, fmY, fmZ;
rahutchinson 3:98c49df25889 31 int16_t raX, raY, raZ;
rahutchinson 3:98c49df25889 32 int16_t rmX, rmY, rmZ;
rahutchinson 3:98c49df25889 33 acc.enable();
Kojto 0:e1c215fe231c 34 pc.printf("Initializing \n");
rahutchinson 3:98c49df25889 35 mkdir("/sd/test", 0777);
rahutchinson 3:98c49df25889 36
rahutchinson 3:98c49df25889 37 fp = fopen("/sd/test/testing.txt", "a+");
Kojto 0:e1c215fe231c 38 if (fp == NULL) {
Kojto 0:e1c215fe231c 39 pc.printf("Unable to write the file \n");
Kojto 0:e1c215fe231c 40 } else {
rahutchinson 3:98c49df25889 41 fprintf(fp, "\nTesting Reset _________________________________\n");
rahutchinson 3:98c49df25889 42 fprintf(fp, "Data goes here\n");
Kojto 0:e1c215fe231c 43 fclose(fp);
rahutchinson 3:98c49df25889 44 int count = 0;
rahutchinson 3:98c49df25889 45 while(true){
rahutchinson 3:98c49df25889 46 count =0;
rahutchinson 3:98c49df25889 47 fp = fopen("/sd/test/testing.txt", "a+");
rahutchinson 3:98c49df25889 48 while (count <1000) {
rahutchinson 3:98c49df25889 49 acc.getAxis(acc_data);
rahutchinson 3:98c49df25889 50 mag.getAxis(mag_data);
rahutchinson 3:98c49df25889 51 fprintf(fp,"FXOS8700Q ACC:__ X=%1.4f Y=%1.4f Z=%1.4f ", acc_data.x, acc_data.y, acc_data.z);
rahutchinson 3:98c49df25889 52 fprintf(fp," MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag_data.x, mag_data.y, mag_data.z);
rahutchinson 3:98c49df25889 53 acc.getX(&faX);
rahutchinson 3:98c49df25889 54 acc.getY(&faY);
rahutchinson 3:98c49df25889 55 acc.getZ(&faZ);
rahutchinson 3:98c49df25889 56 mag.getX(&fmX);
rahutchinson 3:98c49df25889 57 mag.getY(&fmY);
rahutchinson 3:98c49df25889 58 mag.getZ(&fmZ);
rahutchinson 3:98c49df25889 59 fprintf(fp,"FXOS8700Q ACC:__ X=%1.4f Y=%1.4f Z=%1.4f ", faX, faY, faZ);
rahutchinson 3:98c49df25889 60 fprintf(fp," MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", fmX, fmY, fmZ);
rahutchinson 3:98c49df25889 61 acc.getAxis(acc_raw);
rahutchinson 3:98c49df25889 62 mag.getAxis(mag_raw);
rahutchinson 3:98c49df25889 63 fprintf(fp,"FXOS8700Q ACC: X=%d Y=%d Z=%d ", acc_raw.x, acc_raw.y, acc_raw.z);
rahutchinson 3:98c49df25889 64 fprintf(fp," MAG: X=%d Y=%d Z=%d\r\n", mag_raw.x, mag_raw.y, mag_raw.z);
rahutchinson 3:98c49df25889 65 acc.getX(&raX);
rahutchinson 3:98c49df25889 66 acc.getY(&raY);
rahutchinson 3:98c49df25889 67 acc.getZ(&raZ);
rahutchinson 3:98c49df25889 68 mag.getX(&rmX);
rahutchinson 3:98c49df25889 69 mag.getY(&rmY);
rahutchinson 3:98c49df25889 70 mag.getZ(&rmZ);
rahutchinson 3:98c49df25889 71 fprintf(fp,"FXOS8700Q ACC: X=%d Y=%d Z=%d ", raX, raY, raZ);
rahutchinson 3:98c49df25889 72 fprintf(fp," MAG: X=%d Y=%d Z=%d\r\n\n", rmX, rmY, rmZ);
rahutchinson 3:98c49df25889 73 wait(.001);
rahutchinson 3:98c49df25889 74 count = count +1;
rahutchinson 3:98c49df25889 75 }
rahutchinson 3:98c49df25889 76 fclose(fp);
rahutchinson 3:98c49df25889 77 }
rahutchinson 3:98c49df25889 78
Kojto 0:e1c215fe231c 79 }
rahutchinson 3:98c49df25889 80
Kojto 0:e1c215fe231c 81
Kojto 0:e1c215fe231c 82 }