2020/6/16

Dependencies:   mbed BMX055 SDFileSystem

Files at this revision

API Documentation at this revision

Comitter:
Takagisyuiti
Date:
Thu Oct 29 07:32:17 2020 +0000
Parent:
0:68bf06937509
Commit message:
BMX

Changed in this revision

SDFileSystem.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 68bf06937509 -r f54eae4853ca SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Thu Oct 29 07:32:17 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/2020_CEES_ModelRocket/code/SDFileSystem/#8a9e4765abcb
diff -r 68bf06937509 -r f54eae4853ca main.cpp
--- a/main.cpp	Tue Jun 16 04:52:27 2020 +0000
+++ b/main.cpp	Thu Oct 29 07:32:17 2020 +0000
@@ -1,25 +1,38 @@
 #include "mbed.h"
 #include "BMX055.h"
+#include "SDFileSystem.h"
 
+SDFileSystem sd(PA_7, PA_6, PA_5, PA_4, "sd"); // the pinout on the mbed Cool Components workshop board
 DigitalOut myled(LED1);
-BMX055 bmx(p28,p27);//SDA,SCL
+
+BMX055 bmx(PB_7,PB_6);//SDA,SCL
 Serial pc(USBTX, USBRX);
 double a[3],b[3],c[3];
+int r;
 
 int main() {
-    while(1) {
+    mkdir("/sd/mydir00", 0777);
+    FILE *fp = fopen("/sd/mydir00/sddata.csv", "w");
+    if(fp == NULL) {
+        error("Could not open file for write\n");
+    }
+    
+    r=0;
+    while(1000>r) {
         bmx.getAcc();
         bmx.getGyro();
         bmx.getMag();
-        for(int i=0;i<=3;i++){
-            a[i]=(bmx.accel[i]/512)*9.8;
-            b[i]=(bmx.gyroscope[i]*125)/2048;
-            c[i]=bmx.magnet[i];
-            }
-        pc.printf("%2.4f,%2.4f, %2.4f, %2.4f,%2.4f, %2.4f, %2.4f,%2.4f, %2.4f\r\n",a[0],a[1],a[2],b[0],b[1],b[2],c[0],c[1],c[2]);
+        
+    fprintf(fp,"%2.4f,%2.4f,%2.4f,%2.4f,%2.4f,%2.4f,%2.4f,%2.4f,%2.4f\n\r",(bmx.accel[0]/512)*9.8f,
+        (bmx.accel[1]/512)*9.8f,(bmx.accel[2]/512)*9.8f,(bmx.gyroscope[0]*125)/2048.0f,
+        (bmx.gyroscope[1]*125)/2048.0f,(bmx.gyroscope[2]*125)/2048.0f,bmx.magnet[0]/3.0f,bmx.magnet[1]/3.0f,bmx.magnet[2]/3.0f);
+        
+        pc.printf("%2.4f,%2.4f, %2.4f, %2.4f,%2.4f, %2.4f, %2.4f,%2.4f, %2.4f\r\n",bmx.accel[0],bmx.accel[1],bmx.accel[2],bmx.gyroscope[0],bmx.gyroscope[1],bmx.gyroscope[2],bmx.magnet[0],bmx.magnet[1],bmx.magnet[2]);
         //pc.printf("%2.4f, %2.4f, %2.4f, ",(bmx.accel[0]/512)*9.8,(bmx.accel[1]/512)*9.8,(bmx.accel[2]/512)*9.8);
         //pc.printf("%2.4f, %2.4f, %2.4f, ",(bmx.gyroscope[0]*125)/2048,(bmx.gyroscope[1]*125)/2048,(bmx.gyroscope[2]*125)/2048);       
-        //pc.printf("%2.4f, %2.4f, %2.4f\r\n",bmx.magnet[0],bmx.magnet[1],bmx.magnet[2]);
-        wait(0.2);
+        //pc.printf("%2.4f, %2.4f, %2.4f\r\n",bmx.magnet[0],bmx.magnet[1],bmx.magnet[2])
+        r++;
+    //    wait(0.2);
     }
+    fclose(fp);
 }