Now that we know what MicroPython is, and we have installed an IDE on our computer, it’s time to upload the firmware to our board.
The firmware is the software that is loaded directly onto the hardware of a device, and that it runs during its operation.
In the case of MicroPython, the firmware is a lightweight version of the Python interpreter that runs on the microcontroller of the board. This firmware allows executing Python code on the device.
The good news is that it is very easy to install it on our board. Let’s see how to do it.
Download the MicroPython Firmware
The first step is to download the appropriate firmware for your board. You can find the firmware files on the official MicroPython site: https://micropython.org/download/.
You will need to download the exact file for your specific model and variant of board.
Device | File to download |
---|---|
ESP32 | .bin file for your model |
ESP8266 | .bin file for your ESP8266 model |
Raspberry Pi Pico | .uf2 file for your Raspberry Pi Pico model |
Arduinos | .hex file for your model |
STM32 | .duf file for your model |
Upload the Firmware to the Board
Now we need to upload the firmware to the board. To do this, connect the board to the computer using a USB cable.
The process varies depending on your board. Let’s see how the upload process would be for an ESP32/ESP8266, and a Raspberry Pi Pico (any of its versions).
For other models (Arduino, STM32, etc), consult the information in the official documentation.
Installation on ESP32/ESP8266
Install esptool
: If you haven’t installed it, you can install it using pip
:
pip install esptool
Erase the flash memory: Before installing the new firmware, it is recommended to erase the flash memory of the board:
esptool.py --port /dev/ttyUSB0 erase_flash
Replace /dev/ttyUSB0
with the correct port on your system.
Upload the firmware: Use esptool
to upload the downloaded firmware:
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0x1000 firmware.bin
Make sure to replace firmware.bin
with the name of the file you downloaded.
Restart the board: Once the upload is complete, disconnect and reconnect the board to restart it.
For ESP32 and ESP8266, it is necessary to put the board in programming mode. This is usually done by connecting a specific pin (like GPIO0
) to ground (GND
) before connecting the board to the computer.
Depending on your board, it may do this automatically by pressing a button, or you may have to do it manually.
Installation on Raspberry Pi Pico
Raspberry Pi Pico is very much designed to run MicroPython, so the upload is very simple (you might even have it preloaded on the board).
To install the firmware on the Raspberry Pi Pico:
- Hold down the
BOOTSEL
button while connecting the board to the computer. - This will put the board in mass storage mode, appearing as a drive on your PC (like a USB flash drive).
- Now you just need to copy the
.uf2
file directly, as you would with any file (for example with Ctrl + C / Ctrl + V, or dragging the file). - The board will automatically restart and load the MicroPython firmware, and you are ready to go.
Verify the Installation
Once the firmware is installed, you can verify that everything is working correctly using the REPL (Read-Eval-Print Loop).
But we will cover that in the next tutorial.