home

Documentation MicroBit Manager (MBM)

 

Overview:


The MicroBit Manager can be used to develop programs for the micro: bit (or compatible microcontrollers, e.g. the Calliope Mini) 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 from an internal firmware image. After the flashing process, some useful Python library modules are copied to the target (support of motors, tutorials, external sensors, etc.).

During the program development, the target 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). When the terminal window is open and for up- and downloading files other than the firmware, the target is addressed as a serial device (via USB), thus uses 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/Calliope. An additional black-bordered button appears in the taskbar and the options Remote Terminal, Download/Execute, Download module, Flash target are enabled in the Tools menu.


Development process:

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 target, 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 target 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 target is powered with 5V by a USB charger or USB power bank, the main.py is immediately started.

If main.py hangs or the target 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 target is accessed by importing from microbit import * resp. from calliope_mini import * (a full documentation for the micro:bit can be found here) .

 

MBM API:

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:

Module Import: from mbm import *

Function Action
showFiles()

browses the file system of the target 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 target to the directory, where the TigerJython program is located
copy(filename)

copies the file filename from the development system to the target. 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 target. 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() installs the internal firmware image
flash(filename) installs the given external firmware image
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 target acts as data logger and the content of the data file is transferred to TigerJython by calling extract(filename) where it is further processed.

 


home