Skip to content

wongfei2009/microbit-webble-p5js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ubitwebble.js

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.

Installation

  1. Download the library:
git clone https://github.com/wongfei2009/microbit-webble-p5js.git
  1. Upload this firmware to your micro:bit

  2. Include in your project:

<script src="ubitwebble.js"></script>

Browser Support

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

Quick Start

// 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);

Running Examples

You can try the examples online or run them locally:

Online Demos

Visit the hosted examples at:

Running Examples Locally

  1. Clone this repository:

    git clone https://github.com/wongfei2009/microbit-webble-p5js.git
    cd microbit-webble-p5js
  2. Start a local web server. You can use:

    • Using Python 3:
      python3 -m http.server 8000
  3. Open your web browser and navigate to:

Note: A local server is required because browsers restrict Web Bluetooth API access to secure contexts (HTTPS) or localhost.

API Reference

Connection

  • microBit.searchDevice() - Connect to device
  • microBit.onConnect(callback) - Connection success handler
  • microBit.onDisconnect(callback) - Disconnection handler

Inputs

  • microBit.setButtonACallback(callback) - Button A press handler
  • microBit.setButtonBCallback(callback) - Button B press handler
  • microBit.getAccelerometer() - Get acceleration {x,y,z}
  • microBit.getTemperature() - Get temperature (°C)
  • microBit.getBearing() - Get compass heading (0-360°)

Display

  • microBit.writeMatrixIcon(matrix) - Show LED pattern
  • microBit.writeMatrixText(text) - Show scrolling text
  • microBit.writeMatrixTextSpeed(speed) - Set scroll speed

Communication

  • microBit.writeUARTData(text) - Send UART message
  • microBit.setReceiveUARTCallback(callback) - Receive UART handler

About

A javascript library to interact with BBC micro:bit using web bluetooth API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%