
Explore MicroPython on the ESP32 microcontroller, with guidance for Python users, beginners, and Arduino programmers, covering motors, displays, wifi, IoT, and two capstone projects.
Explore how MicroPython adapts Python for microcontrollers by offering a lean Python 3 subset, a repl, board-specific libraries, and cross-target portability on ESP32 and more.
Identify and set up the software you need for MicroPython on the ESP32, including a suitable editor, the correct MicroPython firmware, and libraries for sensors, motors, and displays.
explore the essential hardware for MicroPython with the ESP32, including a basic board with a pullup button, sensors, oled displays, i2c, Pyxis modules, and small motors.
Plan your learning with dedicated time and uninterrupted blocks, so you complete one section in a sitting and achieve the learning and practical outcomes before moving on.
Download a zip file containing all demo scripts used in the MicroPython with the ESP32 course, then test and modify them to explore the demonstrated code.
Explore core differences between MicroPython and CPython, including stricter syntax rules, self keyword handling, formatting and string methods limitations, and non-raising json serialization errors, with pointers to official resources.
Explore MicroPython resources, from official documentation to community forums, and leverage libraries from Awesome MicroPython and the Python Package Index to accelerate ESP32 development.
Explore how MicroPython runs on diverse boards, from the original pinboard to ESP32 and ESP8266, Raspberry Pi pickle, and the BBC micro:bit, noting wifi, Bluetooth limitations, and available drivers.
Explore Thonny, an open source IDE, to program the ESP32 with MicroPython, install the interpreter, switch between MicroPython and other interpreters, and interact with the Python console.
Download and install the latest Sony editor beta from GitHub releases, and compare version 4 with version 3, noting Python 3.10 and Pipkin for macro Python on ESP32.
Install the MicroPython firmware on the ESP32 by downloading the stable 1.14 release from the MicroPython site and uploading it with Sony, then access the MicroPython prompt.
Upgrade the ESP32 dev kit to MicroPython 1.18 by downloading the latest stable release, erasing flash, updating firmware, and restoring your files, then test a GPIO 21 blink script.
Learn to fix a failed ESP32 firmware upload by holding the boot button during installation, and explore a cheap capacitor hack to enable boot mode.
Explore switching between Python interpreters across devices, from the built-in environment to MicroPython on Raspberry Pi Pico and Micro:bit, using the interpreter drop-down.
Learn to write a simple MicroPython program for the ESP32 and run it in the interactive shell or as a file on the device.
Explore Thonny IDE debugging features for general Python and desktop versions, contrasted with micro Python; learn about object inspector, heap and stack memory, and step over/into/out with Birds Eye debugger.
Learn to set up Thonny IDE with the Raspberry Pi Pico, run MicroPython, and toggle the pin connected to JP twenty five using the machine pin module.
Upgrade the Raspberry Pi Pico to MicroPython 1.18 by backing up its flash, then using Thonny to install the latest firmware in boot mode.
Explore how to run a micro:bit MicroPython program in Thonny and install firmware. Create a Hello world message that scrolls on the dot matrix using the display module and set_pixel.
Explore the ESP32 advanced configuration in Thonny, including syncing the RTC, UTC versus local time, and editing the data folder config file for time settings and three time-setting methods.
Find and install Python packages for MicroPython on the ESP32 using a built-in package manager and PyPI. Learn to search, view package details, and verify hardware compatibility before installation.
Learn to use the ESP32 micro python shell to run scripts, list directories, and execute files; upload and download code with Thony and control hardware via the machine module.
Learn to manage and transfer MicroPython files between your host computer and the ESP32 using Thonny's file manager, run scripts on the device, and perform bulk uploads and downloads.
Learn to organize MicroPython projects on the ESP32 by splitting code into modules, creating simple functions, importing libraries, and calling those functions to perform arithmetic operations and print results.
Learn to interrupt and restart a running MicroPython program on the ESP32 using soft resets, Ctrl-C, Ctrl-D, hard resets, and disconnecting, with auto start on boot.
Learn to run a MicroPython script at boot on the ESP32 by either embedding code in the boot file or importing a separate module, ensuring automatic execution on power-up.
Learn practical MicroPython debugging techniques for the ESP32, using print statements to trace values, read Python error messages, and interpret tracebacks to fix pin and function issues.
Explore the basics of Python and micro Python for microcontroller development, and learn core concepts like reserved keywords, variables, types, sequences, dictionaries, control structures, functions, and objects.
Discover how Python reserves keywords that cannot be used to declare variables, classes, or functions, and learn to distinguish reserved keywords from developer-defined names using code examples and syntax highlighting.
Discover how to document MicroPython code for the ESP32 with header block comments using triple quotes and inline # comments.
Explore built-in Python and MicroPython data types, including numbers, sequences, mappings, and exceptions, and learn type compatibility, casting, and basic operations across types.
Explore Python operators across numeric types, text, and lists, with arithmetic, concatenation, and counting examples. Learn about the operator module, its MicroPython availability, and how to install it for operations.
Explore how to print and format strings in MicroPython and Python, covering the string module, placeholders, escape sequences, and the format specification language.
Explore the three Python sequences—lists, tuples, and ranges—and learn how mutable lists differ from immutable tuples and how ranges provide count sequences in MicroPython on the ESP32.
Learn looping techniques in MicroPython on the ESP32 by iterating ranges, lists, tuples, and dictionaries with for loops, and printing items using range, items(), and key-value access.
Explore how if, elif, and else enable runtime decision making in MicroPython by evaluating user input with integer casting and a range of comparison operators, including chained expressions.
Define and use functions in MicroPython with the ESP32 to organize code, handle parameters and defaults, and return results from simple and named calls.
Explore classes and objects in MicroPython on the ESP32 by building a calculator class with add and subtract methods, including constructor initialization and instance state.
Learn how MicroPython on the ESP32 differs from CPython, with examples on spaces, constructor arguments, and traceback behavior, and consult the MicroPython documentation for details.
Discover how MicroPython modules work, including built-in and community modules, and how to import selectively for ESP32 RAM efficiency, for example, a 2x16 LCD with the LCD API module.
Discover MicroPython built-in modules, compare standard and micro libraries, and learn to import only needed ESP32-specific functions to optimize memory while accessing hardware with the machine module.
Explore how to find and evaluate MicroPython modules for ESP32 projects, compare LCD display libraries, and install chosen packages via a package manager, with guidance from Awesome MicroPython and PyPI.
Install external modules on the ESP32 with MicroPython by downloading a zip, transferring the module directory, and importing the operator module to use add and power.
Learn practical micro python on the ESP32 by blinking an LED in a loop, wiring a generic SB 32 board and exploring peripherals with Thonny.
Use a hardware timer in MicroPython on the ESP32 to blink an LED, replacing a while loop with a periodic timer and a callback ISR.
Fade an led with pwm on ESP32 using MicroPython, selecting pwm capable pins like GPIO 21, setting frequency and duty (0-1023), and looping with range to fade in and out.
read the button state on the esp32 with microPython, using an internal pull up and a loop, then three progressively efficient examples using the pin constructor and time.ticks_ms.
Discover how to read a button with a hardware interrupt on the ESP32, using IRQ on the falling edge, an ISR, and global variables to manage button presses efficiently.
Read the state of a button using a hardware timer and interrupt service routine with a 50 ms period, updating a global flag and turning on an LCD when pressed.
Learn to read a potentiometer with ESP32 using MicroPython, scale a 12-bit adc 0–4095 to 0–1023 with a 0.24 factor, convert to int, and update the output in a loop.
Use the DHT22 environment sensor with MicroPython on the ESP32, wiring it correctly, leveraging the built-in DHT driver, and performing periodic measurements to read temperature and humidity.
Learn to use a third-party MicroPython driver to connect the BME280 with the ESP32 via I2C, import the driver, and read temperature, humidity, and pressure.
Learn to read three-axis data from an analog accelerometer with MicroPython on the ESP32 using ADC with 11 dB attenuation and GPIO pins 34, 35, and 32, outputting readings.
Explore how to use the HC-SR04 ultrasonic distance sensor with MicroPython on the ESP32, including driver installation, wiring, and periodic centimeter distance measurements.
Explore wiring and software setup to drive a 2x16 LCD display with a PCF8574 I2C backpack on the ESP32 using hardware I2C, including essential libraries and a live counter display.
Switches from hardware I2C to software I2C for a 2x16 LCD display with PCF8574 on the ESP32, shows wiring changes and reuses the same MicroPython script.
Learn to drive a 0.96 inch SSD1306 OLED display from MicroPython on the ESP32, including wiring, a frame-buffer based driver, and drawing primitives like text, lines, boxes, and circles.
Drive a 1.3-inch OLED with the SH1106 controller over I2C using the hardware interface, initialize the display, print text, draw rectangles, and run a bouncing box animation.
Explore wiring and driving a 0.96-inch OLED with SSD1315 and SSD1306 controllers on the ESP32 via 3.3-volt supply using software I2C, rendering text, lines, and basic primitives in a loop.
Explore using neopixels with the ESP32 in MicroPython by importing the neopixel module, creating a pixel object, and individually addressing eight LEDs with RGB colors and simple animations.
Drive four max7219 8x8 matrix displays in a row with Esp32 using MicroPython and a max7219 driver, wiring SPI, and rendering random pixels with brightness control.
Learn to display text on the MAX7219 8x8 matrix using the text function, including four-letter strings, brightness and color settings, and the library’s fixed size and no-rotation limitations.
Learn to control a servo on ESP32 with MicroPython using map function to map 0–180 degrees to pwm values, wiring ground, 5 V, and a pwm pin at 50 Hz.
Control a five-volt dc motor with the DRV8871 via in1 for direction and in2 PWM for speed, powered at least 6.5 V and 5.5 V logic for UNO or ESP32.
Last Updated in June and July 2022 to cover the latest versions of the Thonny editor (version 4) and MicroPython firmware (version 1.18+).
More details about this update: I have introduced new lectures to show you how to install and use Thonny 4, and how to upgrade your ESP32 devkit and Raspberry Pi Pico boards to use the MicroPython 1.18 firmware.
I have also tested all experiments to ensure that they work with these versions of Thonny and MicroPython.
If you are using an ESP32 board that is unable to automatically enter upload mode, you will find a solution in a new lecture in Section 3.
With this course, you will learn how to use MicroPython with the ESP32 microcontroller.
MicroPython is a high-level programming language specifically designed for microcontrollers and resource-limited embedded devices.
Who is this course for?
I have created this course for three types of students:
If you are familiar with Python, you will find that MicroPython looks, feels, and works like regular Python. This course will help you get started quickly, and help you out with the peculiarities of using Python as MicroPython operating on the ESP32 hardware.
If you have little programming experience, MicroPython is a perfect option for learning how to program hardware. This course will help you learn enough MicroPython to be able to write programs that run on the ESP32 microcontroller.
If you have experience in programming the ESP32 with the Arduino IDE and language, but what to check out MicroPython, this course will help you do that.
What is MicroPython?
MicroPython is a programming language that borrows the syntax and language attributes of Python 3.
Python 3 is a powerful high-level general-purpose language that is designed to be easy to learn and use. It is extremely popular, and among the top-5 most widely used programming languages. As a result, has an extensive set of learning resources, excellent documentation, and code libraries that cover an amazing breadth of applications.
From gaming to the Internet of Things, from data science to industrial automation, anything that can be programmed in Python.
MicroPython was modelled after Python to reduce the barrier to entry for people that want to write programs for microcontrollers or embedded devices that have limited resources.
What is the ESP32?
The ESP32 is a powerful yet low-cost microcontroller device from Espresif.
The appeal of the ESP32 device is that it packs a powerful dual-core CPU, with relatively large amounts of RAM and flash storage, a full complement of wireless and wired communications options, with lots of input/output pins in a small low-cost package.
The ESP32 is also versatile, as you can program it with a variety of programming tools and languages, including the Arduino IDE, and, of course, MicroPython.
I selected the ESP32 as the hardware for this course because it is easy to find in the market, very affordable considering its capabilities, and, most likely, most people interested in microcontrollers already have at least one.
What are the objectives of this course?
This course has 3 main objectives:
To introduce you to the MicroPython programming language, even if you have little or no prior experience.
To help you learn how to use MicroPython with common external devices, like motors and screens, with MicroPython programs running on an ESP32 microcontroller.
To consolidate this knowledge with the help of two capstone projects. In these projects, you will create a working gadget by combining the knowledge you acquired earlier in the course.
What are the knowledge prerequisites?
Before embarking on this course, please confirm that you tick the following boxes:
You have a basic understanding of electronics. You are comfortable with assembling simple circuits on a breadboard, and you understand simple concepts like pull-up resistors and voltage dividers.
You have a basic understanding of microcontrollers. For example, you know what is a GPIO, the I2C or SPI interfaces and PWM. You understand that if you connect a 3.3V device to a 5V power source, you will damage the device.
You are familiar with related concepts, such as the Internet Of Things (which features in one of the course sections).
You are comfortable with at least one programming language and programming tool. It doesn’t matter which ones, as all modern languages and programming share the same basics.
You have a growth mindset, and you are willing to work hard in order to learn.
If you feel that you don’t tick one of these boxes, consider doing one of my introductory Arduino and Electronics courses first. Then you’ll be ready to come back to this course.
Course organization
This course is organised in four parts.
In the first part, you will learn the basics. This is where you’ll learn how to set up and use Thonny, our programming editor, and prepare your ESP32 to work with MicroPython.
You will also have the opportunity to learn the basics of MicroPython and where and how to find compatible libraries.
The second part is where you roll up your sleeves and write MicroPython programs. You’ll start with simple pin operations that make LEDs blink and read buttons, then move on to sensors, displays, and motors. There’s a large section dedicated to Wifi and Internet of Things applications, and another section dedicated to more advanced topics such as hardware timers, working with internal sensors, and sleep.
In the third and final part, you will consolidate your new knowledge with the help of two capstone projects. Both projects combine the same hardware components with one big difference in the software. While in the first project, all of the MicroPython code exists in the same file, in the second project I show you how to modularise the design and break up the code into two files.
Required software and hardware
For details on the required software and hardware, I have prepared two separate lectures in this section, which I invite you to watch next.
But, in summary:
For the software, you will the Thonny programming tool, and the MicroPython firmware for the ESP32. Both are open-source and free
For the hardware, you will need an ESP32 board, and an assortment of common components like LEDs, resistors, sensors and motors. It doesn’t matter which ESP32 board you have. As long as it is an ESP32, it will work with MicroPython.
If you have taken one of my Arduino courses, you probably already have everything you need.
For the details, please refer to the two lectures in this section where I go into the details for the required software and hardware.
Ok, what's next???
I hope that you now have a good understanding of what this course is about and what to expect ahead.
The first section contains several free lectures with more detailed information about the course. Feel free to watch them if you wish before enrolling.
Happy Learning!