此教學將介紹 Mini GaussSense 如何從單顆擴增至四顆串接,快速擴大感測範圍!
硬體材料
- Mini GaussSense x 4
- Mini GaussSense 四轉一麵包板轉接頭
- 磁鐵
- 麵包版
- Arduino 開發版和 USB 線
- 10 條杜邦線
開發環境
準備以下軟體環境:
- 安裝 Arduino Software (如果已安裝 Arduino 可以跳過這一步。)
- 安裝 Processing IDE (如果已安裝 Processing 可以跳過這一步。)
- 安裝 GaussSense SDK for Processing
- 下載 Arduino Firmware for 2x2 Mini GaussSense, 此檔案 (.ino) 將上傳至 Arduino 板。
串接電路
透過 2x2 4-way Mini GaussSense 麵包板轉接頭,可以大幅降低接線上的困難,按照以上的示意圖透過十條跳線連結需要的電路。
Arduino | Mini GaussSense |
---|---|
5V | V |
GND | G |
A0 | A0 |
A1 | A1 |
A2 | A2 |
A3 | A3 |
2 | S0 |
3 | S1 |
4 | S2 |
5 | S3 |
上傳 Arduino 程式碼
2x2 Mini GaussSense 的 Arduino 程式碼可以在此連結中下載: Mini GaussSense Arduino Code (filetype: zip)
下載後解壓縮檔案, 在 Mini_GaussSense_V1 資料夾後在 Arduino IDE 打開 Mini_GaussSense_V1.ino。
此 Arduino 程式碼可用於單顆 Mini GaussSense 與多顆 Mini GaussSense,在使用 2x2 Mini GaussSense 時需要做以下修改:
其中 MINI_GAUSSSENSE_AMOUNT
的數量為 4 :
const int MINI_GAUSSSENSE_AMOUNT = 4;
增加 analogInPin
對應的四個 pin 腳:
const int analogInPin[] = {A0, A1, A2, A3}; // Set the analog pins used
在 Arduino IDE 中的工具選單中選擇您的 Arduino 開發板種類與序列阜,即可上傳此份程式碼到 Arduino 板。
上傳 Arduino 程式碼
下載後解壓縮檔案, Mini_GaussSense_V1 資料夾後在 Arduino IDE 打開 Mini_GaussSense_V1.ino
在 Arduino IDE 中的工具選單中選擇您的 Arduino 開發板種類與序列阜,即可上傳此份程式碼到 Arduino 板。
準備好 Processing 開發環境並下載 Processing 的 GaussSense SDK 後,點選 File > Examples… 中的 Contributed Libraries > GaussSense SDK for Processing,如下方左圖所示,可看到 GaussSense SDK 中 Basics 的 e1_HelloGaussSense 範例 sketch,即為我們第一個範例程式。
因為目前我們串接了 2x2 (4顆) Mini GaussSense,在 GaussSense 的 Constructor 中需要修改其中 width, height 參數為 2, 2:
// Initialize the 2x2 GaussSense Grid gs = new GaussSense(this, GaussSense.GSType.GAUSSSENSE_MINI, 2, 2, Serial.list()[Serial.list().length - 1], 115200);