Skip to main content

MicroPython micro:bit REPL

This script lets you run commands directly onto a connected micro:bit device. Put simply, you get to program the micro:bit in real time, just like we used to with the old BBC micro from the 1980’s. This encourages exploration, experimentation and a sense of adventure. It’s also a good way to play with the device to learn about its capabilities.

The script detects the port to which the micro:bit is connected and uses PySerial to make a connection to the micro:bit’s Read Evaluate Print Loop (REPL).

For more information about what a REPL, is check out this Wikipedia article:

https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop

Installation

Unfortunately, Windows does not come with serial/COM drivers for the micro:bit installed by default (happily, Linux and OSX do).

If you’re on Windows, in order to make this work you should use the mbedWinSerial_16466.exe file (found in the root directory of this project) to install the correct drivers. You MUST have your micro:bit plugged into your computer when you run this command.

For more information and the latest versions of this driver please visit:

https://developer.mbed.org/handbook/Windows-serial-configuration

Assuming this requirement is met, you can install/run the script in three ways:

  1. Install via pip and PyPI:

    # pip install microrepl
  2. Install via setup.py:

    # python setup.py install
  3. Run the script from within the repository:

    # pip install -r requirements.txt
    # python microrepl.py

All of the above should probably be done within a virtualenv. The first two options will result in two commands being installed: microrepl or its alias urepl. Simply type these at the command prompt to run the application.

Getting Started

When you run the script it will try to be as helpful as possible in working out why it can’t connect. In most cases it will try to print some helpful advice.

Once connected the script will stop the program running on the micro:bit in order to drop you into the REPL itself. You type Python commands next to the prompt (>>>).

If things don’t seem to be working, re-flash your micro:bit using the firmware.hex file in this directory, and try again.

You can use the TAB key to auto-complete words. For example, if you type microbit.sc then hit TAB, MicroPython will helpfully complete the word for you, like this: microbit.screen.

You can move forwards and backwards through your command history by using the up arrow key (to move back through your command history) and down arrow key (to move forwards through your command history). The left and right arrow keys allow you to move through the text of your command without deleting it.

Use the TAB and arrow key commands! They save a lot of typing and look really cool.

Unplugging the device and pressing the reset button will re-start the program as the version you originally flashed onto the device.

Useful Commands

A good place to start is to type help(). From here you should be able to explore the device and the MicroPython version of Python 3.

All the micro:bit’s hardware is available to program via the microbit module. To start using it type the command import microbit. Do fun things such as microbit.display.scroll('Hello, World!') and watch the device react in real-time.

Type the command dir() to see a list of all the things currently available to you - this includes the various classes and functions for the program you may have already flashed onto the micro:bit.

Find Out More

To learn more about the amazing MicroPython visit: http://micropython.org/

The BBC micro:bit’s (non-Pythonic) home is: http://microbit.co.uk/

To learn about the Python language visit: http://python.org/

Release History

0.5

Updated to latest version of PySerial.

0.4

Windows support added. Requires installation of drivers found in the mbedWinSerial_16466.exe executable. More information can be found at the ARM website: https://developer.mbed.org/handbook/Windows-serial-configuration

0.1

Initial release. Works on Linux and OSX on both Python 2.7 and 3.3+. Windows version coming soon.

Release files for microrepl 0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for microrepl 0.6
File Size Uploaded
microrepl-0.6.tar.gz 579.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for microrepl 0.6
File Interpreter ABI Platform
microrepl-0.6-py3-none-any.whl Python 3 none any Details

Total release size: 587.2 kB

Release files / microrepl-0.6.tar.gz

Download URL microrepl-0.6.tar.gz
Size 579.4 kB
Tags Source
SHA-256 checksum
How to use checksums
20ce959e4cd0fbce90ff68023e1f4bd9ddb11afee9c1953142169d2d2686a5f9
BLAKE2b-256 checksum
How to use checksums
fd66eea75d90e1fde919e66706d064db7176ff846f277b6597283878d0a32ac1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / microrepl-0.6-py3-none-any.whl

Download URL microrepl-0.6-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59e09db899809d4b3ec4f2e303468c5c230fd7facd1e441b94bf9bcd8f1af89b
BLAKE2b-256 checksum
How to use checksums
4bf7ad7c1771ebceebab1ce3be2ac8df675ab7ca1841b7628f72937195b3e92f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.6 This release

2 release files

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page