for Airio-Base. getting data of "Seeed Grove 6-Axis v1.0" write to FlashAir(SD card).

Dependencies:   LSM6DS3 SDFileSystem mbed

Code URL

https://os.mbed.com/users/mbed_crane_elec/code/Airio-Base_Grove_6Axis/

Airio-Baseで 6軸センサーデータ取得とSDカードへの記録をするサンプルコードです。

準備

SWスイッチ動作

SWを押している間、LED2が点灯します。それ以外はなにもありません。

ISPスイッチ動作

SDカードにアクセスしカレントディレクトリに「TEST.txt」を作成し 6軸センサーからデータを0.4秒ごと5回のデータを取得して記録します。動作中LED1が点滅します。

取得データの確認

データの取得と記録が成功すると、以下のようなテキストデータがFlashAir等(SDカード)内に記録されます。複数回してもデータは上書きされます。FlashAirはAirio-Baseに装着のまま、PCやスマートフォンからFlashAirにアクセスし確認してみて下さい。

gx:5.929108 gy:1.876678 gz:-4.972076
ax:-0.001160 ay:0.264648 az:0.943542
temp:24.437500
gx:1.076660 gy:-3.140259 gz:-3.491669
ax:-0.021118 ay:0.237671 az:1.003906
temp:24.437500
gx:1.330872 gy:-3.147736 gz:-3.506622
ax:-0.019226 ay:0.236206 az:1.006042
temp:24.437500
gx:1.323395 gy:-3.125305 gz:-3.529053
ax:-0.021790 ay:0.237000 az:1.002136
temp:24.437500
gx:1.413116 gy:-3.259888 gz:-3.506622
ax:-0.019592 ay:0.235168 az:1.004089
temp:24.437500

Files at this revision

API Documentation at this revision

Comitter:
mbed_crane_elec
Date:
Thu Aug 09 00:44:04 2018 +0000
Commit message:
1st release.

Changed in this revision

LSM6DS3.lib Show annotated file Show diff for this revision Revisions of this file
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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r d6f289df4a08 LSM6DS3.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM6DS3.lib	Thu Aug 09 00:44:04 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/5hel2l2y/code/LSM6DS3/#ed14e6196255
diff -r 000000000000 -r d6f289df4a08 SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Thu Aug 09 00:44:04 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/respon/code/SDFileSystem/#abfb095fb178
diff -r 000000000000 -r d6f289df4a08 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Aug 09 00:44:04 2018 +0000
@@ -0,0 +1,70 @@
+#include "mbed.h"
+#include "SDFileSystem.h"
+#include "LSM6DS3.h"
+ 
+//-------------------------------------------------------------------------------
+//Port Settings
+DigitalOut led1(LED1);
+DigitalOut led2(P1_13,0);
+//DigitalOut USB_CONNECT(P0_6,0);
+DigitalIn sw(P1_20);
+DigitalIn isp(P0_1);
+DigitalOut sd_en(P1_16, 1);//SD card power on/off control port. and ON default.
+//DigitalIn sd_dat3(P0_17); // 0x10
+//DigitalIn sd_dat2(P1_22); // 0x08
+//DigitalIn sd_dat1(P1_14); // 0x04
+//DigitalIn sd_dat0(P0_22); // 0x02
+//DigitalIn sd_cmd(P0_21);  // 0x01
+ 
+//-------------------------------------------------------------------------------
+//
+SDFileSystem fs(P0_21, P0_22, P1_15, P0_17, "sd"); // mosi(CMD), miso(DAT0), sclk(CLK), cs(DAT3)
+LSM6DS3 lsm(P0_5, P0_4, LSM6DS3_AG_I2C_ADDR(0) );//I2C ADDR 0x6A
+ 
+ 
+//-------------------------------------------------------------------------------
+//
+int main()
+{
+    while(1)
+    {
+        led1 = 1;
+        wait(0.2);
+        led1 = 0;
+        wait(0.2);
+        
+        if(sw == 0)
+        {
+            led2 = 0;
+        }
+        else
+        {
+            led2 = 1;
+        }
+        
+        if(isp == 0)
+        {       
+            FILE *fp = fopen("/sd/TEST.txt", "w");
+            if(fp != NULL)
+            {
+                lsm.begin();
+                for(int i = 0;i < 5;i++)
+                {
+                    led2 = 0;
+                    wait(0.1);
+                    lsm.readGyro();
+                    fprintf(fp,"gx:%f gy:%f gz:%f\r\n",lsm.gx ,lsm.gy ,lsm.gz);
+                    lsm.readAccel();
+                    fprintf(fp,"ax:%f ay:%f az:%f\r\n",lsm.ax ,lsm.ay ,lsm.az);
+                    lsm.readTemp();
+                    fprintf(fp,"temp:%f\r\n",lsm.temperature_c );
+                    led2 = 1;
+                    wait(0.3);
+                }
+                fprintf(fp,"\r\n");
+                fclose(fp);
+                free(fp);
+            }
+        }
+    }
+}
diff -r 000000000000 -r d6f289df4a08 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Aug 09 00:44:04 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file