[ English ] [ 日本語 ]
- The support for Web Bluetooth API may be limited to Chrome (>= 56) or Opera (>= 43).
- The following contents are verified on macOS 10.14 using Chrome 77 and Bluetooth Explorer included in Additional Tools for Xcode 10.2.
Your code written in Blocks/JavaScript
using Microsoft Makecode |
micro:bit runtime |
micro:bit device |
Your code written in JavaScript |
Web Bluetooth API |
Chrome (>= 56) or
Opera (>= 43) |
-
Launch any browser on your PC.
-
Open Microsoft Makecode for micro:bit site.
-
Create a
New Project
. -
Add extension
Bluetooth
fromAdvanced
->Extensions
if it is not listed. Note that incompatible extensionRadio
will be removed when you addBluetooth
. -
Switch editor mode from
Blocks
toJavaScript
and replace the existing code with the following.bluetooth.onBluetoothConnected(function () { basic.showIcon(IconNames.Yes) }) bluetooth.onBluetoothDisconnected(function () { basic.showIcon(IconNames.Square) }) bluetooth.onUartDataReceived(serial.delimiters(Delimiters.NewLine), function () { str = bluetooth.uartReadUntil(serial.delimiters(Delimiters.NewLine)) basic.showIcon(IconNames.Heart) basic.pause(200) basic.showIcon(IconNames.Yes) bluetooth.uartWriteString("Received " + str + "\n") }) let str = "" bluetooth.startButtonService() bluetooth.startLEDService() bluetooth.startUartService() basic.showIcon(IconNames.Square)
-
Open
Project Settings
and change paring method fromJustWorks pairing (default)
toNo Pairing Required
. This setting is required for this experiment. -
Name the project (e.g.,
BLE
) and save it. The.hex
file (e.g.microbit-BLE.hex
) for flashing to the device is automatically saved to yourDownloads
folder. -
Connect your micro:bit device to a USB port on your PC and make sure that the usb storage named
MICROBIT
is mounted. -
Copy the downloaded
.hex
file to the usb storage. -
The device shows a square icon if it's ready for a Bluetooth connection.
- Launch Chrome or Opera and open
source/index.html
in the cloned repositry. - Make sure that the device shows a square icon. Reset the device if it shows a yes (checkmark) icon.
- Press
Connect
button on the browser. Choose a device namedBBC micro:bit [.....]
from the list on the dialog box. - When connection is established,
Connection Status
field on the browser showsConnected
. Also, the device shows a yes (checkmark) icon. - Press button A or B on the device. State changes are reported from the device and shown on
Button Status
field on the browser.
To generate the documentation of JavaScript part, run JSDoc (github.com) as below with jsdoc.json
file in the project root. JSDoc 3 or higher is required.
$ jsdoc -c jsdoc.json
$ open jsdoc/index.html
- micro:bit Bluetooth profile overview (lancaster-university.github.io)
- micro:bit Bluetooth profile reference (lancaster-university.github.io)
- MakeCode Bluetooth reference (makecode.microbit.org)
- Web Bluetooth API (mozilla.org)
- Web Bluetooth Samples (googlechrome.github.io)
- Web Bluetooth (webbluetoothcg.github.io)
© 2019 Softgraph, Inc.