TensorFlow Lite for Microcontrollers的Magic wand example實作

接續前面文章與環境設定,進行TensorFlow Lite for Microcontrollers的Magic wand example實作。這個實作只對應SparkFun Edge與Arduino Nano 33 BLE Sense兩塊開發板,SparkFun Edge開發板的實作環境在Ubuntu 16.04 64bits Linux,Arduino Nano 33 BLE Sense開發板的實作環境在Windows 7 64bits上。另外,請參照閱讀TinyML: Machine Learning with TensorFlow Lite on Arduino and Ultra-Low-Power Microcontrollers一書的第11章與第12章,以瞭解程式碼的細節。首先,進行SparkFun Edge開發板的實作;在tensorflow原始碼的目錄下,先進入SparkFun編譯的Python虛擬環境:

conda activate sparkfun-tensorflow

用以下命令進行編譯與執行檔簽署:

make -f tensorflow/lite/micro/tools/make/Makefile TARGET=sparkfun_edge magic_wand_bin

cp tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/keys_info0.py \
tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/keys_info.py

python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/create_cust_image_blob.py \
--bin tensorflow/lite/micro/tools/make/gen/sparkfun_edge_cortex-m4/bin/magic_wand.bin \
--load-address 0xC000 \
--magic-num 0xCB \
-o main_nonsecure_ota \
--version 0x0

python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/create_cust_wireupdate_blob.py \
--load-address 0x20000 \
--bin main_nonsecure_ota.bin \
-i 6 \
-o main_nonsecure_wire \
--options 0x1

接上SparkFun Edge開發板到主機上,用以下程序燒錄執行檔到板子上:

export DEVICENAME=/dev/ttyUSB0

export BAUD_RATE=921600

# 確保您的SparkFun Edge已連接到SparkFun USB-C Serial Basic,並透過USB連接到您的電腦
# 仍然按著標記為14按鈕,按一下標記RST按鈕以重置電路板 
# 持續按著標記為14按鈕,電腦執行以下命令

python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/uart_wired_update.py \
-b ${BAUD_RATE} ${DEVICENAME} \
-r 1 \
-f main_nonsecure_wire.bin \
-i 6

使用串列埠終端機程式(CoolTerm)觀察執行結果:

接下來進行Arduino Nano 33 BLE Sense開發板實作,首先在Arduino IDE上安裝Arduino_LSM9DS1程式庫:

接著,用外部編輯器修改程式碼(Arduino_LSM9DS1/src/LSM9DS1.cpp)如下所示:

完成後,選擇開發板與序列埠如下:

接著開啟magic_wand範例,並進行上傳:

編譯與上傳成功後,使用”序列埠監控視窗” 觀察執行結果:

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *