3 Easy Projects to Get Acquainted with the Pi Pico

Inside this Article
1. Getting Set Up
2. Project 1: LCD Thermometer
3. Project 2: Pico Piezo Piano
4. Project 3: Mini Breakout Game

The chip shortage is real, y’all. No, I’m not talking about Lays putting fewer potato chips in your bag… that’s a topic for a different day. I’m referring to semiconductors; the little brains etched in silicon that run our lives. If you don’t believe me, try buying a Raspberry Pi right now. Everywhere you look, you’ll see “out of stock”… except for eBay, that is, where you’ll find the $45 pi selling for $150 or more. Anyone who would’ve seen this coming back in 2020 could’ve had a solid pandemic investment strategy.

SparkFun and every other retailer is sold out of Raspberry Pi devices

For those of us that love to tinker and build things, what should we do? It’s a great time for us as makers to explore alternatives and try moving some of our single-board computer projects into the microcontroller realm instead. And you can’t go wrong by playing with the Raspberry Pi Pico.

The Pico is an inexpensive board with loads of power and excellent features. The RP2040 microcontroller is packed with great capabilities compared to other chips with a similar footprint and cost. The Arm Cortex-based processor can operate at 133MHz. It has a number of built-in controllers, including SPI, I2C, UART, and even a USB 1.1 controller. And with 30 general purpose I/O pins that include PWM support, you can wire up a ton of sensors and other devices to this little board.

CapabilityRaspberry Pi PicoArduino Uno R3
MicroprocessorDual-core ARM Cortex-M0+ATmega series, 8-bit
Processor SpeedUp to 133MHz (125MHz default, overclockable to 200+ MHz)16MHz (overclockable, but requires replacing oscillator)
Input Voltage1.8 – 5.5v DC7 – 12v DC (via power barrel) or 5v via USB
Operating Voltage3.3v5v
Onboard Flash Memory2 MB32 KB
I/O Pins26 Digital (3 of these pins can also be used for Analog)14 Digital + 6 Analog
Serial CapabilitiesUART, I2C, SPI (2 of each)UART, I2C, SPI
Price$4 USD$28 USD

And all of this for a whopping $4. No, you read that correctly… $4 USD. If you really want to splurge, you can pick-up a version of the board with built-in WiFi for $6. And the best part of all – they’ve been available to purchase throughout the chip shortage.

SparkFun has several Picos in stock

If it’s so cheap and available, then that must mean it’s difficult to work with, right? No, it’s actually a great board for beginners. In fact, you have several options for programming it. In addition to writing assembly directly, the Pico supports C/C++ and MicroPython. There’s also support for CircuitPython, which is an Adafruit derivative of the MicroPython project. This opens the device to even broader compatibility with different development libraries.

For the rest of this article, my goal is to help you get comfortable with the Pico, by taking you through a couple of easy projects. This is a springboard you can use to start building some of your own ideas. I’m going to use MicroPython, because the barrier to entry with this python-based language is so low.

Getting Set Up

Before jumping into a project, we have a little bit of setup work to do. When you bought your Pico, it probably arrived like this:

The first thing you’ll need to do is solder on some header pins, so you can use it in a breadboard. If your Pico didn’t include headers, you can buy them for a fairly reasonable price. There are vendors on Amazon that will send you a couple dozen rows of headers for just a few dollars, such as these uxcell headers. Or you can purchase a Pico header kit, like the one SparkFun sells for $1.50.

SparkFun’s Pico Header Kit

Soldering on your headers is quite easy, though it’s sometimes difficult to get them on squarely. The technique I use is to put the pins into a breadboard and solder them in place. They say that you shouldn’t solder pin headers to a board while it’s in a breadboard because the heat from the iron can melt and damage the breadboard. However, I think it’s worth sacrificing a cheap breadboard and making it your “soldering breadboard” for this purpose. This ensures that the pin headers are nice and square, while giving you a stable surface to solder onto.

While frowned upon by many, it’s worth sacrificing a breadboard to be used only for soldering headers

If you want to follow along with the projects in this article, you’re also going to need a few components, which I’ve listed in each of the projects in this article. These may be things you already have, but in case you don’t, I’ve provided links to some affordable options on Amazon.

Installing MicroPython on the Pico

After preparing the hardware, the next thing to do is to flash the latest MicroPython build onto the Pico. The folks over at Raspberry Pi have done a great job making this process simple. The easiest way to do this is to hold the BOOTSEL button down on the Pico while plugging it into the USB port on your computer. This will boot the Pico into UF2 (USB Flashing Format) mode.

