A javascript library to interact with BBC micro:bit using web bluetooth API
A JavaScript library for interacting with BBC micro:bit using Web Bluetooth API. Control LED matrix, read sensors, and exchange data wirelessly between micro:bit and web browsers.
git clone https://github.com/wongfei2009/microbit-webble-p5js.git
Upload this firmware to your micro:bit
<script src="ubitwebble.js"></script>
Browser | Support Status | Notes |
---|---|---|
Chrome 56+ | ✅ Full | Windows, Mac, Android |
Edge (Chromium) | ✅ Full | Windows, Mac |
Opera | ✅ Full | All platforms |
Firefox | ❌ No | - |
Safari | ❌ No | iOS or Mac |
// Create instance
const microBit = new uBitWebBluetooth();
// Connect
await microBit.searchDevice();
// Show a smile!
const smile = [
['0', '0', '0', '0', '0'],
['0', '1', '0', '1', '0'],
['0', '0', '0', '0', '0'],
['1', '0', '0', '0', '1'],
['0', '1', '1', '1', '0']
];
microBit.writeMatrixIcon(smile);
You can try the examples online or run them locally:
Visit the hosted examples at:
git clone https://github.com/wongfei2009/microbit-webble-p5js.git
cd microbit-webble-p5js
Start a local web server. You can use:
python3 -m http.server 8000
Note: A local server is required because browsers restrict Web Bluetooth API access to secure contexts (HTTPS) or localhost.
microBit.searchDevice()
- Connect to devicemicroBit.onConnect(callback)
- Connection success handlermicroBit.onDisconnect(callback)
- Disconnection handlermicroBit.setButtonACallback(callback)
- Button A press handlermicroBit.setButtonBCallback(callback)
- Button B press handlermicroBit.getAccelerometer()
- Get acceleration {x,y,z}microBit.getTemperature()
- Get temperature (°C)microBit.getBearing()
- Get compass heading (0-360°)microBit.writeMatrixIcon(matrix)
- Show LED patternmicroBit.writeMatrixText(text)
- Show scrolling textmicroBit.writeMatrixTextSpeed(speed)
- Set scroll speedmicroBit.writeUARTData(text)
- Send UART messagemicroBit.setReceiveUARTCallback(callback)
- Receive UART handler