MICROPYTHON WITH THE ESP32 GUIDE SERIES
Find Python Packages At PyPI
PyPi is a repository of Python and MicroPython packages. You can search PyPi from Thonny IDE and install packages with a single click. In this lesson I'll show you how.
The Thonny PyPi tool
You can install a Python package directly from the Thonny ID user interface.
You will find the PyPi search and installation tool under Tools, Manage Packages.
Example 1: search, find, install a MicroPython package
PyPi contains thousands of Python packages. Only some of them are specifically written in MicroPython. Most MicroPython packages are written to be compatible with a specific microcontroller, like the ESP32 or the Micro:bit.
You need to be mindful of this, and take care so that the package that you eventually download to your Thonny is actually compatible with your target device.
I'll show you an example of how to do this.
Let's start with a very broad search on the term "MicroPython" directly on the PyPi website. This search will return any packages that contain the term "MicroPython".
As you can see there are almost a thousand project that contain this name, I am not familiar with any of the projects showing in the first page of the list.
I'll pick one randomly to take a closer look, from page two of the list.
The "lucky" project is titled "micropython-selectors 0.0.1".
Let's say that this is a package that you would like to use in your MicroPython project. The next thing to do is to download it and install it in Thonny.
Copy the name, go to Thonny, bring up the Manage Packages window (under "Tools"), and copy the package name in the search field.
In the list of results, you'll find the package with the name you searched for at the top. Click on the package hyperlink to get to the package information page. Click on the Install button to download and install the package.
A few seconds later, you'll see the package listed in the left-side packages list.
Example 2: search for a specific MicroPython package (gives error)
Let's look at another example. Unlike the previous generic search, now I'd like to be somewhat more specific. Let's look for a MicroPython package that is compatible with the ESP32.
Let's try this search term: "MicroPython dht ESP32".
With this search I hope to find a DHT11 or DHT22 MicroPython driver for the ESP32.
Do the search in PyPi.org and take a minute to look at the results.
Because MicroPython can be used across a lot of different hardware targets, not all the package search results will be compatible with the target you intend to use. However, ESP23 and ESP8266 are (generally) cross-compatible when it comes to MicroPython. So, in general, if you find a package that is marked to be compatible with the ESP8266, chances are that the package will also work with the ESP32.
In the result list for the term "micropython dht esp32", there are several hits. One that drew my interest is titled "micropython-wifimanager".
Let's install this package in Thonny.
Follow the exact same process as with example 1. Copy the package name into the Thonny package manager tool, and click on the "Install" button.
Unfortunately, the installation failed for me at the time I was writing this guide (it may work for you).
I am not sure why the installation failed, but the error message suggest a problem with the configuration of the package itself, and not Thonny.
This is unfortunate, but not the end of the world.
Let's try something else.
Example 3: esp32-net-config
An interesting package is titled "esp32-net-config". It creates a local WiFi access point so that you can configure a hot-spot SSID and password without having to hard-wire this information on your ESP32.
Install it as you did with examples 1 and 2. The package contains several files, that will be listed in the left text box:
Close the package manager, and look at the file browser of the ESP32 target device in the left bottom corner of the Thonny IDE. Inside the lib directory you can see the files that make up the package you just installed.
Click on the config.py file (or any of the other files, if you prefer), to look inside.
If you want to curious to learn how to use this package, you can have a look at the information in the project's GitHub repository which contains instructions and examples.
These were three simple examples of how you can find, install, and inspect MicroPython packages available in the PyPi repository.
Learn MicroPython for the ESP32
With this video course, you will learn how to use the
MicroPython programming language with the ESP32 micro-controller.
MicroPython is the perfect language for anyone looking for the easiest (yet still powerful) way to program a micro-controller.
Jump to another article
1. What is MicroPython?
2. MicroPython vs Python
3. MicroPython resources
4. MicroPython compatible boards
5. Getting started with Thonny IDE
6. How to install the MicroPython firmware
7. Setup an interpreter in Thonny IDE
8. How to write and execute a MicroPython program
9. Thonny IDE with the Raspberry Pi Pico
10. Thonny IDE with the BBC Micro:bit
11. Thonny IDE advanced configuration
12. How to find MicroPython packages at PyPi
13. The MicroPython shell
14. MicroPython Programming with files
15. How to interrupt a running program
16. How to run a program at boot
17. How to debug MicroPython program
Last Updated 8 months ago.
We publish fresh content each week. Read how-to's on Arduino, ESP32, KiCad, Node-RED, drones and more. Listen to interviews. Learn about new tech with our comprehensive reviews. Get discount offers for our courses and books. Interact with our community. One email per week, no spam; unsubscribe at any time