https://www.youtube.com/watch?v=Hiq5i1sZXQM
嗯...以前都用WiFi, 這次用藍芽試試看! 效果還不錯, 蠻簡單的! 只用了一個超便宜的USB Bluetooth dongle. 過幾天拿Banana Pi M2+、Banana Pi M3已經內建藍芽的系列也試試看
安裝藍芽在Banana Pi M1的Unbuntu 15.04上, 插入dongle後重新開機一下, 我當時的步驟:
安裝必要的套件:
sudo apt-get update
sudo apt-get install bluetooth bluez-utils blueman
看看你的藍芽, 這將顯示你的藍芽dongle相關登記資訊:
hciconfig
接著去掃描你的HC-05, 記得拿支筆抄下HC-05的address; address會比如是98:D3:31:20:43:96這樣的一串16進位:
hcitool scan
然後配對! 記得你的藍芽dongle的HCI代號、HC-05的address; 如果找到HC-05, 就輸入PIN code進行配對. 一般HC-05的PIN code就是1234這樣的數字:
sudo bluez-simple-agent hci0 98:D3:31:20:43:96
然後安裝rfcomm這個protocal, 才能讓Banana Pi M1上的USB Bluetooth dongle和Arduino上的HC-05可以透過rfcomm這個protocal模擬serial介面:
sudo nano /etc/bluetooth/rfcomm.conf
把這段加到/etc/bluetooth/rfcomm.conf後儲存起來, 回到Terminal :
rfcomm1 {
bind yes;
device 98:D3:31:20:43:96;
channel 1;
comment "Connection to Bluetooth serial module";
}
再讓rfcomm啟用:
sudo rfcomm bind all
之後看看/dev下有沒有一個/dev/rfcomm1這樣的裝置, 有的話就是成功了! 最後, 確定你的Python可以透過serial介面抓資料:
sudo apt-get install python-serial
好啦~~我把範例程式放在以下的網址:
Arduino; 我在這個範例用了Grove的Touch V1.1、Buzzer V1.2, HC-05因為直接插上D0、D1用serial所以燒錄的時候記得要把HC-05先移開, 燒錄好再插回Arduino :
https://drive.google.com/…/0B4zJys3uKtnaRlppbHA4cnNEZ…/view…
Banana Pi M1的Python :
https://drive.google.com/…/0B4zJys3uKtnaT3M2Z21VXzg1S…/view…
歐敏銓
2016-07-06 18:04:53