MicroPython
What is MicroPython?
Edit this on GitHub
MicroPython is a full implementation of the Python 3 programming language that runs directly on embedded hardware like Raspberry Pi Pico. You get an interactive prompt (the REPL) to execute commands immediately via USB Serial, and a built-in filesystem. The Pico port of MicroPython includes modules for accessing low-level chip-specific hardware.
-
The MicroPython Wiki
Note
|
If you’re new to MicroPython, our official guide, "Get started with MicroPython on Raspberry Pi Pico", is a great place to start. Learn the basics of MicroPython and physical computing, connect your Pico to displays and sensors, build alarms, reaction games, and more. |
Drag-and-Drop MicroPython
Edit this on GitHub
You can program your Pico by connecting it to a computer via USB, then dragging and dropping a file onto it so we’ve put together a downloadable UF2 file to let you install MicroPython more easily.
Download the correct MicroPython UF2 file for your board:
-
Raspberry Pi Pico W (with urequests and upip preinstalled)
Then go ahead and:
-
Push and hold the BOOTSEL button and plug your Pico into the USB port of your Raspberry Pi or other computer. Release the BOOTSEL button after your Pico is connected.
-
It will mount as a Mass Storage Device called RPI-RP2.
-
Drag and drop the MicroPython UF2 file onto the RPI-RP2 volume. Your Pico will reboot. You are now running MicroPython.
-
You can access the REPL via USB Serial.
The Raspberry Pi Pico Python SDK book contains step-by-step instructions for connecting to your Pico and programming it in MicroPython using both the command line and the Thonny IDE.
Warning
|
If you are using an Apple Mac and running macOS Ventura there has been a change in how the Finder works which causes drag-and-drop to fail. This issue was fixed as of macOS Ventura version 13.1. Please see our blog post for a full explanation along with workarounds if you are unable to upgrade to the latest version of Ventura. |
Where can I find documentation?
Edit this on GitHub
You can find information on the MicroPython port to RP2040 at;
- Raspberry Pi Pico Python SDK
-
A MicroPython environment for RP2040 microcontrollers
- Connecting to the Internet with Raspberry Pi Pico W
-
Getting Raspberry Pi Pico W online with C/C++ or MicroPython
- RP2 Quick Reference
-
The official documentation around the RP2040 port of MicroPython
- RP2 Library
-
The official documentation about the
rp2
module in MicroPython
There is also a book by Raspberry Pi Press available written by Gareth Halfacree and Ben Everard.
In "Get Started with MicroPython on Raspberry Pi Pico", you will learn how to use the beginner-friendly language MicroPython to write programs and connect hardware to make your Raspberry Pi Pico interact with the world around it. Using these skills, you can create your own electro-mechanical projects, whether for fun or to make your life easier.
-
Set up your Raspberry Pi Pico and start using it
-
Start writing programs using MicroPython
-
Control and sense electronic components
-
Discover how to use Pico’s unique Programmable IO
-
Make a reaction game, burglar alarm, temperature gauge, and many more
You can buy the book on the Raspberry Pi Press site.
Which hardware am I running on?
Edit this on GitHub
There is no direct method for software written in MicroPython to discover whether it is running on a Raspberry Pi Pico or a Pico W by looking at the hardware. However, you can tell indirectly by looking to see if network functionality is included in your particular MicroPython firmware:
import network
if hasattr(network, "WLAN"):
# the board has WLAN capabilities
Alternatively, you can inspect the MicroPython firmware version to check whether it was compiled for Raspberry Pi Pico or for Pico W using the sys
module.
>>> import sys
>> sys.implementation
(name='micropython', version=(1, 19, 1), _machine='Raspberry Pi Pico W with RP2040', _mpy=4102)
So if the 'Pico W' string is present and in sys.implementation._machine
that can be used to determine whether your firmware was compiled for Pico W.