Overview
Since the PyPortal came out, there have been many examples written which take advantage of the CircuitPython displayio graphics system. We have been working on writing a version of displayio that runs on Blinka, the CircuitPython compatibility layer for Python 3 on single board computers. With Blinka, you can run your favorite CircuitPython displayio applications and games on boards such as the Raspberry Pi or even the FT232H.
To make things even easier, we also wrote a version of the PyPortal library that runs on Blinka to make it even easier to get up and running. The Raspberry Pi is already connected to the internet, so we decided to take advantage of this and removed much of the code that handled managing the connections and replaced it with the Linux equivalents.
The Blinka PyPortal library is a port of the original PyPortal library that is intended to be run in CPython. It leverages the Blinka Displayio library, which is a port of the original CircuitPython displayio library and is built on top of Adafruit Blinka and the Python Imaging Library. The idea behind the PyPortal library is to be able to run many of the examples that are currently available for the PyPortal with minimal changes.
Parts
To run the examples, you'll need a Raspberry Pi or FT232H. If you are going the Raspberry Pi route, a Raspberry Pi 4 is preferred due to its processing speed:
For the Raspberry Pi, you will also need a PiTFT such as the 3.2" TFT:
If you would like to play sound, one of the easiest ways is to connect an amplified speaker to the Raspberry Pi such as the Monoprice 5-watt amp:
If you would prefer to run it directly from your computer, you could use an FT232H:
For the FT232H, you will need a Breakout TFT such as the 2.8" TFT Breakout:
Page last edited March 08, 2024
Raspberry Pi Setup
Setting up the Raspberry Pi is easy. Since the PiTFT comes preassembled, all you need to do is place it onto the GPIO pins.
Since there are dozens of Linux computers/boards you can use we will show wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported.
Connect the display as shown below to your Raspberry Pi.
If you are using a Raspberry Pi 4 and have some active cooling on it such as the Pimoroni Fan Shim or Heatsink Case, you may want to attach a 40-pin stacking header so that the pins on the PiTFT don't interfere:
Software Setup
You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require enabling SPI on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!
Install the PyPortal Library
You'll next want to install the Blinka PyPortal library. Installing this library will also install all of the dependencies, so it's really easy to setup. Just run the following command:
pip3 install adafruit-blinka-pyportal
Using a 3.5" PiTFT
If you want to use a 3.5" PiTFT, then you will need to do a little extra work. First, you'll need to install the HX8357 library. You can do that by using the following comand:
pip3 install adafruit-circuitpython-hx8357
Next you'll need to initialize the display at the beginning of the example and pass it into the initializer. We'll go over that on the Running Examples page.
Connecting More Sensors
Most of the PiTFT hats either have a 40-pin or a 26-pin connector on the back that allows you to connect more sensors. We also conveniently have both 40-pin and 26-pin versions of the Pi cobbler that will connect to the back of the panel so that you can hook up more sensors.
Page last edited March 08, 2024
FT232H Setup
Using the FT232H for running the PyPortal examples will require 3 main components. You will need the FT232H itself and a TFT display such as the 2.8" ILI9341 touchscreen breakout.
The first thing you will need to do is be sure the solderable jumpers on the back of the TFT breakout is setup to use SPI. By default, all of these breakouts are configured to use 8-bit data mode and some soldering will be required.
- For the 2.4" TFT, you will want to visit the 2.4" TFT SPI Wiring and Test page.
- For the 2.8" and 3.2" TFT, you will want to visit the 2.8" and 3.2" TFT SPI Wiring and Test page.
- For the 3.5" TFT, you will want to visit the 3.5" TFT SPI Wiring and Test page.
- 5V on the FT232H connects to Vin on the TFT
- GND on the FT232H connects to GND on the TFT
- D0 on the FT232H connects to CLK on the TFT
- D1 on the FT232H connects to MOSI on the TFT
- D4 on the FT232H connects to CS on the TFT
- D5 on the FT232H connects to D/C on the TFT
- D6 on the FT232H connects to RST on the TFT
Software Setup
To run the Examples off your Mac, Windows, or Linux computer, first you'll need to be sure that you have your computer set up to run Blinka. You can find more information on getting your computer set up in our CircuitPython Libraries on any Computer with FT232H guide.
Additionally, you will also need PIL and NumPy. Since the installation procedure can vary from system to system, we linked to each package's installation instructions.
Pillow/PIL
This is the Python Imaging Library which is used to render the plots onto bitmaps that can be sent to the TFT display. Install instructions are here:
NumPy
This is the Numerical Python library and is an open source Python library that’s the universal standard for working with numerical data in Python, and it’s at the core of the scientific Python and PyData ecosystems. This is used to quickly process graphical data so that it can be sent to the display efficiently.
Page last edited March 08, 2024
Running Examples
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.
settings.toml File
To run the examples, you will need to setup a settings.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:
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,
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:
Page last edited March 08, 2024