The MicroBit Manager can be used to develop programs for the micro: bit with various well-known program editors/ IDEs. After editing the source, by one click they are downloaded and executed on the target system. The program execution is supervised in a terminal window (Console, REPL), where error messages and print output are displayed. By pressing Ctrl+C the program can be stopped and the Python prompt is presented. The user can now enter command lines and let them execute with the Python interpreter. With an option, the MBM can flash the firmware for the micro:bit from an internal firmware image, that is slightly modified from the original to suppress the long lasting writing out of error messages on the dot display, thus greatly accelerating the development cycle. After flashing, the python module mbutils.py is copied to the micro: bit, which contains some practical auxiliary functions, especially for controlling the micro:bit buggy (by Kitronik).
During the program development, the micro:bit board is connected to the development system via the USB interface. It then appears as a extra external USB device with its own drive letter (Windows) or as an extra drive name (Mac, Linux). For the communication when the terminal window is open and up- and downloading files other than the firmware, the micro:bit is addressed as a serial device (via USB), thus receiving a ComPort (Windows) or a serial device name (Mac, LInux). For Windows versions earlier than 10, an mbed driver must be installed, which can be downloaded from here. No additional driver is required for Windows 10 and Mac/Linux.
The MicroBit Manager is integrated into TigerJython and does not need any additional installations. To be used standalone or with other IDEs, it can be downloaded from here as a Java application (including source). All its functions are selected via command-line parameters, which are listed when calling MBM without parameters (java -jar MBM.jar)
To enable the MBM in TigerJython, choose Preferences | Library | Chose robot and select micro:bit. An additional black-bordered button appears in the taskbar and the options Remote Terminal, Download/Execute, Download module, Flash micro:bit are enabled in the Tools menu.
The source is written in the editor window of TigerJython and then stored on the development system like other Python programs. But since the program is not executed on the development system, but on the micro:bit, instead of pressing the green run-button the black-bordered download/execute-button is clicked (or Tool option Download/Execute selected). The code is then checked for syntax errors with TigerJython's special Python parser and user friendly error messages are displayed in the editor window near the position where they are detected. If the program passes the parsing process, an extra terminal window (REPL) is obened, in which the communication process with the micro:bit is traced. This comprises the following steps:
Any print() output and all error messages are displayed in the terminal window and by typing Ctrl+C the program can be halted. After a program stops, Python's interpreter prompt >>> is displayed and commands can be entered. A simple Ctrl+D performs a soft boot and restarts the program. There is no need to close the terminal window: when a new version is downloaded from the development system, the window closes automatically and a new window is opened.
Because a running program is stopped automatically, it is allowed to write non-terminating programs or endless loops, as common for microcontroller programs written in C or assembler. However, these loops should not overload the processor, because otherwise the program interruption may fail (insert a sleep(0.001) in tight loops).
To support structured programming, Python modules can be copied to the target system using the option Download module. As usual they are integrated with an import statement. Unfortunately to the size of programs and modules cannot exceed more than a few kBytes due to the lack of memory space.
After a program has been downloaded (and renamed automatically to main.py), the USB connection to the development system can be unplugged. Each time the USB port of the micro:bit is powered with 5V by a USB charger or USB power bank, the main.py is immediately started.
If main.py hangs or the micro:bit becomes unreachable because of a faulty software manipulation, a new system can be installed from scratch by flashing the firmware. Because all program modules are lost, they must be restored from the development system.
The Python interpreter MicroPython is not a full implementation of Python 3.x, but most language features are available. The special hardware of the micro:bit is accessed by importing the module microbit: import microbit or from microbit import * (see the doc here) .
As an additional feature, operations of the MBM can also be executed by a Python program running in TigerJython. After import mbm the following functions are available:
Function | Action |
showFiles() |
browses the file system of the micro:bit and displays all file names |
openTerminal() | opens a terminal window (REPL) and connects to the micro: bit |
extract(filename) | copies the file filename from the micro:bit to the directory, where the TigerJython program is located |
copy(filename) | copies the file filename from the development system to the micro:bit. The filename remains the same, but the directory path is truncated |
run(filename) | opens a terminal window (REPL) and copies the file filename from the development system to the micro:bit. Renames it to main.py and runs the program. A given directory path is truncated |
runMain() | opens a terminal window (REPL) and runs main.py (if available) |
flash() | copies a firmware image and the module mbutils.py from the distribution to the micro:bit. |
flash(filename) | copies the specified firmware image (hex file) and the mbutills module from the distribution to the micro:bit |
enableDataCapture(enable) | enables/disables text line capture in terminal window, captured lines are added to the data line buffer |
getDataLines() | returns a list with all captured lines in the data line buffer and clears the buffer |
isTerminalDisposed() |
returns True, if the terminal is not visible (not yet opened or already closed) |
In a typical example , the micro:bit acts as data logger and the data file is transferred to TigerJython by calling extract(filename) where it is further processed.