因為
mbed跟Arduino,都是算不錯好上手簡單開發的工具。
但是用習慣Arduino語法的我們,還是覺得使用Arduino開發比較簡單。
且有許多熟悉的Library可以直接使用,方便許多。
所以這邊來講裝Arduino的流程。
安裝環境
Ubuntu 16.04
我就假設已經你們自己都裝好Arduino IDE了。
依照arduino-nRF5所述步驟
首先就先安裝Ubuntu相關所需套件
1 2 3 | sudo dpkg --add-architecture i386 sudo apt-get update sudo apt-get -y install libc6:i386 libstdc++6:i386 libncurses5:i386 libudev1:i386 |
開始安裝Arduino的部份吧
進IDE後–>檔案–>偏好設定–>額外的開發板管理員網址
1 | https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json |
在工具—>開發板最上方有個開發板管理員,點選進入。
搜尋nRF5 即可找到剛剛我們加入的開發板,點選安裝。
安裝完成後,即可到開發板區域選擇nRF51
這邊還有一點 要用藍芽功能的話
可以選擇S130 SoftDevice or S132 SoftDevice
功能我也還沒看,有興趣可以自己去看原廠Paper
要安裝SoftDevice的話 要Follow以下步驟
1 2 3 4 5 6 | cd ~/Arduino mkdir tools mkdir tools/nRF5FlashSoftDevice mkdir tools/nRF5FlashSoftDevice/tool/ cd tools/nRF5FlashSoftDevice/tool/ wget https://github.com/sandeepmistry/arduino-nRF5/releases/download/tools/nRF5FlashSoftDevice.jar |
- 重開Arudino IDE
- 選擇開發板-我自己的是WaveShare BLE400
- SoftDevice S130
- 燒錄器 CMSIS-DAP
- 工具 -> nRF5 Flash SoftDevice
但在這邊燒錄SoftDevice時出了點問題,以下是吐出來的錯誤訊息
1 2 3 4 5 6 7 8 9 10 11 | /home/notbeloser/.arduino15/packages/sandeepmistry/tools/openocd/0.10.0-dev.nrf5/bin/openocd -d2 -f interface/cmsis-dap.cfg -c ; -f target/nrf51.cfg -c init; halt; nrf51 mass_erase; program {{/home/notbeloser/.arduino15/packages/sandeepmistry/hardware/nRF5/0.5.1/cores/nRF5/SDK/components/softdevice/s130/hex/s130_nrf51_2.0.1_softdevice.hex}} verify reset; shutdown; Open On-Chip Debugger 0.10.0-dev-00254-g696fc0a (2016-04-09-12:07) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html debug_level: 2 Info : only one transport option; autoselect 'swd' cortex_m reset_config sysresetreq adapter speed: 1000 kHz Error while flashing SoftDevice. Error: unable to open CMSIS-DAP device 0xc251:0xf001 |
這邊是出在權限不足的問題,因此要把Arduino用su的身份執行。
不過,先用上一篇編譯好的OpenOCD做燒錄試試看吧,參考他吐出來的指令下。
1 2 3 4 5 6 7 8 9 | sudo openocd -f interface/cmsis-dap.cfg -f target/nrf51.cfg #call a new terminal telnet localhost 4444 > init > halt > nrf51 mass_erase > program /home/notbeloser/.arduino15/packages/sandeepmistry/hardware/nRF5/0.5.1/cores/nRF5/SDK/components/softdevice/s130/hex/s130_nrf51_2.0.1_softdevice.hex verify > reset > shutdown |
這邊要解決OpenOCD的燒錄問題有兩個方法
- 使用Root權限開啟Arduino IDE
- 使CMSIS-DAP使用時不須Root
這邊選擇第二個方案,因為我不只會在Arduino IDE內開發,也在Eclipse內。
從StackOverFlow尋找到解法
1 2 3 4 5 6 7 8 | sudo nano /etc/udev/rules.d/98-openocd.rules #加入以下內容到檔案 ACTION!="add|change", GOTO="openocd_rules_end" SUBSYSTEM!="usb|tty|hidraw", GOTO="openocd_rules_end" ATTRS{product}=="*CMSIS-DAP*", MODE="664", GROUP="plugdev" LABEL="openocd_rules_end #離開並存檔 sudo udevadm control --reload |
可以透過Arduino成功燒錄了!
安裝好SoftDevice之後,還需要安裝一個BLE的Library,不然會開發的很痛苦。
- 在Arduino-IDE內,選擇管理程式庫
- 搜尋BLEPeripheral,並安裝。
此時就可以著手開發藍芽了~