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

InterfaceHardware SupportedTinyGo Support
GPIOYESYES
UARTYESYES
SPIYESYES
I2CYESYES
ADCYESNot yet
PWMSoftware supportNot yet

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:

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

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

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:

  1. // use the same pins as for SPI0, but with SPI1
  2. machine.SPI1.Configure(machine.SPIConfig{
  3. SCK: machine.SPI0_SCK_PIN,
  4. MOSI: machine.SPI0_MOSI_PIN,
  5. MISO: machine.SPI0_MISO_PIN,
  6. Frequency: 500000,
  7. Mode: 0})
  8. // use I2C0 as normally do
  9. machine.I2C0.Configure(machine.I2CConfig{})