BBC micro:bit

The BBC micro:bit

The BBC micro:bit is a small microcontroller board designed for computer education in the UK - see the Wikipedia Article for more information.

It contains:

  • USB comminications and JST power connectors
  • A 5x5 array of LEDs for use as a display
  • Two user-configurable buttons, and one reset button
  • An accelerometer (MMA8652) and magnetometer (MAG3110)
  • A Nordic nRF51822 ARM Cortex-M0 microcontroller (256kB flash, 16kB RAM)
  • A Freescale Kinetis chip to handle USB - this provides a virtual USB flash drive that allows firmware updates just by saving a file.

Note: While we provide Espruino for the micro:bit, it takes a lot of memory to provide bluetooth functionality and as a result some functionality has had to be removed:

  • No ES6 Features (ArrayBuffer map/forEach, template literals, arrow functions, etc)
  • No advanced library functions (In the reference, any function with the comment "Note: This is only available in some devices: not devices with low flash memory" will not be included)
  • Low program memory (Espruino on micro:bit has only 350 vars available, whereas on other devices it has over 10 times that)

If you want the full experience, please consider buying an official Espruino Board. Puck.js is especially useful if you want to experiment with Bluetooth LE.

Flashing Espruino

There is a build of Espruino designed specifically for the micro:bit. Releases are available from the Download page - 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:

  • Plug it into USB. A drive called MICROBIT should appear
  • Download the .hex file for Espruino, and save it directly into the root of that drive
  • The yellow LED on the micro:bit will blink quickly for a few seconds, and will then stop.
  • The Espruino firmware is now installed!

Using the micro:bit

There are two ways to communicate with your micro:bit:

USB

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.

Bluetooth Low Energy (BT 4.0 / Bluetooth Smart)

You can also program the micro:bit wirelessly! There are two main ways to do this:

Web Bluetooth (Google Chromebook, Android 6)

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:

  • Click the connect icon at the top left
  • Choose Web Bluetooth - if this doesn't exist, it's because your device doesn't have Web Bluetooth enabled.
  • If it isn't enabled:
    • If you're on Android, make sure you install Chrome Dev
    • Enter chrome://flags/#enable-web-bluetooth in your address bar
    • Click to enable it, and restart Chrome
  • Now you should be prompted for a device to connect to by the web browser
  • Click it, and wait - connection can take around 10 seconds
  • Finally the icon up the top left should change state to 'Connected', and you'll be able to program Espruino as normal - but via Bluetooth!

Note: You can still use Web Bluetooth on Android 5, but you need the latest 'Chromium' builds. See this post on StackOverflow

micro:bit Functionality

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 nothing
  • show(1) lights the first LED
  • show(0b1000) lights the fourth LED
  • show(0b1111111111111111111111111) or show(0x1FFFFFF) lights all LEDs
  • The following will draw a smiley face:
show("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);

acceleration()

This returns an object with x, y, and z elements, each containing the force in that axis in g.

compass()

This returns an object with x, y, and z elements, indicating the current direction of the magnetic field

Pinout

Hover the mouse over a pin function for more information. Clicking in a function will tell you how to use it in Espruino.

  • Purple boxes show pins that are used for other functionality on the board. You should avoid using these unless you know that the marked device is not used.
  • ! boxes contain extra information about the pin. Hover your mouse over them to see it.
  • 3.3v boxes mark pins that are not 5v tolerant (they only take inputs from 0 - 3.3v, not 0 - 5v).
  • 3.3 is a 3.3v output from the on-board Voltage regulator.
  • GND is ground (0v).
  • ADC is an Analog to Digital Converter (for reading analog voltages)
  • SPI is the 3 wire Serial Peripheral Interface.
  • I2C is the 2 wire Inter-Integrated Circuit bus.
D3 ! ADC
D0 ADC
D4 !
D5 ADC BTN1
D6 !
D7 !
D1 ADC
D8
D9 !
D10 ! ADC
D11 BTN2
D12
D2 ADC
D13 SPI1 SCK
D14 SPI1 MISO
D15 SPI1 MOSI
D16
3.3
3.3
3.3
D19 ADC I2C1 SCL
D20 I2C1 SDA
GND
GND
GND

Tutorials

Tutorials using the micro:bit Board:

No tutorials use this yet.

Buying

micro:bits are currently available to buy in the UK and in the United States.

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.