UF2 technology is quite magical. It works by emulating a standard USB mass storage device. So, when you connect your Pico to your PC in UF2 mode, it actually shows up as a USB drive. From there, you simply need to drag-and-drop the appropriate UF2 file into the ‘drive’, and that’s it. Once the file is detected, the payload will get flashed, and the Pico will automatically reboot.

Here’s a step-by-step for getting MicroPython up and running on the Pico:

  1. Download the latest MicroPython UF2 file from the MicroPython web site.
  2. Hold down the white BOOTSEL button on the Pico, while plugging it into your USB port. The Pico should now appear on your computer as a new USB drive.
  3. Drag the MicroPython UF2 file into the USB drive that the Pico added.

Shortly after this, the Pico’s “USB Drive” will be disconnected, and the Pico will appear to your computer as a new USB serial device.

Software Setup

A lot of the Pico tutorials online will have you use one of a couple of different Python IDEs. The main one that I see is called Thonny – and to be honest, I’m just not a fan. Instead, I prefer to use Microsoft’s excellent multi-platform source code editor, VS Code. So, I’m going to skip Thonny (there are a ton of Pico tutorials online that show you how to use if you want to go that route) and instead get you set up with VS Code.

Step 1 – Install VSCode

To get started, head over to the VS Code web site, and download the installer for your platform. Once downloaded, run through the setup utility, selecting your options along the way.

After installation completes, go ahead and open up VS Code.

The opening dialog of VS Code

Step 2 – Add a MicroPython Extension

VS Code understands some programming languages out of the box, but the power of it is in its extension-based approach. Extensions are used to add support for new programming languages, as well as other bits of functionality in the code editor. You’ll access the Extension Marketplace from the tab that has the boxes:

The Extensions tab in VS Code

Once there, search the marketplace to find the Python extension, and install it with the “Install” button. Then, search for and install the Pico-W-Go extension. Even if you don’t have the “W” version of the Pico (the model with built-in Wi-Fi), you still want to use Pico-W-Go. The extension works fine with both Wi-Fi-enabled and non-Wi-Fi-enabled Picos.

Install both the Python and Pico-W-Go extensions

Finally, close VS Code and re-open it to ensure your newly installed extensions are loaded.

Step 3 – Run a Test Program

Next, you’ll want to build a quick test project to make sure VS Code is correctly configured and that the Pico works as expected. Start by creating a new folder to contain the test project. For example, my test project folder is in c:\code\picotest. Then, open the folder in VS Code by going through the File menu and selecting “Open Folder”.

Open the folder in VS Code

Once you have the correct folder opened, you can then create a new python file in the root of the folder. From the File menu, select “New File”. Then in the drop-down menu that opens, select Python file.

Paste the following code into your Python file. This MicroPython code will simply turn the LED on or off every 1 second:

from machine import Pin
from time import sleep

led = Pin(25, Pin.OUT)

while True:

After you’ve entered the code, save the Python file. I’ve named my file picotest.py, but it doesn’t really matter what the name is.

Before you can run the test program on the Pico, the last thing to do is configure the folder that you opened in VS Code to connect to the Pico via the Pico-W-Go extension. To do this, open the Command Palette (CTRL + Shift + P in Windows) and type “configure project“. You should see an entry in the list that says Pico-W-Go > Configure project. Click on that.

Configure the project for the Pico-W-Go extension

This will result in a new .picowgo file in the root of the folder, along with a couple of additional files in the .vscode folder. You should also see some new options in the bottom-left-hand toolbar of the VS Code editor window:

Pico-W-Go extends the VS Code interface

The “Pico W Disconnected” message on the left indicates that I have not yet connected my Pico to my computer via USB. Once connected, you can click on that message, and Pico-W-Go will attempt to connect to your board. However, I’ve found that I have to manually set the COM port for the Pico before it will connect. To do this, you first need to find out which COM port your Pico is connecting on.

If your Pico isn’t already plugged into your computer, go ahead and connect it via USB. Then, open the Device Manager tool. You can find it by pressing the “windows” key and typing “device manager“.

Once there, look under the “Ports (COM & LPT)” section. You should see at least one device listed there, but there may be several. To determine which one is the Pico, you can unplug the Pico from the USB cable and see which of the devices in the list disappears. Then plug your Pico back in and verify that it reappears. For me, the Pico appeared on my system as COM8, as shown in the following figure.

My Pico came up as COM8 on my system

