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

PenguinTutor YouTube Channel

Learning the Raspberry Pi Pico Microcontroller

The Raspberry Pi Pico is a small inexpensive microcontroller based around a custom designed integrated circuit. It has support for C/C++ as well as MicroPython.

There is now a wireless version of the Raspberry Pi Pico. For the wireless version please see Pico W (Wi-Fi) project page.

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.

Communicating between a Raspberry Pi and a Pico with UART - Voltmeter project

This is a mini project showing how you can communicate between a Raspberry Pi computer and a Raspberry Pi Pico. This is using the UART serial protocol. It uses the Analog-to-Digital convertor to measure a voltage input, which is then displayed on a graphical user interface (GUI) on the Raspberry Pi.

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.

The project is a bit different than I originally planned. I was hoping to use I squared C or possibly SPI to communicate between the Raspberry Pi and the Raspberry Pi Pico, but I ended up using UART serial instead. That’s not a problem with this example, but I’ll explain the reason for that in the video. I hope to look at the other protocols in a future video.

Wiring up the Raspberry Pi and the Raspberry Pi Pico

The following connections are needed. Both the Raspberry Pi and the Raspberry Pi Pico have 3.3V for the GPIO so these can be connected direct without needing a level-converter.

  • Raspberry Pi Gnd physical pin 14 to Pico Gnd physical pin 8.
  • Raspberry Pi Tx physical pin 8 to Pico Rx physical pin 7.
  • Raspberry Pi Rx physical pin 10 to Pico Tx physical pin 6.

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.

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:

Other projects using the Raspberry Pi Pico

Future projects

I'm always working on new projects
To find out about the updates please:
Subscribe to the PenguinTutor YouTube Channel
and
Follow @penguintutor on Twitter

Previous Maker / hacker projects
Maker / hacker projects
Next Pico W (Wireless)
Pico W (Wireless)