---
# System prepended metadata

title: 安裝Edge Impulse平台工具進行Dataset收集

---

## 安裝Edge Impulse平台工具進行Dataset收集
測試用的硬體開發工具
Arduino nano 33 BLE SENSE
https://docs.edgeimpulse.com/docs/development-platforms/officially-supported-mcu-targets/arduino-nano-33-ble-sense

安裝基本環境軟體
- 安裝Python 3.7
- 安裝Node.js 16

安裝Edge Impulse Cli工具

[參考來源] https://docs.edgeimpulse.com/docs/tools/edge-impulse-cli/cli-installation 

打開終端機程式輸入以下指令
```
npm install -g edge-impulse-cli --force
```
碰到node-gyp錯誤的解決方式
https://juejin.cn/post/7042123168722452516

### Arduino程式碼
1. 先安裝Arduino 2.2.1 https://www.arduino.cc/en/software
2. 開啟Arduino之後先設置Seeed Studio XIAO nRF52840 Sense開發環境 https://www.seeedstudio.com/Seeed-XIAO-BLE-Sense-nRF52840-p-5253.html
https://wiki.seeedstudio.com/XIAO_BLE/
3. 設置Arduino的File->Preferences->增加Additional Boards Manager URLs
https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
4. 點選Arduino IDE左側的Boards Manager，輸入"seeed nrf52"
5. 安裝Seeed nRF52 Boards與Seeed nRF52 mbed-enabled Boards
6. 打開Arduino IDE左側的Library Manager，輸入"lsm6ds3"三軸加速度感測器的程式庫安裝
7. 找到"Seeed Arduino LSM6DS3"，然後點選Install安裝
8. 將以下的程式碼輸入到Arduino IDE內
```cpp=
// XIAO BLE Sense LSM6DS3 Accelerometer Raw Data 

#include "LSM6DS3.h"
#include "Wire.h"

//Create a instance of class LSM6DS3
LSM6DS3 myIMU(I2C_MODE, 0x6A);  //I2C device address 0x6A

#define CONVERT_G_TO_MS2 9.80665f
#define FREQUENCY_HZ 50
#define INTERVAL_MS (1000 / (FREQUENCY_HZ + 1))

static unsigned long last_interval_ms = 0;


void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;

  if (myIMU.begin() != 0) {
    Serial.println("Device error");
  } else {
    Serial.println("Device OK!");
  }
}



void loop() {
  if (millis() > last_interval_ms + INTERVAL_MS) {
    last_interval_ms = millis();
    Serial.print(myIMU.readFloatAccelX() * CONVERT_G_TO_MS2, 4);
    Serial.print('\t');
    Serial.print(myIMU.readFloatAccelY() * CONVERT_G_TO_MS2, 4);
    Serial.print('\t');
    Serial.println(myIMU.readFloatAccelZ() * CONVERT_G_TO_MS2, 4);
  }
}
```

9. 按下upload上傳程式碼到XIAO內
10. 開啟終端機畫面查看輸出的Data是否為


### 使用Edge Impulse工具
1. 註冊帳號 https://studio.edgeimpulse.com/login
2. 建立一個project 
3. 在Getting started的地方收集new data，所以點選Collect new data按鈕
4. 在Collect new data 選擇connect your device or development board
5. 打開終端機程式，輸入以下指令
```
edge-impulse-data-forwarder
```
6. 在終端機畫面看到:
```shell!
>Edge Impulse data forwarder v1.23.1
? What is your user name or e-mail address (edgeimpulse.com)? 輸入自己的email
? What is your password? 輸入自己的密碼 
Endpoints:
    Websocket: wss://remote-mgmt.edgeimpulse.com
    API:       https://studio.edgeimpulse.com
    Ingestion: https://ingestion.edgeimpulse.com
[SER] Connecting to 選擇要連到哪一個Comport? 可以到裝置管理員去查看
[SER] Serial is connected
[WS ] Connecting to wss://remote-mgmt.edgeimpulse.com
[WS ] Connected to wss://remote-mgmt.edgeimpulse.com
? To which project do you want to add this device? accelerometer-demo-1
? 3 sensor axes detected. What do you want to call them? Separate the names with ',': 輸入accX, accY, accZ
? What name do you want to give this device? 輸入對這個裝置的命名例如: XAIO_01
[WS ] Device "Arduino nano 33 BLE Sense(KennethLiu)" is now connected to project "Motion Recognition with XIAO BLE SENSE". To connect to another project, run `edge-impulse-data-forwarder --clean`.
[WS ] Go to https://studio.edgeimpulse.com/studio/336705/acquisition/training to build your machine learning model!
```
8.  連結完成之後回到原本的project，在Collect data的地方會看到需要定義data的Label，輸入要訓練的Label名稱，例如: draw
9. 按下Start sampling之後有10秒時間會抓取500次的取樣資料，取樣後會結束一次的Training資料
10. 確認從XIAO輸出Serial.print是按照以下的格式，每一個軸的數值中間用","做分隔
```
accX,accY,accZ
-0.12,-6.20,7.90
-0.13,-6.19,7.91
-0.14,-6.20,7.92
-0.13,-6.20,7.90
-0.14,-6.20,7.91
```

## 開始用Edge Impulse進行模型訓練
1. 當Dataset已經收集到相關Sample的Data後，可以進行模型的訓練，點選左
