This is my program.

Dependencies:   SDFileSystem X_NUCLEO_IKS01A2 mbed

Fork of HelloWorld_IKS01A2 by ST

Revision:
18:1aabdb577e76
Parent:
13:fc873da5b445
--- a/main.cpp	Wed Sep 27 15:48:21 2017 +0000
+++ b/main.cpp	Sun May 27 06:39:01 2018 +0000
@@ -39,16 +39,19 @@
 /* Includes */
 #include "mbed.h"
 #include "XNucleoIKS01A2.h"
+#include "SDFileSystem.h"
+
+SDFileSystem sd(D11, D12, D13, D10, "sd");
 
 /* Instantiate the expansion board */
 static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
 
 /* Retrieve the composing elements of the expansion board */
-static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer;
-static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor;
-static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor;
-static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
-static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer;
+static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer; //磁力計
+static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor;//温度計
+static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor; //圧力計
+static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro; //ジャイロスコープ 500dps
+static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer; //加速度 16g
 
 /* Helper function for printing floats & doubles */
 static char *print_double(char* str, double v, int decimalDigits=2)
@@ -87,11 +90,16 @@
 }
 
 /* Simple main function */
+
 int main() {
   uint8_t id;
   float value1, value2;
   char buffer1[32], buffer2[32];
   int32_t axes[3];
+  int t=0;
+  
+  /*ファイル作成*/
+  FILE *fp = fopen("/sd/sensor_log.txt", "w");
   
   /* Enable all sensors */
   hum_temp->enable();
@@ -114,6 +122,15 @@
   acc_gyro->read_id(&id);
   printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id);
  
+  mkdir("/sd/mydir", 0777);
+
+    if(fp == NULL) {
+        error("Could not open file for write\n");
+    }
+   
+
+ 
+ 
   while(1) {
     printf("\r\n");
 
@@ -129,16 +146,25 @@
 
     magnetometer->get_m_axes(axes);
     printf("LSM303AGR [mag/mgauss]:  %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+    fprintf(fp,"LSM303AGR [mag/mgauss]:  %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
     
     accelerometer->get_x_axes(axes);
     printf("LSM303AGR [acc/mg]:  %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
-
+    fprintf(fp,"LSM303AGR [acc/mg]:  %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+   
     acc_gyro->get_x_axes(axes);
     printf("LSM6DSL [acc/mg]:      %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
-
+    //fprintf(fp,"LSM6DSL [acc/mg]:      %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+   
     acc_gyro->get_g_axes(axes);
     printf("LSM6DSL [gyro/mdps]:   %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
-
-    wait(1.5);
-  }
+    fprintf(fp,"LSM6DSL [gyro/mdps]:   %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+    t=t++;
+    wait(0.01);
+    if(t==10000){
+        fclose(fp); 
+        break;
+        }
+  
 }
+}