Now that you know the COM port, go back into VS Code, and open the settings.json file under the .vscode folder. Add a new property at the bottom called picowgo.manualComDevice, and enter your COM port as its value. Make sure to keep COM in capital letters – I noticed that it didn’t work for me when I enter it in lowercase. Here’s my updated settings file as an example:

I added COM port 8 to my Pico-W-Go settings

Save the settings file, and then close and restart VS Code. Upon starting back up, you should see the Pico connect and get the “Pico W Connected” message in the status bar:

The Pico is now connected

Finally, you can run the sample code and validate that the onboard LED flashes on and off every 1 second. First, make sure the picotest.py file is active file in the code editor window. The Pico-W-Go extension will attempt to upload the code to the board that you currently have open.

Next, click the Run button in the status bar, next to the “Pico W Connected” message. It’s important that you use this particular run button and not the native “run” button inside of the VS Code. The latter will try running the python file on your computer instead of the Pico.

Use the Run button in the status bar to execute the code on the Pico

You should see the code get uploaded to your Pico. If everything works as expected, your onboard LED should start blinking. Now that the Pico is ready to use, let’s dive into a couple of projects.

Project 1: LCD Thermometer

In this first project, I’m going to show you how to wire up a 128 x 64 graphic LCD to the Pico. These inexpensive LCDs are great for small projects.

The 128 x 64 graphic LCD I’m using for this project

The Pi Pico has a built-in temperature sensor onboard, which can be accessed through an internal ADC (Analog to Digital Converter). For this project, I’m going to take you through the process of reading this sensor, converting it to a human-readable temperature, and displaying it on the graphic LCD.

If you’d like to follow along with this project, you’re going to need just a couple parts:

  • 128×64 Graphic LCD: You can pick one up for as little as $10 on Amazon, but they’re also available at other maker retailers as well.
  • Some Jumper wires: You can never have too many of these lying around. Jumper wires will sometimes be included in breadboard kits, but you can also purchase them individually. This 120-piece set from Amazon is a decent deal at $7.

Once you’ve gathered your parts, you’ll then want to connect the Pico and LCD to your breadboard. Use the following configuration if you want to run the code for this project without having to change any variables:

Wiring diagram for the LCD Thermometer Project

Notice that the Pico is connected to the positive and negative voltage rails on the breadboard. I’ve done this by connecting pin 40 to the positive rail, and pin 38 to the negative rail. Even though the Pico uses 3.3v logic, I’m powering it with a 5v USB connection. So, the signal coming out of pin 40 is 5v, which is what’s needed to power the 12864 graphic LCD. To that end, I connected the LCD to the 5v rail in two places – at pin 2 and pin 19. Pin 2 (which is labeled VDD) provides the LCD with power.

Pin 19 is used for the LCD’s backlight. By having the backlight power on a separate pin, the brightness can be controlled by adding some resistance, either through a resistor or a potentiometer. When connected to 5v directly, the LCD will get the full brightness.

Aside from the power and ground connections, there are four other pins connected to the display (the blue, green, orange, and yellow wires). The blue wire is connected from Pin 1 on the Pico to the RST pin of the LCD. As the label implies, the RST pin is used to reset the display, which is accomplished by pulling it to ground. Technically, this pin doesn’t need to be connected to the Pico. Instead, you could just wire it directly into the 5v signal, and the LCD will never be reset. By having it connected to the Pico, however, you can choose to reset it in code.

The remaining three wires are all used for serial data communication with the LCD. This is one of the things I like about using these graphic LCDs – the driver chip they use supports both parallel and serial connectivity. If using it in parallel mode, all the pins labelled DB0 – DB7 would need to be connected to the Pico. This is certainly doable on the Pico – it has plenty of I/O pins. For the sake of simplicity, however, I’m using serial, as it only requires three wires.

To send serial data to the LCD, I’m using the Pico’s SPI bus (Serial Peripheral Interface). The Pico has two built-in SPI controllers to support SPI communication natively in the hardware. To understand how this works, I want to take a moment and dive a little deeper into SPI.

Communicating with the LCD over SPI

The SPI standard provides full duplex serial communications between a host controller and any number of peripherals. To make this work, you will normally see four wires – two for data, a clock wire, and a “chip select” wire. Here’s an example of how a SPI host (the Pico in this case) would be wired up to two different SPI-based peripherals (a graphic LCD and an SD Card module).

Wiring multiple SPI peripherals to a single SPI host device

