How to Install MicroPython on Your Microcontroller: A Step-by-Step Guide

MicroPython brings the simplicity and power of Python to microcontrollers, making it an ideal choice for a wide range of projects. Whether you’re a beginner or an experienced developer, installing MicroPython is a straightforward process.

This article will guide you through the general steps for installing MicroPython on most microcontrollers, followed by specific instructions for using Thonny, a popular Python IDE, to make the process even simpler.

How to Install MicroPython

Here are two methods for installing MicroPython on a microcontroller:

  1. Download the MicroPython firmware for your microcontroller
  2. Connect your microcontroller to your computer
  3. Flash the MicroPython firmware onto the microcontroller
  4. Verify the installation

Alternatively

  1. Install Thonny
  2. Open Thonny and connect your microcontroller
  3. Choose the version
  4. Write and run your first script

Downloading the MicroPython Firmware

The first step is to download the appropriate MicroPython firmware for your microcontroller. This can typically be found on the MicroPython website under the ‘Downloads’ section. Ensure you select the firmware that matches your specific microcontroller model.

Picture of the MicroPython download page

Picture of the MicroPython download page


Connecting Your Microcontroller

Connect your microcontroller to your computer using a suitable USB cable. It’s important that your computer recognizes the device, which might require installing drivers depending on your operating system and the microcontroller.

Connecting the USB cable

Connecting to USB


Flashing the Firmware

Flashing the firmware for most modern micropython boards is really simply:

  1. Unplug the USB cable
  2. Press and hold the boot (bootsel on some boards) button
  3. Plug in the USB cable
  4. Release the boot button
  5. Drag the firmware file onto the microcontroller from Finder (on macOS) or Explorer (on Windows) - the file will end in .uf2 which is a special firm that the microcontroller knows how to install
  6. Voila, you’re done!

Verifying the Installation

After flashing, most microcontrollers will reboot automatically. You can verify the installation by connecting to the microcontroller’s REPL (Read-Eval-Print Loop) interface, typically through a serial terminal program like PuTTY or an application like the Arduino IDE, or Thonny.


Installing MicroPython Using Thonny

Thonny is a beginner-friendly Python IDE that simplifies working with Python and MicroPython. Here’s how you can use Thonny to install MicroPython:


Install Thonny

Download and install Thonny from its official website https://thonny.org. It’s available for Windows, macOS, and Linux.


Open Thonny and Connect Your Microcontroller

  1. Launch Thonny
  2. Before connecting your microcontroller to your computer via USB, hold down the boot or bootsel button on the microcontroller
  3. Thonny automatically detects the device and displays it in the ‘Device’ dropdown menu at the bottom right of the screen.
  4. Click Install MicroPython...

Installing Thonny

Thonny


Choose the Version

  1. Select the version of MicroPython you want to install (the Raspberry Pi Pico / Pico H is a good choice, in this scenario)
  2. Click the Install button
  3. The firmware will upload to the device and once its complete you can click the Close button

Selecting the MicroPython version

Thonny


Writing and Running Your First Script

Once MicroPython is installed, you can write Python code directly in Thonny’s editor. To run your script on the microcontroller, simply click the ‘Run’ button. Thonny executes the script on the device and displays any output in the built-in shell.

Your first MicroPython program

Thonny


Conclusion: Getting Started with MicroPython

With MicroPython installed on your microcontroller, you’re ready to explore the vast possibilities of microcontroller programming with Python. The simplicity and power of MicroPython, combined with tools like Thonny, make it accessible for everyone, from hobbyists to professionals, to create amazing projects. Whether you’re building smart devices, experimenting with IoT, or learning the basics of electronics, MicroPython is an excellent starting point.


Where can I learn MicroPython?

We have a free course on MicroPython, which you can access here:


Did you find this content useful?


If you found this high quality content useful please consider supporting my work, so I can continue to create more content for you.

I give away all my content for free: Weekly video content on YouTube, 3d Printable designs, Programs and Code, Reviews and Project write-ups, but 98% of visitors don't give back, they simply read/watch, download and go. If everyone who reads or watches my content, who likes it, helps fund it just a little, my future would be more secure for years to come. A price of a cup of coffee is all I ask.

There are a couple of ways you can support my work financially:


If you can't afford to provide any financial support, you can also help me grow my influence by doing the following:


Thank you again for your support and helping me grow my hobby into a business I can sustain.
- Kevin McAleer