How to install MicroPython Learn how to Install micropython on your microcontroller 10 January 2024 3 minute read By Kevin McAleer Share this article on Table of Contents How to Install MicroPython on Your Microcontroller: A Step-by-Step GuideHow to Install MicroPythonDownloading the MicroPython FirmwareConnecting Your MicrocontrollerFlashing the FirmwareVerifying the InstallationInstalling MicroPython Using ThonnyInstall ThonnyOpen Thonny and Connect Your MicrocontrollerChoose the VersionWriting and Running Your First ScriptConclusion: Getting Started with MicroPythonWhere can I learn MicroPython?Learn Micropython - the basics Tags Micropython Microcontrollers Raspberry Pi ESP32 ESP8266
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: Download the MicroPython firmware for your microcontroller Connect your microcontroller to your computer Flash the MicroPython firmware onto the microcontroller Verify the installation Alternatively Install Thonny Open Thonny and connect your microcontroller Choose the version 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 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 Flashing the Firmware Flashing the firmware for most modern micropython boards is really simply: Unplug the USB cable Press and hold the boot (bootsel on some boards) button Plug in the USB cable Release the boot button 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 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 Launch Thonny Before connecting your microcontroller to your computer via USB, hold down the boot or bootsel button on the microcontroller Thonny automatically detects the device and displays it in the ‘Device’ dropdown menu at the bottom right of the screen. Click Install MicroPython... Installing Thonny Choose the Version Select the version of MicroPython you want to install (the Raspberry Pi Pico / Pico H is a good choice, in this scenario) Click the Install button The firmware will upload to the device and once its complete you can click the Close button Selecting the MicroPython version 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 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: Learn Micropython - the basics