New to microcontrollers? You might be wondering what MicroPython exactly is. This is a special edition of Python 3 designed to run on small, compact microcontroller systems like the Raspberry Pi Pico.
It's great for programming simple functions and even somewhat complex ones—especially if you're already familiar with Python. Read more about it on the official MicroPython website.
Make sure your Pico is ready for whatever project you have in mind. Gather any modules, jumper wires, or tools you might need for your Raspberry Pi Pico project. Here are a few questions to make sure you're prepared to get started.
- Do you need any accessories or additional modules?
- Will you need a breadboard for prototyping?
- Have you soldered any headers into place?
To use MicroPython and program the Pico with it, we'll be using an Integrated Development Environment (IDE) called Thonny. Thankfully, the latest edition has been updated to include support for the Raspberry Pi Pico which saves us a lot of hassle!
Visit the official Thonny website and download the latest edition for your operating system. Versions are available for Mac, Windows, and Linux machines.
Run the installer and make sure Thonny can launch without any issues when it's done.
- Connect your Raspberry Pi Pico to the computer with a micro USB cable while holding the button on the Pico. Your OS should recognize the Pico as a connected device.
- If you haven't already, launch Thonny.
Thonny may not recognize the Pico immediately. Make sure the IDE is configured for using MicroPython with the Raspberry Pi Pico using these steps:
- Open Tools and choose the Interpreter tab.
- Under the drop-down labeled "Which interpreter or device should Thonny use for running your code?", choose "MicroPython (Raspberry Pi Pico).
- Set the Port to "< Try to detect port automatically >".
- Click OK.
When your Pico is first detected, Thonny will give you an option to install MicroPython. Click Install and wait for the process to finish.
The Raspberry Pi Pico can store up to 2MB of data. MicroPython is super flexible in this environment. It doesn't take up much space and is easily stored on the Pico alongside any code you want to use. With Thonny, we can store programs on the Pico or run commands in real-time using the Shell window.
How to store a program
Enter your MicroPython script into the top window in the Thonny application. When you try to save or run it, you will be prompted with a question as to where you want the script to be saved. Specify that you want to use the MicroPython Device. This will ensure the script is saved to the Pico.
Below is a sample script that will toggle the onboard LED.
from machine import Pin led = Pin(25, Pin.OUT) led.toggle()
How to run a program using Shell
It's also possible to run commands using Thonny's Shell window. If you don't see it, click View then Shell. If you run the following script
print ("Hi there.")
You will receive a response in the Shell window with the string
Once you've got a grasp on how MicroPython is installed and programmed on the Pico, all you need is a project to develop! The Pico is a great microcontroller option for projects that need centralized command for a few components at a time. While a Raspberry Pi runs a full-blown OS, these modules are assigned simple tasks and use much less power.
Take your time deciding what components will work best in your project and grab a breadboard for some prototypes. Congratulations! You're ready to get started with MicroPython on the Raspberry Pi Pico.
When it comes to options for decorating for a holiday, Halloween is at or near the top of the list for most people.