The two data wires (MOSI and MISO) are used for sending and receiving the serial data between the host and the peripherals. Because two separate wires are used, the data sent and received are transferred simultaneously. This makes SPI a great approach when you need speedy serial data transfer.

For this project, however, all the communication is only one way; the Pico only needs to send data to the LCD, it doesn’t need to receive any. If you take another look at the breadboard layout in the earlier diagram, you’ll notice that I only have one data wire connected. That wire connects the Transmit (MOSI) pin of the Pico’s first SPI controller (SPI0) to the D/I pin (Data/Instruction) on the LCD.

📝 The Pico has two separate SPI controllers on board – SPI0 and SPI1. You can use either one to connect your serial peripherals, or both.

Going back to the SPI diagram, notice that the same data wires are shared by each SPI peripheral. Because of this, there’s a separate, dedicated wire between the host and each peripheral called “Chip Select”. This wire indicates which of the peripherals the host is talking to. The host will put a logic LOW on the CS wire of the peripheral the data is intended for. That peripheral notices its CS wire pulled LOW, and that signals it to handle the data on the MOSI line. Every other peripheral will just ignore the data.

In addition to the data wires, SPI also requires a clock signal that’s used for correctly timing the data sent across the data wires. In the breadboard diagram above, the green wire is the clock line. It connects the clock pin on the Pico’s SPI0 controller to the pin labeled E on the LCD. In this case, the ‘E’ is short for Enable, but you may also see this pin labeled as Clock, SCK, or SCLK.

Using the LCD in MicroPython

In an article I wrote a couple of months ago, I walked through how to use 16×2 character LCDs with an Arduino and a Raspberry Pi. In there, I talked about the HD44780 controller, which is commonly used by those particular LCDs. The 12864 graphic LCD uses a different controller, however – the ST7920. The MicroPython code needs to know how to use this controller when sending the data to the LCD. The ST7920 driver expects the data sent to it to look a specific way, and to be preceded by a specific sequence of commands.

Ordinarily, I would find a library that someone wrote and just use that. In this case, however, I had difficulty finding an ST7920 library for MicroPython that worked correctly with the Pi Pico. I did find one for CircuitPython, but it wasn’t backwards compatible with MicroPython due to some of the dependencies in the library. At that point, I decided to modify one of the existing libraries that I did find. So, I forked an ST7920 MicroPython library that was written for an ESP8266 and fixed some of the issues that prevented it from working properly with my Pico projects. If you want to use my updated library for your own Pico project, you can grab it from my GitHub here.

When using this library, you start out by creating an object in Python that represents the LCD:

import st7920

lcd = st7920.Screen(cs=5, rst=0)    # Create the lcd object

In the above code, I passed in two parameters when creating the lcd object – cs, and rst. The cs parameter represents the Pico I/O pin number that I have the chip select wire connected to. Likewise, the rst parameter represents the Pico pin that the LCD’s reset pin is connected to. The library assumes that you’re connecting the LCD to the first SPI controller on the Pico (SPI0). If you choose a different SPI controller, then you’ll need to create a SPI object and pass that in as the first parameter.

The library automatically puts the LCD into graphics mode, so after you create the object, you can just clear the screen and start drawing on it:

lcd.clear()                               # Clear the screen

lcd.line(10, 5, 20, 60)                   # Draw a line
lcd.rect(28, 14, 100, 46)                 # Draw a rectangle
lcd.fill_rect(108, 20, 123, 40)           # Draw a filled rectangle
lcd.circle(64, 30, 10)                    # Draw a circle
lcd.plot(2, 37)                           # Draw a dot
lcd.put_text("What's Ken Making?", 0, 0)  # Write some text

All the drawing is buffered in memory, so you’re not going to see anything right away. When you’re ready to display it all on the screen, call the .redraw() method:

lcd.redraw()    # Update the screen\
The output of the above sample code

Reading the Temperature

Among the many features of the Pico is an onboard temperature sensor that’s built into the RP2040 microprocessor. This sensor is connected internally to the fifth ADC (ADC4). If you’re looking for a super accurate temperature, you’re going to want an external temperature sensor. The built-in sensor is sensitive to variations in the reference voltage, so even slight fluctuations of voltage could cause the sensor to shift its reading by several degrees. Regardless, it’s interesting to interface with this sensor in a project such as this.

When reading data from an analog input, you need some form of a digital representation of that data in order to use it in your code. That’s the job of the ADC (Analog to Digital Converter). The built-in ADC for the Pico provides a 16-bit value that represents the analog voltage on a scale of 0v – 3.3v. In theory, a 0v input should produce a 16-bit value of 0000h, and a 3.3v input should produce FFFFh (or 65535 in decimal).

