Raspberry Pi Pico Programming: Initial Setup Guide for School Students
Welcome to the exciting world of Raspberry Pi Pico programming! If you love gadgets and enjoy making things work, you’re in for a treat. The Raspberry Pi Pico is a tiny, powerful microcontroller that you can program using several languages. Let’s dive into how you can start programming your Pico with MicroPython, a beginner-friendly language that’s perfect for young tech enthusiasts like you.
1.1 Programming Languages for Raspberry Pi Pico
When it comes to programming the Raspberry Pi Pico, you have a few options:
- C/C++: These are powerful languages used by many professionals, but they can be a bit tricky for beginners.
- MicroPython: This is a special version of Python designed just for microcontrollers like the Pico. It’s easy to learn and great for beginners.
- Assembly Language: This is a low-level programming language that’s closer to what the computer actually understands. It’s not commonly used by beginners.
While the Pico is set up for C/C++, many new programmers prefer starting with MicroPython because it’s simpler and more intuitive.
1.2 Installing MicroPython on the Pico
Before we can start programming, we need to install MicroPython on the Pico. Once installed, it stays on your Pico until you decide to change it. Here’s how you can get MicroPython up and running, using either a Raspberry Pi 4 or a PC with Windows 10.
1.2.1 Using a Raspberry Pi 4 to Install MicroPython
If you have a Raspberry Pi 4, follow these steps:
- Boot Up: Turn on your Raspberry Pi 4 and log in.
- Internet Connection: Ensure your Raspberry Pi is connected to the Internet.
- Connect Pico: Hold down the BOOTSEL button on your Pico and connect it to the Raspberry Pi using a micro-USB cable. Keep holding the button for a few seconds and then release it.
- Detect the Pico: Your Pico should appear as a removable drive. Click OK when you see the “Removable medium is inserted” window.
- Download MicroPython: Open the file INDEX.HTM from the Pico drive, scroll down, and click on the “Getting started with MicroPython” tab. Download the UF2 file.
- Install MicroPython: Drag and drop the downloaded UF2 file onto the Pico drive. This will install MicroPython on your Pico.
Now, your Pico is ready to run MicroPython!
1.2.2 Using a PC (Windows) to Install MicroPython
No Raspberry Pi? No problem! You can use your PC:
- Connect Pico: Hold down the BOOTSEL button on your Pico and connect it to your PC using a micro-USB cable. Release the button after a few seconds.
- Detect the Pico: Your Pico will appear as a removable drive named RPI-RP2.
- Download MicroPython: Open the INDEX.HTM file from the Pico drive, scroll down, and click on the “Getting started with MicroPython” tab. Download the UF2 file.
- Install MicroPython: Drag and drop the downloaded UF2 file onto the Pico drive. This will install MicroPython on your Pico.
Congratulations! Your Pico is now running MicroPython.
Using the Thonny Text Editor
To write and run your MicroPython programs, we’ll use the Thonny text editor, which is specially designed for Python programming. Let’s set it up and write our first program.
Using Thonny on a Raspberry Pi
- Open Thonny: On your Raspberry Pi, click Menu, go to Programming, and select Thonny Python IDE.
- Select MicroPython: Click on the label Python at the bottom right-hand corner and select MicroPython (Raspberry Pi Pico).
- Check Connection: You should see the version number of MicroPython displayed at the bottom of the screen.
- Write Your First Program: In the Shell (the lower part of the screen), type:pythonCopy code
print("Hello from Raspberry Pi Pico")
Press Enter, and you should see the message displayed.
Using Thonny on a PC
- Install Thonny: Go to the Thonny website (https://thonny.org/) and download the installer. Run the installer to set up Thonny on your PC.
- Open Thonny: Double-click the Thonny icon on your desktop to open it.
- Select MicroPython: Click on the label Python at the bottom right-hand corner and select MicroPython (Raspberry Pi Pico).
- Write Your First Program: In the Shell (the lower part of the screen), type:pythonCopy code
print("Hello from Thonny on PC")
Press Enter, and you should see the message displayed.
Writing a Program in Thonny
Now, let’s write a simple program to save and run on your Pico.
- Write Your Code: In the upper part of the Thonny screen, type:pythonCopy code
print("Hello from my first program!")
- Save Your Program: Click File, then Save As. Choose to save it on the Pico and name it
FirstProg.py
. - Run Your Program: Click the green arrow (Run) at the top of the screen. The output will be displayed in the Shell.
Fun with MicroPython
In the upcoming chapters, we’ll explore various fun and fully tested projects using MicroPython with the Pico. From creating simple games to building interactive gadgets, there’s so much you can do. We’ll also cover some projects using C language, giving you a taste of more advanced programming.
Conclusion
Programming the Raspberry Pi Pico with MicroPython is a great way to start your journey into the world of coding. It’s simple, fun, and you can create amazing projects. So, grab your Pico, follow the steps, and let’s start coding!
Stay tuned for more exciting projects and tips in the next