Getting started with the Thonny MicroPython (Python) IDE for ESP32 and ESP8266.
If you wish to program your ESP32 and ESP8266 with MicroPython firmware, an IDE is quite useful. This guide will introduce you to Thonny IDE. After following this tutorial, you will have your first LED glowing using MicroPython and the Thonny IDE.
We tried many IDEs to program the ESP32 and ESP8266 boards with MicroPython, and we prefer Thonny IDE.
It enables you to program your ESP32, ESP8266, Raspberry Pi Pico, and other boards with MicroPython. It's compatible with Windows, Mac OS X, and Linux. It is installed by default on the Raspberry Pi operating system. Furthermore, it is simple to install, so you should have no issues with the installation.
What is MicroPython?
MicroPython is a Python 3 programming language re-implementation aimed for microcontrollers and embedded systems. MicroPython is extremely similar to conventional Python. Except for a few exceptions, MicroPython has the same language features as Python. The most notable distinction between Python and MicroPython is that MicroPython was designed to function under limited circumstances.
Because of this, MicroPython does not include the whole set of standard libraries. It only includes a small part of the Python standard libraries, but it does include modules for simply controlling and interacting with GPIOs, as well as using Wi-Fi and other communication protocols.
Installing Thonny IDE on Windows PC
To install Thonny on your Windows PC, follow the steps below:1. Visit https://thonny.org.
2. Download the Windows Installer and wait a few seconds while it downloads.
3. Run the .exe file.
4. To complete the installation, simply follow the installation wizard. You only need to click "Next."
5. After finishing the installation, launch Thonny IDE. A window, as seen in the figure below, should open.
Flashing Micropython Software
The ESP32 and ESP8266 boards do not come with MicroPython installed by default. The first step in programming your boards using MicroPython is to flash, upload, or burn the firmware.
There are several options for accomplishing this task. Thonny IDE has a tool that lets you rapidly install MicroPython firmware on your board. That's the approach we'll take in this tutorial.
Flashing your boards with MicroPython is reversible. This means that even after flashing the ESP32/ESP8266 with MicroPython, you can continue to use the Arduino IDE in the future. Simply use the Arduino IDE to upload code to your board.
Flashing MicroPython Firmware with Thonny IDE
This section will show you how to use the Thonny IDE to flash MicroPython firmware on your boards. Take the next steps:1) Connect the ESP32 or ESP8266 board to your computer.
2) Open the Thonny IDE. Navigate to Tools > Options, and then the "Thonny options" window will appear.
3) Select the interpreter that is appropriate for the board you are using, as well as the COM port to which your board is attached. Finally, select the link "Install or update MicroPython".
4) Next, select the port, board, and variant. It will immediately download the most recent MicroPython firmware version—see screenshot below. Finally, click Install.
After a few seconds, the installation should be complete. If you have an ESP32, you may need to press the BOOT button for a few seconds after clicking the Install button.
5) Once the installation is complete, shut the window. The Shell should display the following message (see image below), with the interpreter and COM port listed in the bottom right corner.
Troubleshooting:
If it doesn't recognize the device and displays the message "no backend" in the bottom-right corner, it's possible that the COM port isn't automatically detected. If this is the case, go to Tools > Options > Interpreter and manually set the COM port. Thereafter, it should recognize the MicroPython device and display the previous message.
The REPL
You should also see the ">>>" symbol (if not, click the Stop icon at the top).This symbol depicts MicroPython's REPL (Read-Eval-Print-Loop) prompt. This sign indicates that you're communicating with MicroPython (the board with MicroPython firmware installed) in real time. This basically implies that you may type and run commands directly. Let's try it in the following section.
Testing Installation.
Type help() in the Shell after the >>> prompt to see if your device answers.
It should display some valuable information on programming your board with MicroPython.
You can try different commands. For example, type the following.
>>> print('Hello')
It should print Hello to the Shell immediately after you enter the command.>>> print('Hello') Hello
To activate the ESP32/ESP8266 built-in LED, perform the following commands sequentially in the Shell after the prompt (>>>):
>>> from machine import Pin
>>> led = Pin(2, Pin.OUT)
If you use an ESP32, turn the onboard LED as follows:
>>> led.value (1)
If you're using an ESP8266, the built-in LED uses reversed logic. So, switch it on as follows:
>>> led.value (0)
The on-board LED should illuminate.
Now you may switch off the built-in LED. On the ESP32, execute the following command:
>>> led.value (0)
Like this for the ESP8266:
>>> led.value (1)
If everything works as intended, it indicates you successfully installed Thonny IDE and MicroPython firmware on your ESP32 or ESP8266 devices.
Thonny IDE Overview
By this time, you should have:
- Thonny IDE is installed on your computer.
- ESP32/ESP8266 loaded using MicroPython firmware.
- The Editor section is where you may write code and edit.py files. You can open many files, and the Editor will open a new tab for each one.
- You can type commands into the MicroPython Shell that will be executed immediately by your ESP board, eliminating the need to upload new files. The terminal displays program status, faults during uploading, syntax mistakes, and message output.
The Variables tab could prove to be really beneficial. It lists all of your program's variables and their values.












0 Comments