Adding Libraries

Once you've finished setting up your PyPortal with CircuitPython, you can add these libraries to the lib folder:

  • adafruit_bitmap_font
  • adafruit_bus_device
  • adafruit_display_shapes
  • adafruit_display_text
  • adafruit_esp32spi
  • adafruit_imageload
  • adafruit_io
  • adafruit_adt7410.mpy
  • adafruit_button.mpy
  • adafruit_pyportal.mpy
  • adafruit_requests.mpy
  • adafruit_sdcard.mpy
  • adafruit_touchscreen.mpy
  • neopixel.mpy

Then, you can click on the Download: Project Zip link above the code to download the code file, audio files and bitmap file.


Click on "Copy Code" and then paste it into the Mu editor to save to your PyPortal as or copy the code file from the Project Zip folder to the PyPortal's CIRCUITPY drive.

You will also need the code file from the Project Zip folder since it is required for the PyPortal CircuitPython library.

# SPDX-FileCopyrightText: 2020 Liz Clark for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
from adafruit_button import Button
from adafruit_pyportal import PyPortal

pyportal = PyPortal(default_bg="/stock-pyportal.bmp")

lowE = "/sounds/lowE.wav"
A = "/sounds/A.wav"
D = "/sounds/D.wav"
G = "/sounds/G.wav"
B = "/sounds/B.wav"
highE = "/sounds/highE.wav"

notes = [lowE, A, D, G, B, highE]

pegs = [
    {'label': "lowE", 'pos': (53, 0), 'size': (65, 90)},
    {'label': "A", 'pos': (124, 0), 'size': (65, 90)},
    {'label': "D", 'pos': (194, 0), 'size': (65, 90)},
    {'label': "G", 'pos': (194, 150), 'size': (65, 90)},
    {'label': "B", 'pos': (124, 150), 'size': (65, 90)},
    {'label': "highE", 'pos': (53, 150), 'size': (65, 90)}

buttons = []
for peg in pegs:
    button = Button(x=peg['pos'][0], y=peg['pos'][1],
                    width=peg['size'][0], height=peg['size'][1],
                    fill_color=None, outline_color=0x5C3C15,

note_select = None

while True:
    touch = pyportal.touchscreen.touch_point
    if not touch and note_select:
        note_select = False
    if touch:
        for i in range(6):
            tuning = notes[i]
            button = buttons[i]
            if button.contains(touch) and not note_select:
                note_select = True
                for z in range(3):

Audio Files and Bitmap Graphic

In addition to the lib folder, for this project you'll also have a sounds folder. The sounds folder contains the six audio files that are used to tune your guitar using the PyPortal. Each audio file is a quick sample of each string on a guitar in standard tuning (E - A - D - G - B - E).

  • A.wav
  • B.wav
  • D.wav
  • G.wav
  • highE.wav
  • lowE.wav

There is also a bitmap image for the PyPortal's display that depicts a guitar's headstock. This image file, called stock-pyportal.bmp, will also be stored on the PyPortal. 

Copy the sounds folder and the stock-pyportal.bmp bitmap image file from the Project Zip folder to the PyPortal's CIRCUITPY drive.

Your PyPortal CIRCUITPY drive should look like this after you load the libraries, audio files, bitmap and code files below:

This guide was first published on Jun 09, 2020. It was last updated on Jun 09, 2020.

This page (Coding the PyPortal Guitar Tuner) was last updated on May 13, 2022.

Text editor powered by tinymce.