- [Narrator] What is PIO? (upbeat music) RP2040 is a microcontroller
chip designed by Raspberry Pi. Already built into many
microcontroller boards, like Raspberry Pi Pico, RP2040 features standard
peripheral options, like I2C and SPI.
(text popping) As long as low-level devices, such as LCD displays have
I2C or SPI interfaces, you can use standard MicroPython libraries to control them. But what about hardware that doesn't have I2C or SPI protocols? (popping) Or what if your project
requires more I/O channels? That's why RP2040 has a unique ability called programmable
input/output, or PIO for short. (twinkling music)
(bubbling) When programming in MicroPython, you don't have to worry about
everything the code is doing. (keyboard clattering) Take the humble command print Hello world! When writing in MicroPython, we don't have to worry about
where the letters are stored, the format it's sent in or even how long the execution takes. All of that is handled in the background. (gears creaking) When using PIO, you're dealing with code at a much lower level, which means exerting much more
control over these factors. How dow this work? On typical MicroPython devices, controlling non-standard hardware usually requires a process
called bit banging. This is a process whereby
your code rapidly turns pins on and off in a particular
order to transmit data. Think of it as morse code where you send a series of dots and dashes in a particular order to
communicate a message. (beeping) The timing of the dots
and dashes is essential so that the person who
is receiving the message can understand you, just like the timing
and speed of bit banging is essential so that the hardware can understand the instructions. There are downsides to bit banging. The main one being that
the process is slow. (slow beeping) Because the processor
has to concentrate fully on bit banging to get the right timing, it's not able to get
on with any other work, like adding up numbers
or printing out text. This is where PIO comes in. It allows you to carry out
this bit banging process without drawing resources
from the main processor. Along with the main
Cortex-M0+ processing cores, RP2040 has two PIO blocks, each having four state machines. These state machines are really
paired back processing cores that each have a set of nine instructions. This may not seem like many but they actually allow for
a wide range of behavior and location changes for the data. They are written in a special language for the PIO system on RP2040 that can then be embedded
in a MicroPython program on the main processor. Within these state machines are two First In, First
Out, or FIFO pipes, and these are used to
link the state machine to everything else on the chip. (beeping) This allows for the
orderly processing of data and operates as a queue. The first bit of data to go in is the first bit of data to
be pulled by the state machine and so on. To help understand the benefits of PIO, let's take a common example: Addressable LEDs, commonly
known as NeoPixels. NeoPixels are a great fit
for PIO for two reasons. First, the protocol that
controls NeoPixel signals data by using the widths of pulses to represent ones and zeros and for this reason, has to be bit banged. It is also very timing dependent, requiring the processor's
full concentration. Secondly, NeoPixels' brightness levels are not gamma corrected. Here, gamma correction would allow for more gradual changes in brightness but because they are not gamma corrected, the difference between the
individual brightness levels can be quite stark when
used on other processors. But having PIO means that we
can dedicate a state machine to implement the control protocol, which is what we need to communicate with the LEDs and control timing. That then leaves one of our
main processing cores free to control the level of brightness in a way that gives us
more steps of brightness. That then leaves a whole
processing core free to manipulate other data
like display patterns. PIO is a complex process but it gives a much
deeper level of control to do things like retro game emulation, (beeping) control robot arms,
(robot whirring) and even display HD video. (screen clicking) We've only given a very brief overview of the ideas behind PIO but we have also put
together more resources for you to learn more and even write your own PIO programs to control addressable LED lights. (dinging) To find these and much more about RP2040, and Raspberry Pi Pico, visit
rptl.io/rp2040-get-started. (mouse clicking)