利用 micro:bit 按鈕 控制 Raspberry Pi 3 GPIO 點亮 LED

動機:可否利用 micro:bit 按鈕(A | B) 控制 Raspberry Pi 3 的 GPIO(18) 來點亮 LED (on | off)?!

準備環境
1.Raspberry Pi 3
2.BBC micro:bit(插USB數據線)

實作步驟
1.請依網頁 http://www.allaboutcode.co.uk/single-post/2017/08/09/Controlling-the-Raspberry-Pi-GPIO-with-microbit 指示,安裝 pyserial, mu ...

2.打開 Mu 輸入 micropython 碼,如下


3.將 micro:bit 連接USB數據線並插上 Raspberry Pi 3 USB埠,再於 Mu 功能列按下 [Flash],如下圖

4.開啟 Raspberry Pi menu >> Programming >> Python 3 (IDLE) 及 點選 File >> New File,輸入 python碼,如下圖
其中,我加了 debouncing 程式來處理 micro:bit button 按下toggle時的抖動問題...
源碼,如下


5.接 LED 及 電阻(Pull-down resistor) 至麵包板及Raspberry Pi 3 Pin 12 (GPIO18),pinout 如下


6.按下 F5 執行程式並操作 micro:bit ,示範影片如下

心得:利用 serial 傳送控制文字來開/關LED,真好玩...

感謝
Joshua Lowe, August 10, 2017, Controlling the Raspberry Pi GPIO with micro:bit, http://www.allaboutcode.co.uk/single-post/2017/08/09/Controlling-the-Raspberry-Pi-GPIO-with-microbit

留言