The BBC micro:bit is a small microcontroller board designed for computer education in the UK - see the Wikipedia Article for more information.
There are multiple versions of the micro:bit available:
We are currently not using universal hex files, so you will need to load the
correct hex file (_microbit1
or _microbit2
) for your board.
micro:bit contains:
While we do provide Espruino for the micro:bit v1, it takes a lot of memory to provide Bluetooth functionality and as a result some functionality has had to be removed compared to the v2 and other Espruino devices:
If you want the full experience, please consider buying an official Espruino Board.
There is a build of Espruino designed specifically for the micro:bit. Releases are available from the Download page for micro:bit 1 or micro:bit 2 - however you may also download 'cutting edge' builds from here - these are updated every time something changes in Espruino's source code, so may occasionally not work.
To flash onto your micro:bit:
MICROBIT
should appear.hex
file for Espruino (ensuring that you have the microbit1
or microbit2
file depending on your device), and save it directly into the root of that driveThere are two ways to communicate with your micro:bit:
This is the easiest, and recommended way of communicating with Espruino.
For Windows users, you will need to install drivers first - on other platforms, the board should 'just work'.
Follow the instructions in the Quick Start tutorial to install the Web IDE (ignore the Plugging in
section), and you should be able to communicate with the micro:bit just like any other board.
Note: as the micro:bit has a display but no general-purpose LEDs, the tutorials in the Quick Start that use LED1
/etc will not work without modification.
You can also program the micro:bit wirelessly!
If you have a device that supports Web Bluetooth, you can go directly to the Online Web IDE in your web browser, and can connect with that.
Web Bluetooth
- if this doesn't exist, it's because your device doesn't have Web Bluetooth enabled. Click the status
link for more information.The micro:bit has a few variables and functions that are useful:
BTN1
and BTN2
These read the state of the two buttons, for example:
BTN1.read()
or digitalRead(BTN1)
return 1 or 0 depending on the state of the button
The following will write Pressed
each time the button is pressed:
setWatch(function() {
console.log("Pressed");
}, BTN1, {repeat:true, debounce:20, edge:"falling"});
Or this will write Pressed
or Released
:
setWatch(function(e) {
if (e.state) console.log("Released");
else console.log("Pressed");
}, BTN1, {repeat:true, debounce:20, edge:"both"});
Note: Currently the state of the buttons is inverted - 1
means not pressed, 0
means pressed.
show(bitmap)
Shows graphics on the built-in 5x5 LED screen. This takes a binary number or a string. For example:
show(0)
shows nothingshow(1)
lights the first LEDshow(0b1000)
lights the fourth LEDshow(0b1111111111111111111111111)
or show(0x1FFFFFF)
lights all LEDsshow("1 1\n"+
" 1 \n"+
" 1 \n"+
"1 1\n"+
" 111 \n");
`
You can use the Graphics library to display text and images, for example the following with scroll 'Espruino' across the display:
g = Graphics.createArrayBuffer(5,5,1);
g.flip = function(){show(this.buffer);};
var x = 0;
setInterval(function() {
x++;
if (x>50)x=0;
g.clear();
g.drawString("Espruino",5-x);
g.flip();
}, 100);
Microbit
classThis contains functions for interfacing with the Micro:bit hardware. See a full reference here
Note: In 2v07
and earlier the Microbit
class doesn't exist and instead there are just acceleration()
and compass()
functions.
Microbit.accel()
This returns an object with x
, y
, and z
elements, each containing the force in that axis in g
.
Note: In 2v07
and earlier this doesn't exist and acceleration()
is available instead.
You can also use Microbit.accelOn()
which then creates an event whenever data is available, which can be read with Microbit.on('accel', function(d) { ... })
Microbit.mag()
This returns an object with x
, y
, and z
elements, indicating the current direction of the magnetic field
Note: In 2v07
and earlier this doesn't exist and compass()
is available instead.
Microbit.play(waveform, samplesPerSecond, callback)
Micro:bit version 2 only: plays a sound - see the reference for more information
Microbit.record(samplesPerSecond, callback, samples)
Micro:bit version 2 only: records a sound - see the reference](http://www.espruino.com/Reference#l_Microbit_record) for more information
Hover the mouse over a pin function for more information. Clicking in a function will tell you how to use it in Espruino.
Tutorials using the micro:bit Board:
Tutorials using Bluetooth LE:
Tutorials using Bluetooth LE and functionality that may not be part of the micro:bit:
micro:bits are currently available to buy all over the world.
This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.