Intro to Raspberry Pi Pico and RP2040 - C/C++ Part 3: How to Use PIO | Digi-Key Electronics

Published at : 23 Dec 2025

Programmable Input/Output (PIO) is a unique feature in the RP2040. It allows users to create custom communication peripherals and drivers that run independently of the main program on the CPU. In this video, we’ll show you how to create a simple PIO program that toggles the LED on the Raspberry Pi Pico.

You will need to configure the Pico build system as shown in the first part of this series: https://www.digikey.com/en/maker/projects/raspberry-pi-pico-and-rp2040-cc-part-1-blink-and-vs-code/7102fb8bca95452e9df6150f39ae8422

Setting up debugging is not necessary, but it is recommended: https://www.digikey.com/en/maker/projects/raspberry-pi-pico-and-rp2040-cc-part-2-debugging-with-vs-code/470abc7efb07432b82c95f6f67f184c0. Note that you cannot use step-through debugging on PIO programs.

A written form of this tutorial can be found here: https://www.digikey.com/en/maker/projects/raspberry-pi-pico-and-rp2040-cc-part-3-how-to-use-pio/123ff7700bc547c79a504858c1bd8110

We write a simple blink program in PIO assembly language that toggles the onboard LED and waits for a set number of cycles. We also construct a C helper function in the same PIO file that can be called from the main C program in order to configure the PIO instance and state machine.

Information about the PIO and assembly instructions can be found in Chapter 3 of the RP2040 datasheet: https://datasheets.raspberrypi.org/rp2040/rp2040-datasheet.pdf

In the main C program, we configure the LED pin and set the clock divider for the PIO instance. We then call the helper function found in the PIO program file. We sleep the main CPU so that it does nothing while the PIO program runs independently to toggle the LED.

The PIO can be used to emulate a number of different communication protocols, including UART, I2C, I2S, SPI, PWM, WS2812b driver, SDIO, CAN bus, DVI (with overclocking), etc. We recommend looking at the Raspberry Pi pico-examples repository to see additional examples of PIO programs: https://github.com/raspberrypi/pico-examples/tree/master/pio

Product Links:
https://www.digikey.com/en/products/detail/raspberry-pi/SC0915/13624793

Related Videos:
Intro to MicroPython – Maker.io Tutorial - https://youtu.be/3vnNCSnX7Ig
Intro to Raspberry Pi Pico and RP2040:
Part 1: VS Code and Blink - https://youtu.be/B5rQSoOmR5w
Part 2: Debug with Picoprobe - https://youtu.be/jnC5LrTx470
Part 3: How to Use PIO - https://youtu.be/JSis2NU65w8

Related Project Links:
https://www.digikey.com/en/maker/projects/raspberry-pi-pico-and-rp2040-cc-part-3-how-to-use-pio/123ff7700bc547c79a504858c1bd8110

Related Articles:
Introduction to MicroPython - https://www.digikey.com/en/maker/blogs/2018/introduction-to-micropython
Raspberry Pi Pico and RP2040 - MicroPython Part 1 - https://www.digikey.com/en/maker/projects/raspberry-pi-pico-and-rp2040-micropython-part-1-blink/58b3c31ac93649849b58824caa00529c

Learn more:
Maker.io - https://www.digikey.com/en/maker
Digi-Key’s Blog – TheCircuit https://www.digikey.com/en/blog
Connect with Digi-Key on Facebook https://www.facebook.com/digikey.electronics/
And follow us on Twitter https://twitter.com/digikey