To read the temperature sensor in MicroPython, you first need to import the ADC library. This library simplifies the process of interacting with the ADCs on various devices. From there, you simply call the ADC function, passing in the ID of the ADC you want to interact with, and referencing the read_u16 method. Here’s what this looks like for the Pico:

from machine import ADC

temp = ADC(4).read_u16()   # Read the temperature from Pico's onboard sensor

The read_u16 method will return the current value of the ADC for that input at that point in time, as a 16-bit unsigned integer (0 – 65535). To turn this into a useful temperature, a little more math is necessary.

# Convert the temperature to C, and then F
volt = temp * 3.3 / 65535
temp_c = 27 - (volt - 0.706)/0.001721
temp_f = (temp_c * 9 / 5) + 32

You might be wondering where I got the temperature conversion values from. That information is found in the RP2040 datasheet. It’s always best to go through the datasheet for any device or component you’re using; there’s always helpful information in there that shows you how to use the various features and functions.

Complete Code Listing

I’ve covered the main parts of the code, so you should now know enough to piece together a MicroPython program that reads the temperature from the on-board sensor and displays it on the LCD.

If you want to see how I did it, you can download the code for all the projects in this article from my GitHub repository here.

To run any of these projects, you’ll need to use the “Open Folder” option in VS Code, and target the folder of the project that you want to run. From there, you can use the same steps from the test program you ran earlier.

Seems about right… my workshop is a tad on the cooler side today

Project 2: Pico Piezo Piano

When I was a kid back in the 80s, I had a small pocket-sized electric piano that came with a little song book. I punched away on those tiny piano keys for minutes on end, surely to rob any nearby adult of their sanity. For this second Pico project, I’m going to resurrect this memory with a single octave piano using tact switches and a piezo buzzer.

To follow along with this project, you’ll need the following additional parts:

  • 8 tact switches: These are just standard momentary buttons that come in pretty much every electronics kit. You’ll use these for the piano keys. If you don’t have any tact switches, they’re very inexpensive; you can grab 120 of them on Amazon for just $6.
  • Piezo buzzer: Piezo buzzers are another item that’s usually included in electronics kits. These simple “speakers” can be used to generate tones of differing frequencies by using pulse width modulation (PWM). Here’s a 3-pack from Amazon for $6.

When you’ve gathered your parts, set up your breadboard like shown in the following diagram.

Interfacing with the Buttons

As you’ll notice in the diagram, there are 8 buttons – each wired into a different I/O pin on the Pico. The other side of each button is connected to the positive side of the breadboard’s bus. There’s a red wire connected from pin 36 on the Pico to that same bus, as well, providing it with 3.3 volts.

The logic here is simple – if the button is pressed, you should see a logical high (3.3v) signal on its corresponding pin on the Pico. Otherwise, it should read a logical low (0v). To achieve this, each button’s pin is configured as an input pin on the Pico, using code that’s similar to the following.

button1 = Pin(3, mode=Pin.IN, pull=Pin.PULL_DOWN)
button2 = Pin(4, mode=Pin.IN, pull=Pin.PULL_DOWN)
# ...

To continuously read the state of the buttons (and take action accordingly), there’s a main program loop that never ends.

while True:
    if button1.value() == True:
        # Do something...
    elif button2.value() == True:
        # Do something else...

Using the Piezo Buzzer

Piezo buzzers generate sound using what’s called the “inverse piezoelectric effect”. Back in the 1800s, it was discovered that certain materials will produce an electric charge when they’re compressed. Likewise, putting an electric charge into those materials will alter their physical state and compress them. This is what’s happening with a piezo buzzer. By using an electric charge, the piezo material is being compressed and decompressed, resulting in a sound wave.

Piezo buzzers are popular in microcontroller projects because they are so easy to use. There are only two wires to connect, and just a single pin is required on the microcontroller to generate and produce varying tones. Making the buzzer sing, however, does require an analog signal. It’s not common for a microcontroller like the Pico to have a DAC (digital to analog converter) on board, so producing an analog output is something that can’t be done natively.

Fortunately, however, there is a way to simulate an analog signal using a technique called PWM (pulse width modulation). This is achieved by altering the ratio of time that the signal coming out of the pin is high versus low (the ‘duty cycle’), along with the number of cycles it performs in 1 second (the ‘frequency’).

