microbit 軟體生態圈介紹

2017-04-04 18:16

 

 micro:bit 軟體生態系統介紹

這裡有大量的軟體平台及工具使得許多microbit 計畫順利的進行,這篇文章只是做概略介紹而希望要進一步了解可以到不同計畫的專頁得到更多的資料.

Overview

·        High Level Programming Languages 高階程式語言

o   Compiled Languages 編譯語言

o    Interpreted Langauges 直譯語言

·        Coding environments and IDEs 程式環境及整合介面

·        From Coding Environment to micro:bit 從程式環境到microbit

·        micro:bit Low Level (C/C++) Software Stack  底層軟體架構

 

在microbit 軟體分成在microbit (Target Computer 如下圖右邊)上執行的及主電腦(Host Computer 如下圖左邊)上兩類 :

一般程式寫好後透過USB 轉到micro:bit , 整個流程由兩個晶片完成,一是 KL26Z負責程式刷新(code flashing) ,另一nRF51822則執行完成使用者完成的程式。

 

高階程式語言

Microbit 的高階程式語言分成編譯及直譯兩類(但譯者若以實際的程式執行環境目前都是"編譯” ── 將使用者程式編譯後結合底層已有bytebode ,成為完整執行程式),原文便保留

The ‘high level’ programming languages for the micro:bit break down into two broad categories

·        Compiled languages: your program is compiled to ARM assembler or some other kind of bytecode before being copied onto the micro:bit.

·        Interpreted Languages: both your script and an interpreter for it are copied onto the micro:bit. Because the interpreter is on the micro:bit itself, these langauges typically also allow you to program the micro:bit ‘live’ over USB by typing commands.

 

編譯語言

C/C++, while certainly compiled, is not considered a high-level language in this context

 

為了可以確定線上的編譯環境可支援一百萬片microbit 的板子,微軟用TypeScript 寫了瀏覽器版編譯器(https://makecode.com),在這編譯器上微軟使用了以下的技術 : 

·        Blocks (at microbit.co.uk)

·        TouchDevelop

·        CodeKingdoms Javascript (at microbit.co.uk)

·        Blocks and Javascript as part of pxt (at pxt.microbit.org)

 

整個完整流程說明在瀏覽器編譯頁面 In browser compiler,更細部令人驚豔的細節在 TouchDevelop in 208 bits.

 

瀏覽編譯器不會編譯整個程式,只有使用者編寫的部分,其他底層執行的部分已經預先用mbed 編譯好,並整合進線上編譯器。當使用者編寫完他的程式,編譯器便會編譯並結合底層軟體,讓使用者下載!

 

PS: MakeCode的底層編程語言是TypeScript(github.com/Microsoft/TypeScript-Node-Starter)的一個子集,省略了JavaScript動態特徵。

MakeCode的主要功能有:

一個基於Google Blockly的代碼編輯器以及轉換器到JavaScript

一個基於摩納哥的文本編輯器,具有增強的強大的自動完成和自動校正功能,由TypeScript提供支持。

通過TypeScript或C ++定義塊的可擴展性支持

基於markdown的文檔系統,具有內置宏以呈現塊片段

一個ARM Thumb機器碼發射器

一個命令行包管理器

MakeCode目前在微軟Redmond開發。

 

直譯語言

在microbit.co.uk 正式的編譯器中,只有 Python 是直譯的。這是用MicroPython 直譯器專案所完成,細部資料可以 MicroPython的連結中找到。

另外還有Javascript 直譯器專案 port of the Javascript interpreter Espruino 支持 microbit!

 

 

程式環境及整合介面

這裡有許多程式環境可讓使用者對microbit做不同層面的程式設計.

較普遍的編譯環境都列在https://microbit.org/code,離線的編譯環境有Mu offline Python editor

這裡已經盡可能將micro bit 相關的編譯環境列出來,若你有知道,但不在這上面的,請讓我們知道(Here’s a non-exhaustive list of possible code editors for use with the micro:bit. please add any you know about that are not here,原文中並未指出如何通知,所以在這將原文列出)

·        microbit.co.uk editors based on TouchDevelop backend:

o   Code Kingdoms Javascript

o   Microsoft Blocks

o   Microsoft TouchDevelop

o   Python

·        mbed Online Compiler

·        Mu offline Python editor

·        PXT for micro:bit (successor to the TouchDevelop-based editors above)

 

 

從程式環境到 micro:bit 

每一個編譯環境都會產生一個.hex 的檔案,這是microbit 可以認得的格式。由於主電腦會將Microbit認為是USB隨身碟(是由DAPLink 模擬出來),當編譯出來Hex 檔拖拉至microbit。當閃燈結束,程式便開始執行。

另一"刷程式"(flash’ code) 是用手機AP透過藍芽傳輸至 micro:bit ,更多的資訊請參考 here,有關藍芽手機程式更多資訊請參考 here

 

 

micro:bit底層軟體架構

當你為microbit 寫完你的應用程式,刷你的程式進microbit 。這hex 檔除了包含你寫的部分也包含了許多底成軟體模組,這些軟體模組在底下一、一做介紹:

·        the micro:bit Runtime (有時稱這部分為裝置抽象層),是由Lancaster University 用C++ 寫成。裝置抽象層形成不同語言共同使用的部分,但在不同語言下使用的頻繁度及包裝的緊密度不同。(有興趣的讀者可以用以下列處的連結下載語言編譯器的程式碼研究,或初步去看各語言的reference 作了解)

·        ARM mbed 這部分提供了mbed 對不同ARM based MCU 的周邊有標準的SDK ,這也包含了BLE 的抽象層及API ,這也代表的microbit 的軟體可以執行在其他的mbed 支援的硬體上

·        Nordic nRF51-SDK mbed 是建構在Nordic nRF51-SDK的上層, 由 Nordic 發展的元件可以幫助程式人員使用它們的硬體。

·        MicroPython interpreter 若你是使用python的程式人員 ,它是用micro python 及mbed 開發出來的,所以microPython 是可以使用在許多不同硬體平台

Microbit 台灣 商店購買

Microbit 中文 課程 : Python , Javascript, 物聯網

              中國

—————

返回