Skip to content
Switch branches/tags
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Control a BBC micro:bit from Node.js using BLE and Haxe

These are the Haxe node.js externs from and follows the api

The Micro Bit (also referred to as BBC Micro Bit, stylised as micro:bit) is an ARM-based embedded system designed by the BBC for use in computer education in the UK.

The board is 4 cm × 5 cm and has an ARM Cortex-M0 processor, accelerometer and magnetometer sensors, Bluetooth and USB connectivity, a display consisting of 25 LEDs, two programmable buttons, and can be powered by either USB or an external battery pack.[2] The device inputs and outputs are through five ring connectors that are part of the 23-pin edge connector.



Read more about Haxe

Installation Haxe/NPM

1. follow instructions to install bbc-microbit

Make sure to follow the instructions for noble too.

2. install dependencies with npm

npm install

3. install haxelib

haxelib git bbc-microbit


use this repo locally

haxelib dev bbc-microbit path/to/folder/src

or this git repo

haxelib git bbc-microbit

don't forget to add it to your build file

-lib bbc-microbit

Visual Studio Code

I would suggest to us Visual Studio Code, it's a very nice editor and lets you set breakpoints in your js file

But other code-editors may work as well!

Haxe niceties

create a (LED)pattern from an array

var X = [
	1, 0, 0, 0, 1,
	0, 1, 0, 1, 0,
	0, 0, 1, 0, 0,
	0, 1, 0, 1, 0,
	1, 0, 0, 0, 1,
var buffer = new Buffer(new Pattern().createLedMatrixBuffer(X));

// follow example "LedPatternHx"
// or use a default Pattern
var buffer = new Buffer(new Pattern().createLedMatrixBuffer(Pattern.HEART));

Use string to listen to or EventName

import BBCMicrobit;

// strings will work
microbit.on('buttonAChange', function(value) {
	console.log('\ton -> button A change');

// prevent spelling mistakes with EventName
microbit.on(EventName.BUTTON_A_CHANGE, function(value) {
	console.log('\ton -> button A change');

Use the fixed values for AccelerometerPeriod Period

import BBCMicrobit;

// numbers will work
microbit.writeAccelerometerPeriod(160, function(err) {
	console.log('\taccelerometer period set');

// prevent using wrong value use Period
microbit.writeAccelerometerPeriod(Period.NR_160, function(err) {
	console.log('\taccelerometer period set');


  • UART doesn't work: check api
  • Light sensor doesn't work: it works with a trick read more but with this node.js code unable to access.
  • The code is not written on the micro:bit, remove power (switch off) and the code is gone
  • EventListeners examples doesn't work: the code is not uploaded to NPM yet (but if you want to use it read this)

Fix EventListener

After installing the dependencies via npm install.
You need to update the node_modules/bbc-microbit folder with two files:

And that will make that work.

I have created an issue "microbit.subscribeEvents" but it's not fixed yet.


most examples from are "redone" in Haxe




Control a BBC micro:bit from Node.js using BLE and Haxe




No releases published


No packages published