Raspberry Pi Pico - SARCNET

School Amateur Radio Club Network
School Amateur Radio Club Network
School Amateur Radio Club Network
School Amateur Radio Club Network
Title
Go to content
Raspberry Pi Pico
This workshop presents the setup, coding and debugging of the Raspberry Pi Pico Microcontroller.

This page is under development.
Setup
The Raspberry Pi Pico can be set up to run C/C++ or MicroPython programs. You can select the language you prefer. Here, we use the Arduino Integrated Development Environment (IDE) for C/C++ and Thonny for MicroPython. You can also choose which operating system you prefer to run on your development machine. Here, we use Windows 10 or Raspberry Pi OS (Linux).

Note: The Arduino IDE provides the advantages of using the same IDE as for your Arduino devices and it includes access to many useful C/C++ library routines (many of which, but not all, will run on the Pico).

When you first plug a Raspberry Pi Pico into the USB port of a Windows 10 machine, it will mount the device as an external File Store and open up a File Explorer window for a device called "RPI-RP2 (D:)". If the window does not open, unplug the Pico, press and hold the BOOTSEL button and plug it back in. You can actually program the Pico by dragging and dropping executable .uf2 files onto this window.
C/C++ on Windows 10
To program the Pico using C/C++ with the Arduino IDE please use the following procedure:
  1. Plug the Raspberry Pi Pico into a USB port
  2. Download and install the Arduino IDE from: https://www.arduino.cc/en/software
  3. Open the Arduino IDE
  4. Click the Boards Manager icon
  5. Enter "Pico" into the Search Box
  6. Select "Arduino Mbed OS RP2040 Boards"
  7. Press "Install"
  8. Select File | Examples | 01.Basics | Blink
  9. Select Tools | Board | Arduino Mbed OS RP2040 Boards | Raspberry Pi Pico
  10. Note: Do not select a Port, as for first-time usage Windows 10 will not have registered a COM port yet
  11. Press "Upload". The Arduino IDE will compile and try to upload the Blink sketch, which will fail for the above reason.
  12. Windows 10 will then report:
    1. Settings: Setting up a device - We're setting up 'Raspberry Pi Pico'.
    2. Settings: Device is ready - 'Raspberry Pi Pico' is set up and ready to go.
  13. The Arduino IDE will then display a COM port for the Pico. Tools | Port should now display: COMx (Raspberry Pi Pico)
  14. Press "Upload" again. The LED on the Pico should start flashing slowly. The Arduino IDE Output window will display:

Sketch uses 89829 bytes (4%) of program storage space. Maximum is 2097152 bytes.
Global variables use 42824 bytes (15%) of dynamic memory, leaving 227512 bytes for local variables. Maximum is 270336 bytes.

Congratulations, you have now configured the Arduino IDE to compile and upload C/C++ programs the Raspberry Pi Pico!

MicroPython on Windows 10
To program the Pico using MicroPython with the Thonny  IDE please use the following procedure:
  1. Download the latest UF2 bootloader from https://micropython.org/download/rp2-pico/
  2. Press and hold the Raspberry Pi Pico BOOTSEL button.
  3. Plug the Pico into a USB port.
  4. A File Explorer window for a device called "RPI-RP2" will open
  5. Drag and drop the UF2 bootloader (e.g. rp2-pico-20220618-v1.19.1.uf2) to the RPI-RP2 folder.
  6. The File Explorer window will close.
  7. Browse to https://thonny.org/
  8. At the top of the page, in the download box, click on your operating system, select your platform and download the latest installer for Thonny.
  9. Run the installer, as Administrator (right-click to select)
  10. Select the install mode: "Install only for me". Select Next. Accept the agreement. Select the installation folder. Select "Create a desktop icon". Press Finish.
  11. Double-Click on the desktop icon. Select the language and standard settings.
  12. When the Thonny window opens select Run | Configure interpretter...
  13. Select the "MicroPython (Raspberry Pi Pico)" interpretter and click OK
  14. Enter the code below. It should look the same as the image below.
  15. Select File | Save as... | This Computer | blink.py.
  16. Click the green Run button.
  17. The built-in LED on the Pico should flash.
  18. To save the program to the Pico: Select File | Save as... | Raspberry Pi Pico | main.py.
  19. The program will run whenever the Pico is started.

Code:
from time import sleep
from machine import Pin
led = Pin(25, Pin.OUT)
while True:
led.toggle()
sleep(0.1)

Image:

C/C++ on Raspberry Pi OS (Linux)
MicroPython on Raspberry Pi OS (Linux)
Coding

Debugging
Something went wrong? Here are some problems we have encountered and how to fix them.
Windows 10 COM Port Not Registering
When you plug a Pico into a Windows 10 USB port it is supposed to register a virtual COM port. The COM port should appear in the Ports section of Windows Device Manager. Sometimes Windows 10 just refuses to register a port or it registers a port that is already in use. Sometimes, an error in a previously uploaded Pico program can stop Windows 10 from registering the COM port. These problems can be permanent, until you perform the recovery action below. One known programming error that causes this to happen is initializing a Pico serial (UART) port in the constructor of a C++ class. There may be other causes too. To check for this problem and to restore operation, perform the following steps:

  1. Unplug the Pico from the USB port
  2. Open Windows 10 Device Manager and select Ports
  3. Select View | Show hidden devices
  4. Plug the Pico into the USB port
  5. Check to see if a new COM port appears in Windows Device Manager. If it does, all is well. If not, proceed with the following steps:
  6. Unplug the Pico from the USB port.
  7. Press and hold the Pico BOOTSEL button
  8. Plug the Pico into the USB port
  9. Release the pico BOOTSEL button
  10. Verify that the Pico file explorer window has opened
  11. Copy this pico.ino.uf2 file to the Pico file explorer
  12. Verify that the Pico file explorer window closes and a new COM port appears in Windows 10 Device Manager. If it does, all is well. If not, maybe try again?
  13. If, however, Windows 10 allocates the Pico to an existing COM port, that can cause problems too. You may be able to fool Windows 10 into using a differnet port by right-clicking on the Pico device and selecting "Uninstall Device". Or you can try uninstalling "hidden" devices to free up some COM ports. Then repeat steps 5 onwards.
  14. We have no idea why Windows 10 does this. One hopes it may be fixed in a future update.

Back to content