MicroPython is a well-known lightweight version of Python designed specifically for embedded modules. It allows you to execute necessary functions with simple commands.
To use MicroPython on embedded modules, you need to download the MicroPython firmware. Only with the firmware installed can the chip parse Python statements. Currently, chips that support MicroPython firmware include ESP32, ESP8266, STM32F4, etc. Next, I will introduce the BPI-UNO32 development board using the ESP32 chip.
I would like to thank “Electronic Chip Bar” for their support, for providing the BPI-UNO32 development board used in this article. They are also giving away a BPI-UNO32 to one lucky reader (details on how to participate are at the end of the article). If you want to learn more about embedded development boards, please follow “Electronic Chip Bar”.
BPI-UNO32 Development Board
▼
A: Buzzer, pin IO25
B: Jumper cap, controls the connections of the buzzer, red, green, blue pins from left to right
C: RGB light, red pin IO17, green pin IO16, blue pin IO27
D: I2C interface, SCL pin IO22, SDA pin IO21
E: Button, one is the EN button (reset button), the other is an independent button on pin IO0
F: Indicator light, from top to bottom: serial RX indicator, serial TX indicator, power indicator
G: CH340 chip, connects the computer to the BPI-UNO32 development board
H: ESP32-WROOM-32 module
The BPI-UNO32 looks like an Arduino UNO R3, but it is designed to be compatible with the size of the Arduino UNO R3 board. Of course, aside from size compatibility, the BPI-UNO32 can also be programmed using the Arduino IDE. The BPI-UNO32 is produced by Banana Pi, using the ESP32-WROOM-32 module, with a maximum frequency of 240MHz and 4MByte of Flash memory, sufficient for running MicroPython.
Before we start setting up MicroPython, let’s clarify two questions:
1. How do we download Python to the BPI-UNO32?
2. How does the Python program run on the BPI-UNO32?
Answer to question 1:
Download the Python program from the computer to the BPI-UNO32 Flash via USB serial.
Answer to question 2:
The MicroPython firmware inside the BPI-UNO32 parses the Python statements.
Next, I will specifically introduce how to set up MicroPython on the BPI-UNO32 development board. The implementation steps for other development boards are generally similar, and you can refer to the following steps.
Steps to Set Up MicroPython
▼
First, prepare a MicroUSB cable, a BPI-UNO32, uPyCraft software, and the MicroPython firmware. uPyCraft is a commonly used IDE for MicroPython development, I selected version V1.1, but other versions are also acceptable, with the MicroPython firmware version being ESP32-V1.9.4; other versions are not recommended.
1. Connect the BPI-UNO32 to the computer using a MicroUSB cable, check if the CH340 device appears in the computer’s device manager. If it does not appear, install the CH340 driver first and then try again.
The USB CH340 device is used to flash the firmware and download Python programs to the BPI-UNO32, so it must be recognized.
2. Open uPyCraft, no installation is needed, just double-click to run it.
When opening uPyCraft, you may see a prompt saying “Please install SourceCodePro font”. This indicates that the computer needs to install the SourceCodePro font, click OK. If you see this prompt again when opening it next time, you can ignore it; it does not affect usage.
3. In the uPyCraft menu, select Tools -> Burn Firmware to start downloading the MicroPython firmware.
Follow the green box selections. The BPI-UNO32 uses ESP32, so select ESP32 for the board. If you are using ESP8266, select ESP8266. uPyCraft V1.1 supports firmware downloads for ESP8266, TPYBoardV202, ESP32, and MICROBIT development boards. The burn_addr is the starting address for the firmware, ESP32 selects 0x1000, ESP8266 selects 0x0. The firmware version should be v1.9.4; other versions are not recommended. Users need to download the firmware from the MicroPython official website first; I will provide the download method at the end of the article.
uPyCraft will first erase the Flash data of the BPI-UNO32, then download the MicroPython firmware to the BPI-UNO32 Flash.
4. Connect to BPI-UNO32
After the firmware is downloaded, you can let uPyCraft connect to the BPI-UNO32 by clicking the connect button marked in the right box. If the connection is successful, a boot.py file will appear under the device folder on the top left, and “>>>” will appear in the lower box. boot.py is an internal file of the BPI-UNO32 that is returned to the computer via the USB CH340 serial.
5. Write a simple lighting program in Python and run it
Now we can write Python programs for the BPI-UNO32. Open the boot.py file and write your own Python program. The code in the above image is used to control the red light of the RGB light on the BPI-UNO32 board to blink. After writing, click download and run, and the red light of the RGB light will start blinking.
This concludes how to set up MicroPython on the BPI-UNO32 development board. If you have other ESP32 or ESP8266 development boards, you can also refer to the methods in this article. The overall implementation steps are quite simple, mainly involving a development board that can run MicroPython and uPyCraft software.
Through this article, are you attracted by the small BPI-UNO32 development board? Do you find that MicroPython is not as mysterious as you thought? Do you want to experience MicroPython right away?
Now, “Electronic Chip Bar” is giving away a BPI-UNO32 board. Just reply “I want to participate” in the comment section to have a chance to win one. There is only one board to give away, and the results will be announced on January 16th, sent by mail. To keep the comment section tidy, “I want to participate” will only display the last winner’s comment. Of course, you can also purchase directly from the “Electronic Chip Bar” mini-program mall, or click Electronic Chip Bar – BPI-UNO32 to buy, or apply for a trial in this link.
The uPyCraft software, MicroPython ESP32 firmware, BPI-UNO32 schematic, and other related materials mentioned in the article can be obtained through the following methods:
1. Join the Electronic Maker QQ group (143867886) and download from the group files;
2. Reply “I want to download” on the homepage of the Electronic Maker WeChat public account to get the Baidu Netdisk download link.