In this guide, you’ll learn how to use Mu Editor software to program your ESP32 and ESP8266 boards using MicroPython.
Mu Editor is a simple Python editor for beginner programmers that supports MicroPython with the ESP32 and ESP8266 boards. It works pretty well, comes with a simple and intuitive interface, and provides a menu to burn firmware to your boards quickly.
- MicroPython Introduction
- Installing Mu Editor
- Mu Editor Overview
- Flashing MicroPython Firmware
- Running Your First Script
What is MicroPython?
MicroPython is a Python 3 programming language re-implementation targeted for microcontrollers and embedded systems. MicroPython is very similar to regular Python. Apart from a few exceptions, the language features of Python are also available in MicroPython. The most significant difference between Python and MicroPython is that MicroPython was designed to work under constrained conditions.
Because of that, MicroPython does not come with the entire pack of standard libraries. It only includes a small subset of the Python standard libraries, but it includes modules to easily control and interact with the GPIOs, use Wi-Fi, and other communication protocols.
Installing Mu Editor
Mu Editor is a simple Python editor for beginners. As mentioned on the Mu Editor website, “Less is More: Mu has only the most essential features, so users are not intimidated by a baffling interface.”[Mu Editor Webpage]
Installing Mu Editor is very straightforward. Follow the next steps:
1) Go to the following website and download Mu Editor for your operating system: https://codewith.mu/en/download.
2) Run the installer you’ve just downloaded—it’s probably in your Downloads folder.
3) Finally, follow the on-screen instructions to install it.
If you have trouble with the installation, look at the official instructions on the Mu Editor website: Mu Editor Installation Guides.
And that’s it. It couldn’t be simpler.
Mu Editor Overview
Open Mu Editor. The following window will open.
You can see that the interface is very simple and intuitive to use. Let’s take a quick look at the buttons.
- Mode: choose which mode you want to use. Select ESP MicroPython
- New: creates a new file.
- Load: chooses a file to load into Mu.
- Save: saves the file to your computer.
- Run: runs the current script in your ESP32 or ESP8266 boards without actually uploading code to the board.
- File: opens a window with the files saved on your board filesystem and a window with the files saved on your computer’s current directory.
- REPL: allows you to talk to the ESP32 or ESP8266 by writing commands that the board will run right away. REPL means Read, Evaluate, Print, Loop. The ESP32/ESP8266 waits for instructions by presenting >>> in the REPL. You should type your commands and hit Enter. The ESP will get the commands and send a response.
- Plotter: provides a graphical interface to display and plot values.
- Zoom-in: increases code font size.
- Zoom-out: decreases code font size.
- Theme: changes between different themes.
- Check: checks your code for errors.
- Tidy: tidies up your code when it comes to spaces and indentation.
- Help: opens Mu Editor website help page.
- Quit: closes Mu Editor.
Flashing MicroPython Software
MicroPython isn’t flashed onto the ESP32 or ESP8266 boards by default. The first thing you need to do to start programming your boards with MicroPython is flash/upload/burn the firmware.
There are different ways in which you can do that. Mu Editor comes with a tool that allows you to quickly install MicroPython firmware on your board. Another method is using esptool—check this tutorial to burn MicroPython firmware with esptool.py if you have trouble flashing the firmware with Mu Editor.
Downloading MicroPython Firmware
Go to the MicroPython Downloads page: https://micropython.org/download/.
Select the type of board you’re using. Here are the quick links for “regular” ESP32 and ESP8266 boards:
You should see a similar web page (see figure below) with links to download .bin files. Download the latest release.
At the time of writing this article, the latest release is v1.17 (2021-09-02).bin for the ESP32 and ESP8266 boards. Don’t download the Nightly builds; those versions are not stable and are only recommended for advanced programmers.
The downloaded file will probably go to the Downloads folder. Continue reading to learn how to flash the firmware on your boards.
Flashing MicroPython Firmware using Mu Editor
In this section, you’ll learn how to flash MicroPython firmware on your boards using Mu Editor. Follow the next steps:
1) Connect your ESP32 or ESP8266 board to your computer.
2) Open Mu Editor. And click on the gear icon at the bottom right corner.
3) Click on the ESP Firmware flasher tab. It should automatically detect an ESP32 or ESP8266 board connected to a specific COM port. If you don’t see any port on the Device field, go to this section of the ESP troubleshooting guide.
4) Choose your device type: ESP32 or ES8266 board. Click on the Browse button and select the MicroPython firmware .bin file you’ve downloaded previously.
5) Click on Erase & write firmware to start burning MicroPython firmware.
6) If you’re using an ESP8266 board, the burning process will start automatically for most boards. If you’re using an ESP32 board, you’ll probably need to hold the on‑board BOOT/FLASH button for about two seconds right after clicking on the Erase & Write firmware button to put your board in flashing mode.
7) After a few seconds, the process is completed—see figure below.
Congratulations. You successfully flashed MicroPython firmware on your boards using Mu Editor.
Running Your First Script
At this point, we assumed that you have Mu Editor installed on your computer and the ESP32/ESP8266 flashed with MicroPython firmware.
To get you familiar with the process of writing a file and executing code on your ESP32/ESP8266 boards, we’ll upload a simple script that blinks the on-board LED of your ESP32 or ESP8266 (that corresponds to GPIO 2).
After having the MicroPython firmware installed on your board and having the board connected to your computer through a USB cable, follow the next steps:
1) Press the New button to create a new file.
2) Copy the following code to your newly created file (including indentation).
# Complete project details at https://RandomNerdTutorials.com
from machine import Pin
from time import sleep
led = Pin(2, Pin.OUT)
3) Press the Save button to save the file to your computer. Save it whenever is more convenient to you. We recommend creating a project folder to save that file, for example, called Blink. Then, save the file inside that folder. The file should be called main.py.
4) Click on the Files button to open your board filesystem and your project directory on your computer—see figure below. There should be a file called boot.py already on your board. It is created by default when you burn MicroPython firmware. There’s also a file called main.py on your computer with the code provided previously.
Troubleshooting: If you got an error when clicking on the Files button (see figure below), try the following until you get a response:
- unplug/plug or reset your board;
- restart Mu Editor;
- click on the Files button followed by the REPL button, press CTRL-C to stop any possible running programs on the board, then click on the Files button again. Try this several times until you got a response.
5) To upload code to your board, drag the main.py file from the “Files on your computer” window to the “Files on your device” window. Now, the main.py file is on your board filesystem.
Note: Later, if you want to make changes to your main.py, you should save it on your computer first. Then, drag the main.py again to the device window to overwrite the previous file.
6) Now, press the on-board ESP32/ESP8266 EN (ENABLE) or RST (RESET) button to restart your board. After that, it will run the code we’ve just uploaded. The on‑board blue LED should be blinking every half a second.
The following figure shows the ESP32 on-board LED light up.
And the following figure shows the ESP8266.
Congratulations! You’ve just written and uploaded your first MicroPython script to your ESP32/ESP8266 board using Mu Editor software.
In this tutorial you’ve learned how to use Mu Editor software to program your ESP32 and ESP8266 boards using MicroPython. We have tutorials for other MicroPython IDEs that you might want to experiment with:
- uPyCraft IDE: MicroPython with ESP32/ESP8266
- Thonny IDE: MicroPython with ESP32/ESP8266
- VS Code + PyMakr: MicroPython with ESP32/ESP8266
If you want to learn more about MicroPython with the ESP32 and ESP8266 boards, take a look at our resources:
Thanks for reading.