Third party cookies may be stored when visiting this site. Please see the cookie information.

PenguinTutor YouTube Channel

Programming the Raspberry Pi Pico

In my first video on the Raspberry Pi Pico I explain what it is, how it differs from the Raspberry Pi computers and where you'd choose each. I also explained how you can get the advantages of both by using them together.

This video includes a very basic program in MicroPython showing how you can install MicroPython on the Pico and then create your own program using the Thonny editor.

Raspberry Pi and Pico talking together

I've also created a guide to programming the Raspberry Pi and Pico to communicate together. This allows a graphical program on the Raspberry Pi to receive information from the Pico. This uses UART serial data transfer.

Code is provided for both Python and C running on the Pico and then Python with Pygame Zero on the Raspberry Pi computer.

The use of the Pygame Zero for a graphical interface for an electronics project is along similar lines to my project Pygame Zero for makers - controlling electronics with Python PygameZero.

Installing MicroPython on the Pico

A full workthrough on setting up MicroPython is included in the first video. This goes through the instructions on the Raspberry Pi Pico getting started page. A quick summary of steps is included below.

  • Download the MicroPython UF2 file from the Raspberry Pi website.
  • Connect the Pico to your computer whilst holding down the BOOTSEL button.
  • Copy the UF2 file to the Pico.
  • Launch the Thonny editor and click on the Pico (or MicroPython Generic) in the bottom right.
  • Use the REPL in the bottom of the editor to run commands directly.
  • Create code in the editor to run on the Pico.
  • To have code run automatically whenever the Pico is connected save the program to the pico named main.py.

Wiring details

Details for wiring up the Raspberry Pi and the Raspberry Pi Pico are on the Raspberry Pi Pico Projects page.

Compiling and installing a C/C++ file on the Pico

A run through is shown in the voltmeter video. This goes through the instructions on the Raspberry Pi Pico getting started page.

  • Download the setup script from the SDK Setup section of the above website.
  • Give the shell executable permissions using:
    chmod +x pico_setup.sh
  • Run the script
    ./pico_setup.sh
  • Find something else to do for the next hour or so. How about a nice cup of tea?
  • Create a pico projects directory (optional):
    cd pico
    mkdir pico-projects
  • Create a directory for your projects and copy the following files from the pic-examples folder:
    • pico_sdk_import.cmake
    • CMakeLists.txt (edit with name of your code any libraries you need)
  • Create your c code.
  • Compile the code
    mkdir build
    cd build
    cmake ..
    make -j2
  • Hold down bootsel whilst booting your Pico and copy the .uf2 file from your build directory to the pico
  • The code will now run on the pico and run automatically whenever it is restarted (without the BootSel button pressed).

From Pico to GUI using Pygame Zero

The code that creates the GUI on the Raspberry Pi is written in Pygame Zero. It is created in the Mu editor which has a Pygame Zero mode, making it easier to create Pygame Zero videos.

For more details on creating GUIs see my project on creating maker gui interfaces using Pygame Zero. See this post for details of the serial uart code in Python.

Source code and other files for Raspberry Pi Pico Voltmeter

The files required are listed below:

Blog links and videos on programming

Previous LCD display with micro:bit
LCD display with micro:bit
Next Raspberry Pi Pico LCD display
Raspberry Pi Pico LCD display