In the following sample code, I’m setting the duty cycle to 50% and generating a 262Hz tone. The duty cycle effectively acts as volume control to the buzzer. By setting it to 50%, the material in the buzzer is at its maximum deflection point before it’s reversed, resulting in the highest volume.

# Configure pin #2 on the Pico as an output for the buzzer
buzzer = PWM(Pin(2, mode=Pin.OUT))

# Set the duty cycle on the pin to 50% (16-bit value, so 50% is half of 65535)

# Set the frequency to 262 Hz

Complete Code Listing

By putting together the button and piezo buzzer code, a different tone can be produced for each button that’s pressed. The only thing needed further is a list of which buzzer frequencies produce each of the notes on the piano:

NoteBuzzer Frequency
Middle C262 Hz
D294 Hz
E330 Hz
F349 Hz
G392 Hz
A440 Hz
B494 Hz
C523 Hz

Using this information, you should now be able to produce the code to make your own mini single octave piano. As in first project, I’ve posted my code in this GitHub repository if you want to see how I did it.

The Pico Piano, ready to play a single-octave tune

Project 3: Mini Breakout Game

In this final project, I’ve combined the components used in the first two projects to make a simple breakout-style game for the Pico. There’s nothing fancy here; it’s not really a full game, but more so a playable demo. There’s nothing stopping you from turning this into a complete game, though.

The concept that I’ve built out is simple – this is a single-level clone of the Arkanoid/Breakout game genre. You’ll control the paddle at the bottom of the screen by turning a potentiometer. The change in resistance from the movement of the potentiometer is translated into an on-screen X coordinate by using the Pico’s built-in ADC. As the paddle moves, it’s used to hit the ball that’s bouncing around the screen, which will in turn hit some blocks, making them disappear. Once all the blocks are gone, you’ve won the game.

If you want to follow along, you’ll need the following parts:

  • 128 x 64 Graphic LCD: This is the same LCD used earlier in the thermometer project.
  • 1 Tact Switch: Unlike the piano project, only 1 button is needed for this mini breakout game
  • Piezo Buzzer: The same buzzer used in the piano project. This just generates some basic sounds to go along with the gameplay.
  • 5KΩ Potentiometer: A standard potentiometer. I’m using 5KΩ, but this will work with whatever potentiometer you can muster up

Once you’ve gathered the parts, lay them out on a breadboard, like in the following diagram:

Using the Potentiometer as an Input Device

The paddle across the screen with a standard potentiometer. The outer two legs are wired into ground and 3.3v. The middle leg is connected to one of the Pico’s I/O pins, which is configured as an input. When the potentiometer is turned, the voltage being sunk into the I/O pin will vary between 0 – 3.3v. The ADC library reads this as a 16-bit value, and the code then uses some simple math to calculate the position of the on-screen paddle along the x-axis.

To read the value of the potentiometer with MicroPython, the object first needs to be created by calling the read_u16() method on the ADC library:

pot_val = ADC(0).read_u16()

As you can see, I passed a 0 into the ADC object. This parameter is the ADC number that you’re reading the input from, which for me is ADC0. As I mentioned earlier, the Pico has five ADCs, and three of them are exposed through header pins. Notice in the following figure that ADC0, ADC1, and ADC2 are exposed through pins 31, 32, and 34. You may recall from the first project that the temperature sensor was on ADC4. ADC3 is on the RP2040 chip as GPIO29, but not available on the Pico board through the pin headers.

Pinout on the Pico

Using the read_u16() method, the value of the potentiometer is read in as a 16-bit integer. From there, it needs to be converted to a position on the x-axis for the game paddle. I have the screen in a horizontal layout, so the paddle can move across the bottom row of pixels from x = 0 through x = 127 - size_of_paddle. Here’s what this code looks like:

# Read the potentiometer and update the paddle position
pot_val = ADC(0).read_u16()
x_pos = pot_val // div

# Draw the paddle
lcd.line(x_pos, y_pos, x_pos + paddle_w, y_pos)

Complete Code Listing

The remaining components (the LCD, buzzer, and button) work the same way as they do in the first two projects. The rest of the code is focused on drawing the bricks, the ball, and the other mechanics of playing the game. It’s actually quite simple. Download the code from my GitHub repository and try it out!


This article is just scratching the surface of what you can do with this $4 microcontroller. My intent here was to get you started and to get some of your creative juices flowing. If you were inspired to dig that Pico out of your box of parts and try building something, please post a comment and share your project!

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s