Micro:bit: MicroPython support

The objective of this post is to explain how to configure the  micro:bit board to support MicroPython and create a simple “Hello World” program.


Introduction

The objective of this post is to explain how to configure the  micro:bit board to support MicroPython and create a simple “Hello World” program.

MicroPython is an implementation of the Python 3 programming language for microcontrollers [1]. It includes a subset of the Python’s standard library and is optimized to run on microcontrollers, which have resource constraints [1] in comparison to a computer.

Note that MicroPython was design to be as compatible as possible with the regular Python programming language [1], so it should be very easy to use for people who already know Python. This also means that many of the Python tutorials around the web can be used for learning how to program in MicroPython.

Please note that I have already an extensive number of MicroPython tutorials for the ESP32 and the ESP8266 in my blog, which you can consult here. Some of them should be possible to also run on the micro:bit. Note however that hardware specific code (such as WiFi functions, for example) may not run on the micro:bit.


The configuration

In order to get started with MicroPython on the micro:bit board, we will use DFRobot’s uPyCraft MicroPython IDE, which you can download here. This will make the process of flashing MicroPython in the micro:bit board very simple.

After running the executable file and installing the IDE, you may be prompted to perform an update. If this happens, perform the update so you have access to the latest  uPyCraft version. In my case, I’m using version 0.27, which already supports the micro:bit board. Note that some older versions may not support it.

After finishing the installation and the mentioned initial updates, go to the tools menu, then serial separator and choose the COM port of your micro:bit board.

If multiple COM ports are detected and you are not sure which one corresponds to your micro:bit, you can disconnect the board from your computer, check which COM ports are available at that menu entry, then connect your micro:bit again and check the new one that will appear. Alternatively, you can check here how to find the COM port of your micro:bit on Windows Device Manager.

Figure 1 shows the mentioned menu were you can choose the COM port of your device.

uPyCraft selecting device COM port microbit.png

Figure 1 – Choosing the micro:bit COM port on uPyCraft.

Upon choosing the correct COM port, a popup like the one shown in figure 2 should appear. In this popup, we specify the microbit board in the dropdown and choose uPyCraft in the “Firmware Choose” radio buttons. After setting the correct configurations, click the “ok” button.

microbit uPyCraft Flash MicroPython.png

Figure 2 – MicroPython firmware burn configurations for micro:bit on uPyCraft.

Once you click the “ok” button, a new popup like the one in figure 3 should appear. It indicates that you should wait for micro:bit’s yellow led to stop blinking. Just click the “ok” button and wait for the flashing procedure to finish.

uPyCraft MicroPython microbit flash wait message.png

Figure 3 – Micro:bit MicroPython flashing wait message.

When the procedure is completed, a new popup like the one in figure 4 should appear, indicating that everything finished correctly. Just click the “ok” button.

microbit uPyCraft MicroPython flash ok message.png

Figure 4 – Micro:bit MicroPython flash update ok message.

After this, the MicroPython firmware should already be on your micro:bit board. To establish a connection to the MicroPython prompt, just click the Connect icon, highlighted in figure 5.

Microbit uPyCraft MicroPython open connection.png

Figure 5 – Establishing a serial connection with MicroPython’s prompt.

As shown in figure 6, after the connection, the icon you clicked should have changed and the MicroPythonprompt should now be available at the bottom of the IDE.

microbit uPyCraft MicroPython prompt opened

Figure 6 – Look and feel of the IDE with the connection established with MicroPython’s prompt.

Now you can start sending commands in the MicroPython prompt. When you want to close the connection, simply click again the icon you have used before to open the connection.


Hello World

To finish our tutorial, let’s simply send a print command to the prompt with a “Hello World” message. In MicroPython, we print content to the console by using the print function, which receives as input the content we want to print.

So, just type the command below in the prompt and hit enter.

print("Hello World")

You should get an output similar to figure 7, which shows the “Hello World” message being printed to the console.

microbit microPython hello world.png

Figure 7 – Micro:bit MicroPython “Hello World” message.


References

[1] https://micropython.org/

2 thoughts on “Micro:bit: MicroPython support”

  1. Pingback: Micro:bit: MicroPython support – Arduino Boards News

  2. Pingback: Micro:bit: MicroPython support – Arduino Boards News

  3. Pingback: Micro:bit MicroPython: Concatenating strings | techtutorialsx

  4. Pingback: Micro:bit MicroPython: Concatenating strings | techtutorialsx

Leave a Reply

Discover more from techtutorialsx

Subscribe now to keep reading and get access to the full archive.

Continue reading