CAS Community   >   Resources   >  

no image
microbit_stub - a module to support tests of BBC micro:bit micropython programs

A Python module that emulates the BBC microbit as defined by the microbit micropython API.

Nick Cook

Created by Nick Cook
last edited Jun 01 2016 by Nick Cook

This Python module is based on the microbit micropython API defined as part of the BBC microbit project.

The aim is to provide an implementation of the microbit micropython API that can be used to test a microbit micropython program without having to have a physcial microbit connected. This is similar to the in-browser microbit emulations for other programming languages provided at

If a student develops using the Web based Python editor, feedback with respect to bugs in their program is via a Python error message scrolling across the physical microbit screen. These are quite difficult to read and could become a barrier to development. Development in Python is likely to lead to simple syntax errors (indentation etc.) that only become apparent when an error message is displayed on the microbit screen. The hope is that it will be easier for students to find and correct bugs if they have more readable error output.

The offline mu micropython editor has a REPL shell that, if connected to a microbit, will display error output in the shell and support easier debugging. Even so, there may be some benefit in being able to trace and debug a program without connecting to the physical microbit.

This module supports disconnected program development by emulating most of the microbit’s functionality (see the “What is emulated” section of the GitHub README for more details). Emulation output is text to the console, which means the module can be used in many programming environments.

The module provides mechanisms to simulate changes to the state of the microbit (e.g. reading and writing to pins).

It allows testing of both the syntax and logic of microbit micropython programs.

The microbit_stub code is licensed under the MIT open source license for consistency with the microbit micropython license.

The zip file attached to this resource is a snapshot of the microbit_stub GitHub repository.

To keep up to date with the module, its documentation and other files associated with the module it is recommended to download or contribute to the GitHub repository at:

Level: (Intermediate)

Downloaded 346 times.


This resource has attached files: to access these files, please tick the box below to assent to the license terms
License: The resources on CAS website are under Creative Commons Attribution-Share Alike 3.0 licence unless otherwise specified by the resource creators.

You must confirm that you have read and agree the licence's ToS before you can download the attachments of this resource.

I have read the licence agreement of this resource and agree to abide by its terms and conditions.

Feedback and Comments

Available when logged in (join via the front page, for free):
  • View 2 comments on this resource.
  • View resource history, links to related resources.
  • Leave feedback for the author(s), or help by editing the resource.