Quick Guide to Setting Up a Raspberry Pi Pico with MicroPython and Thonny
Quick Guide to Setting Up a Raspberry Pi Pico with MicroPython and Thonny
Introduction
Setting up a Raspberry Pi Pico for MicroPython is a straightforward process that gets you up and running quickly. In this guide, we'll walk through how to flash MicroPython onto your Pico, set it up using Thonny, and run your first "blinking light" script. Whether you're new to microcontrollers or just need a refresher, this guide will get you started in no time.
Step 1: Get the MicroPython UF2 File
To begin, you'll need the MicroPython firmware for the Pico. Here's where to get it:
1. Visit the official Raspberry Pi website's MicroPython page.
2. Download the MicroPython UF2 file for the Raspberry Pi Pico. This file is necessary for flashing MicroPython onto your Pico and will allow you to program the Pico in the MicroPython environment.
Step 2: Cabling Up Your Raspberry Pi Pico
You'll need a USB cable that supports both power and data transfer—commonly a USB-A to microUSB cable. Here's how to connect your Pico:
1. Get the cable: Make sure the cable supports data transfer, not just power. A typical phone charging cable works if it has both functions.
2. Hold the BOOTSEL button: Press and hold the small BOOTSEL button on your Pico before plugging it into your computer.
3. Plug in the Pico: While holding the button, plug the Pico into a USB port on your computer using the microUSB end.
Your Pico will now appear as a mass storage device on your computer, like a flash drive.
Step 3: Flashing the MicroPython UF2 File
Now that your Pico is connected:
1. Locate the UF2 file you downloaded earlier.
2. Drag and drop the UF2 file onto the Pico's storage drive that appeared on your computer. The Pico will automatically reboot after the file is copied, setting up MicroPython.
At this point, the Pico is ready for coding in MicroPython.
Step 4: Open Thonny and Access the Pico
Thonny is an excellent Python IDE for working with the Raspberry Pi Pico. If you haven't already installed it, download and install Thonny.
1. Launch Thonny: Open Thonny on your computer.
2. Configure Thonny for MicroPython:
- Go to Tools > Options.
- In the Interpreter tab, select MicroPython (Raspberry Pi Pico) from the drop-down list.
- Make sure the correct USB port is selected for the Pico.
Now, you're ready to interact with the Pico through Thonny.
Step 5: Flash the Light (Your First MicroPython Script)
Time to write your first script and see something happen! We'll start with a simple "blink the onboard LED" script.
1. In Thonny's editor, enter the following code:
(MicroPython)
from machine import Pin
import time
led = Pin(25, Pin.OUT)
while True:
led.toggle()
time.sleep(0.5)
2. Save the file to your Pico, naming it something like blink.py.
3. Click the Run button (green arrow) at the top of Thonny.
You should now see the onboard LED blink on and off every half second.
You're Done!
Congratulations! You've successfully set up your Raspberry Pi Pico, flashed MicroPython, and written your first program using Thonny. Now, you're ready to explore the world of MicroPython and Raspberry Pi Pico projects! 😊✨
Image: Raspberry Pi
Comments
Post a Comment