BBC micro:bit

The BBC micro:bit is a tiny programmable computer designed for learning. It is based on the Nordic Semiconductor nRF51822 ARM Cortex MO chip.

Interfaces

Interface Hardware Supported TinyGo Support
GPIO YES YES
UART YES YES
SPI YES YES
I2C YES YES
ADC YES YES
PWM Software support Not yet
USBDevice NO NO
Bluetooth YES YES

Pins

Pin Hardware pin Alternative names
P0 P0_03 ADC0
P1 P0_02 ADC1
P2 P0_01 ADC2
P3 P0_04 LED_COL_1
P4 P0_05 LED_COL_2
P5 P0_17 BUTTONA, BUTTON
P6 P0_12 LED_COL_9
P7 P0_11 LED_COL_8
P8 P0_18
P9 P0_10 LED_COL_7
P10 P0_06 LED_COL_3
P11 P0_26 BUTTONB
P12 P0_20
P13 P0_23 SPI0_SCK_PIN
P14 P0_22 SPI0_SDI_PIN
P15 P0_21 SPI0_SDO_PIN
P16 P0_16
UART_TX_PIN P0_24
UART_RX_PIN P0_25
SDA_PIN P0_30
SCL_PIN P0_00
LED_COL_4 P0_07
LED_COL_5 P0_08
LED_COL_6 P0_09
LED_ROW_1 P0_13
LED_ROW_2 P0_14
LED_ROW_3 P0_15

Machine Package Docs

Documentation for the machine package for the BBC micro:bit

Flashing

The micro:bit comes with the DAPLink bootloader already installed. This means you can just copy the compiled .hex file generated by TinyGo onto it, no additional flashing software is needed.

  • Plug your micro:bit into your computer’s USB port.

  • The micro:bit board will appear to your computer like a USB drive.

  • Build and flash your TinyGo program using tinygo flash like this:

    tinygo flash -target=microbit [PATH TO YOUR PROGRAM]
    
  • The micro:bit should restart and begin running your program.

Note that if you want to use the Nordic SoftDevice, you cannot use this flashing method. Instead you need to flash programs using OpenOCD (see below). The command is tinygo flash -target=microbit-s110v8 -programmer=cmsis-dap.

OpenOCD

An alternative approach to load programs onto the micro:bit is by using the openocd command line utility program. You must install OpenOCD before you will be able to flash the micro:bit board with your TinyGo code.

  • Plug your micro:bit into your computer’s USB port.

  • Build and flash your TinyGo program using tinygo flash -target=microbit -programmer=cmsis-dap

Notes

The micro:bit has two built-in I2C devices, a MMA8653 accelerometer and a MAG3110 magnetometer. You can use them via the I2C0 bus.

The micro:bit I2C0 and SPI0 buses both share the same address space. This means you cannot use them both at the same time. However, you can still use both SPI and I2C at the same time, by using the SPI1 bus with the standard SPI pins at the same time as using the I2C0 bus to access the built-in devices.

For example:

// use the same pins as for SPI0, but with SPI1
machine.SPI1.Configure(machine.SPIConfig{
    SCK:       machine.SPI0_SCK_PIN,
    MOSI:      machine.SPI0_MOSI_PIN,
    MISO:      machine.SPI0_MISO_PIN,
    Frequency: 500000,
    Mode:      0})

// use I2C0 as normally do
machine.I2C0.Configure(machine.I2CConfig{})

Bluetooth support is now available for the BBC micro:bit board. See https://github.com/tinygo-org/bluetooth for more information.