電子工程系車用電子與資訊組
micro:bit入門
吳錫修
sswu@nkut.edu.tw
February 4, 2018
Micro:bit控制板、應用程式開發工具、LED顯示控制、
按鈕輸入、觸控輸入、溫度感測、亮度感測、方位感測、加速度
感測、聲音輸出控制、無線傳輸、藍牙傳輸
shapethefuture
micro:bit簡介 1/4
2 Wu, ShyiShiou Dept. of E.E., NKUT
 Micro:bit 是⼀款由英國廣播電視公司(BBC)推出的專為青少年編
程教育設計的微型電腦開發板
 約½名片大小
 25 個可程式化 LED
 2 個可程式化按鈕
 21個I/O接點
 類比、數位、I2C、SPI及UART
 光和溫度感測器
 動作感測器 (加速儀和羅盤)
 無線通訊,透過2.4G radio和藍牙
 Micro USB界面
shapethefuture
 正面
micro:bit簡介 2/4
3 Wu, ShyiShiou Dept. of E.E., NKUT
4cm
5cm
3 digital/analog IO rings
(capacitive sensing)
power port ground port
2 programmable
buttons
5×5 individually
programmable LEDs
shapethefuture
 背面
micro:bit簡介 3/4
4 Wu, ShyiShiou Dept. of E.E., NKUT
16MHz 32-bit ARM Cortex M0 CPU
256KB flash, 16KB Static RAM with Bluetooth Low Energy
Micro USB connector
Bluetooth Smart antenna
Battery connector
Compass
(Freescale MAG3110)
Accelerometer
(Freescale MMA8652)
20 pin edge connector
Reset button
USB controller
shapethefuture
micro:bit簡介 4/4
5 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
Breakout Board 1/2
6 Wu, ShyiShiou Dept. of E.E., NKUT
https://www.kitronik.co.uk/5601b-edge-connector-breakout-board-for-bbc-microbit-pre-built.html
shapethefuture
Breakout Board 2/2
7 Wu, ShyiShiou Dept. of E.E., NKUT
https://www.sparkfun.com/products/13989
shapethefuture
MI:power board
8 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 MakeCode
 Microsoft為Micro:bit 開發的入門學習編程工具
 https://makecode.microbit.org/
 Block與JavaScript版本
 簡單易學,但指令參數受限
 Python線上編輯器
 http://python.microbit.org
 完整功能可自由操控Micro:bit
 micro:bit接上電腦後,Windows系統會自動建立⼀個MICROBIT磁
碟機
應用程式開發工具 1/6
9 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Online Python editor
應用程式開發工具 2/6
10 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 JavaScript Blocks Editor (積木指令模式)
應用程式開發工具 3/6
11 Wu, ShyiShiou Dept. of E.E., NKUT
開啟/關閉模擬器
模擬器
下載程式
指令分類
程式區
shapethefuture
 即時語法檢查
應用程式開發工具 4/6
12 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 JavaScript Blocks Editor (JavaScript模式)
應用程式開發工具 5/6
13 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Python離線編輯器
 https://codewith.mu/
應用程式開發工具 6/6
14 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
燒錄程式 1/2
15 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 將下載的程式傳送到MICROBIT磁碟機
燒錄程式 2/2
16 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 LED matrix
LED顯示控制 1/4
17 Wu, ShyiShiou Dept. of E.E., NKUT
column(x)
row(y)
(4,4)
(0,0)
shapethefuture
LED顯示控制 2/4
18 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 內建圖案
LED顯示控制 3/4
19 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 自訂圖案
 顯示訊息
LED顯示控制 4/4
20 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 按鈕A連接pin 5,按鈕B連接pin 11,
並有pull-up電阻接3V
按鈕輸入
21 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 micro:bit類比輸入接腳P0、P1及P2提
供觸控輸入
 ⼀⼿按著GND,另⼀隻⼿碰觸P0、P1
或P2接點
觸控輸入
22 Wu, ShyiShiou Dept. of E.E., NKUT
touch-pins
shapethefuture
 micro:bit並未配置獨立的溫度感測器來偵測環境溫度,而是嵌入在
晶片中,由於供電時晶片本身會散熱,micro:bit所推斷的環境溫度
會高於實際值
 實際溫度值= 量測值 – 校正值
