View on GitHub

ubitwebblejs

A MakeCode project

ubitwebblejs

This project turns a BBC micro:bit into a versatile Bluetooth Low Energy (BLE) device that can be controlled from a web browser. It allows a web-based client to interact with the micro:bit’s sensors and actuators.

Try it out with the companion web app: https://wongfei2009.github.io/microbit-webble-p5js/

Features

How it Works

The micro:bit runs a program that initializes a number of Bluetooth services. A connected device can then use these services to interact with the micro:bit.

Music Player

A connected client can send music to the micro:bit in chunks over the UART connection. The protocol is as follows:

  1. A message with a MUSIC: prefix is sent to set the tempo.
  2. The music data is sent in one or more messages with a CHUNK: prefix.
  3. The last chunk must contain the string |END to signify the end of the music data.
  4. The micro:bit assembles the chunks and then uses a custom library to parse the music string and play it.

Use as Extension

This repository can be added as an extension in MakeCode.

Build and Deploy

Prerequisites

Setup

  1. Clone the repository:
    git clone https://github.com/wongfei2009/ubitwebblejs.git
    cd ubitwebblejs
    
  2. Install PXT command-line tools and set up the micro:bit target:
    npm install -g pxt
    pxt target microbit
    
  3. Install project dependencies:
    pxt install
    

Building

To build the project and generate the .hex file:

pxt build

Or use the Makefile:

make build

The compiled files will be generated in the built/ directory. The main file is built/binary.hex.

Deploying

Option 1: Automatic deployment (if micro:bit is connected via USB):

pxt deploy

Or use the Makefile:

make deploy

Option 2: Manual deployment:

  1. Connect your micro:bit to your computer via USB
  2. The micro:bit will appear as a USB drive named “MICROBIT”
  3. Copy the built/binary.hex file to the MICROBIT drive
  4. The micro:bit will automatically flash the new program

Important Notes