Before running these examples, be sure your Single Board Computer is connected to the internet, since a connection is required.

The included examples are all ports from previous projects for the PyPortal with associated learn guides. To use each of the examples, you will want to either go to the original Learn Guide click Download Project Zip or go to the original Project Files on GitHub.

While there are other examples besides the ones listed on this page, some of them make use of the some of the onboard sensors such as the light or temperature sensor, which is not present by default on the Pi. However, if you have a PiTFT with additional pins on the back, you could use a 26-pin or 40-pin Pi-Cobbler and connect additional sensors too.

If you are using an FT232H, you could may wire up some additional sensors to this board on some unused GPIO pins, though since the I2C pins are shared with the SPI pins, you won't be able to run and use I2C devices at the same time.

The following examples have been modified to work with the Raspberry Pi, which has a Linux Operating System and no built-in NeoPixel.

secrets.toml File

To run the examples, you will need to setup a secrets.toml file in your script folder. You can copy it below if you don't already have one. Note that unlike the original PyPortal secrets file, you don't need to add your WiFi connection information because your board should already be on the internet.

# SPDX-FileCopyrightText: 2023 Adafruit Industries
#
# SPDX-License-Identifier: MIT

# This is where you store the credentials necessary for your code.
# The associated demo only requires WiFi, but you can include any
# credentials here, such as Adafruit IO username and key, etc.
CIRCUITPY_WIFI_SSID = "your-wifi-ssid"
CIRCUITPY_WIFI_PASSWORD = "your-wifi-password"
GITHUB_TOKEN = "fawfj23rakjnfawiefa"
HACKADAY_TOKEN = "h4xx0rs3kret"
OPENWEATHER_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxx"

PyPortal Startup Image and Sound

The PyPortal library looks to see if the PyPortal Startup Image and Wav file are in the folder that you are running the example from and plays them if they are there. You can download those here if you don't already have a copy. Be sure they are named pyportal_startup.bmp and pyportal_startup.wav.

When you start up each example, you should see the startup image displayed briefly and a hear sound played:

If you are using the 3.5" PiTFT, keep in mind that the display's resolution is higher than what examples were written for, so things may appear a little off.

Script changes for the 3.5" HX8357 TFT Display

To use the HX8357 display, we'll need to declare the display object in the example and pass it in since there's no way to detect which display is being used. In fact, it's likely that without modifying the code, the example would still run in a portion of the display with the unused part appearing as random noise.

The first thing you will need to add is some code to setup the display.

# Setup the Display
import board
import displayio
import adafruit_hx8357
displayio.release_displays()
spi = board.SPI()
tft_cs = board.CE0
tft_dc = board.D25

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = adafruit_hx8357.HX8357(display_bus, width=480, height=320, backlight_pin=board.D18)

The other thing you will need to change is to pass in the already initialized display as an additional parameter to the PyPortal Initialization Function. So we will change this line:

pyportal = PyPortal(

to this:

pyportal = PyPortal(
    display=display,
If you see "AttributeError: module 'board' has no attribute 'NEOPIXEL'", make sure you are using the examples below rather than the original examples from the guides.

NASA Image Example

The next example is the Image of the Day from NASA. This will get the current NASA image URL, download the image, resize it, and display it on the screen. You can get the resources for this example from the original PyPortal NASA Example or from the original Learn Guide.

Temporarily unable to load content:

Upload the secrets file, background image, font folder and the above example code to your Pi. If you are using a 3.5" display, be sure to make the necessary changes as well. After that, run the code:

python3 adafruit_blinka_pyportal_nasa.py

You should see the following background appear first:

Following that, it should download and display an image similar to this:

Quote Example

The next example is the Adafruit Quote display. This will go out and fetch a random quote from the Adafruit website and display it on the screen. You can get the resources for this example from the original PyPortal Quote Example or from the original Learn Guide.

Temporarily unable to load content:

Upload the secrets file, background image, font folder and the above example code to your Pi. If you are using a 3.5" display, be sure to make the necessary changes as well. After that, run the code:

python3 adafruit_blinka_pyportal_quote.py

You should see something similar to the following:

Discord Counter Example

The next example is the Adafruit Discord Online Counter display. This will go out and find the number of people currently online using the Adafruit Discord Server and display it on the screen. You can get the resources for this example from the original PyPortal Discord Example or from the original Learn Guide.

Temporarily unable to load content:

Upload the secrets file, background image, font folder and the above example code to your Pi. If you are using a 3.5" display, be sure to make the necessary changes as well. After that, run the code:

python3 adafruit_blinka_pyportal_discord.py

You should see something similar to the following:

Open Weather Example

The last example is the Open Weather display. This will go out and find the weather conditions for the location that you have set and display it on the screen. This example is a little bit more complicated than the other examples. You can get the resources for this example from the original PyPortal Open Weather Example or from the original Learn Guide.

For this example, you will need to go to this link and register for a free account. Once registered, you'll get an email containing your API key, also known as the "openweather token". Edit your secrets.py file and add the token into there.

Look for this line and be sure to change the LOCATION variable to your location:

# Use cityname, country code where countrycode is ISO3166 format.
# E.g. "New York, US" or "London, GB"
LOCATION = "Manhattan, US"

For this example, you will need 2 files. The main file:

Temporarily unable to load content:

And the Graphics handling file:

Temporarily unable to load content:

Upload the updated secrets file, background image, font folder, icons folder and the above example files to your Pi. If you are using a 3.5" display, be sure to make the necessary changes as well. After that, run the code:

python3 adafruit_blinka_pyportal_openweather.py

You should see something similar to the following:

This guide was first published on Jul 09, 2020. It was last updated on Jul 15, 2024.

This page (Running Examples) was last updated on Jul 14, 2024.

Text editor powered by tinymce.