溫度感測 1/2
23 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
溫度感測 2/2
24 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 micro:bit並未配置獨立的亮度感測器,而是透過使用LED屏幕上的
⼀些LED來測量周圍的光線
 當電流在LED上反轉,則對光敏感,特別是它對發出的同樣顏色的光敏
感。因此micro:bit對紅光的反應比任何其他顏色都要強
 首次讀取光線感應值會回傳255
亮度感測 1/2
25 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
亮度感測 2/2
26 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 首次執行或變更地點應執行電子羅盤校正
 旋轉micro:bit在LED畫個圓圏
 室內空間可能影響準確度
電子羅盤 1/3
27 Wu, ShyiShiou Dept. of E.E., NKUT
方位
shapethefuture
電子羅盤 2/3
28 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
電子羅盤 3/3
29 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Z為上下移動
 X為左右傾斜
 Y為前後高低
加速度計 1/2
30 Wu, ShyiShiou Dept. of E.E., NKUT
X
Y
Z
shapethefuture
加速度計 2/2
31 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 利用加速度計資料可判斷使用者操作micro:bit動作
 Up
 Down
 Left
 Right
 Face up
 Face down
 Freefall
 Shake
 2G/4G/8G
手勢偵測 1/2
32 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
手勢偵測 2/2
33 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 makecode之音樂積木使用P0輸出,
所以蜂鳴器必須接到P0接點
聲音輸出控制 1/2
34 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 撥放方式
聲音輸出控制 2/2
35 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 micro:bit處理器內建2.4G無線模組
 相互通訊的控制板,必須設置為相同的無線群組
 資料傳送
 數值
 數據對
 字串
2.4G無線傳輸 1/3
36 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 資料接收
2.4G無線傳輸 2/3
37 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 兩片控制板上傳相同程式
2.4G無線傳輸 3/3
38 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 點擊Add Package新增套件
設定藍牙傳輸 1/5
39 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 點擊bluetooth套件
設定藍牙傳輸 2/5
40 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 藍牙套件與Radio套件不能並存
設定藍牙傳輸 3/5
41 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
設定藍牙傳輸 4/5
42 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 點擊設定>Project Settings,指定藍牙配對作業方式
設定藍牙傳輸 5/5
43 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 測試程式
藍牙傳輸
44 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 安裝micro: bit App並開啟
藍牙配對 1/5
45 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 同時micro:bit控制板背面的A、B鍵,不要
放掉
 按⼀下micro:bit控制板背面的Reset鍵
 等待micro:bit LED螢幕顯示"PAIRING
MODE!",再放開A、B鍵
藍牙配對 2/5
46 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 當PAIRING MODE! 結束後, micro:bit LED
會顯示該micro:bit控制板的"簽名"圖案
 在micro: bit App輸入同樣"簽名"圖案,之後
點擊PAIR按鈕
藍牙配對 3/5
47 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Android⼿機藍牙可用的裝置出現"BBC
micro:bit [XXXXX]"
藍牙配對 4/5
48 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 micro:bit LED顯示向左的箭頭
 按⼀下micro:bit控制板A鍵 ,micro:bit LED
會顯示6個數字 (配對PIN碼)
 在⼿機的藍牙配對作業對話窗輸入PIN碼
(Personal Identity Number)
 如果micro:bit LED出現打勾的圖形,表示配
對完成;而如果micro:bit LED出現打X的圖
形,就代表過程沒完成,就要重來⼀次
藍牙配對 5/5
49 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 安裝micro:bit Blue App
micro:bit Blue App 1/7
50 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 點擊FIND BBC MICRO:BIT(S)搜尋micro:bit藍牙裝置
micro:bit Blue App 2/7
51 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 點擊所要連接的micro:bit藍牙裝置
micro:bit Blue App 3/7
52 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 等待探索micro:bit之藍牙服務
micro:bit Blue App 4/7
53 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 加速計服務:會顯示micro:bit控制板之加速計狀態
micro:bit Blue App 5/7
54 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Button服務:會顯示micro:bit控制板之A、B按鍵狀態
micro:bit Blue App 6/7
55 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 LED服務:可由⼿機設定micro:bit控制板LED矩陣顯示內容
micro:bit Blue App 6/7
56 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Temperature服務:即時顯示micro:bit控制板感測之溫度值
micro:bit Blue App 6/7
57 Wu, ShyiShiou Dept. of E.E., NKUT

micro:bit入門