Testing the Adafruit PyPortal touchscreen

Display Deluxe

© Lead Image © donatos1205, 123RF.com

© Lead Image © donatos1205, 123RF.com

Article from Issue 237/2020

Unlike other displays for the Raspberry Pi, Adafruit's PyPortal touchscreen provides an autonomous environment, including a microprocessor, sound output, and a WiFi connection.

The Raspberry Pi has a hard time with small displays because support from Raspbian is surprisingly poor. Creating and implementing suitable interfaces is difficult with a dearth of off-the-shelf programs for controlling small displays. I'm quietly confident that the PyPortal intelligent touchscreen by Adafruit is a better solution.

PyPortal (Figure 1) is a small 3.2-inch networkable resistive touch display with an integrated microprocessor [1]. At $55 (EUR59), it is not exactly cheap, but considering its components, the price seems reasonable. A correspondingly sized 3.2-inch display plus a Pi Zero W with an SD card, at about the same price, will serve as a comparison with the PyPortal configuration.

Figure 1: The front of the intelligent PyPortal display. The resistive touchscreen requires a certain amount of pressure before it reacts.

PyPortal in Detail

The screen takes up almost all of the real estate on the front, with a mounting frame and a brightness sensor on the right side. Adafruit has cut costs on the display itself. The resolution of 320x240 pixels is more suitable for 2.8-inch devices. Resistive touch technology is also a way of saving cash, but it does mean you need a stable mounting – just touching the screen is not enough, you actually have to press it.

The PyPortal is now available in two other sizes. The PyPortal Pynt for $45 reduces the screen diameter to 2.4 inches with the same number of pixels; the 3.5-inch PyPortal Titano offers a resolution of 320x480 pixels, plus a USB C power connection for $60.

The back of the display (Figure 2) accommodates, among other things, an ATSAMD51J20 CPU by Atmel. It is supported by the far larger ESP32 WiFi coprocessor by Espressif. These popular modules provide WiFi at a low cost. The ESP32 takes on the computationally intensive TLS/SSL encryption protocol, thus reducing the burden on the Atmel CPU. Its Cortex-M4 processor runs at 120MHz and has 1MB of flash memory for program code and 256KB of RAM. Additionally, 8MB of flash memory is available for other resources, such as images or sounds.

Figure 2: The back of the PyPortal features the Atmel CPU and the ESP32 chip, which handles WiFi and the computationally intensive TLS/SSL encryption protocol.

In addition to the previously mentioned light sensor, the PyPortal's features include a reset button, a temperature sensor, a miniature speaker with an amplifier, a microSD slot, a neopixel LED, an I2C port, and two ports for additional sensors. The last three ports also provide power and ground.

Mostly because of the extensive equipment, it's not surprising that the intelligent display has been very well received in the maker scene. Adafruit also designs the hardware, so you can adapt it to your own ideas. For example, if you need a better loudspeaker, just interrupt the defined conducting path and connect your own.

Besides the PyPortal, Adafruit also sells a matching minimalist display stand. However, both Adafruit and the community have already designed various cases that are available on popular 3D printing portals. You will find the stand from Figure 1, for example, on Thingiverse [2].

Getting Started

To put the display into operation, all you need to do is connect it to a 5V power supply with a micro-USB plug. CircuitPython runs on the Cortex-M4 processor; Adafruit has implemented a small example program, but it throws errors because the WiFi chip fails to connect to the home network without an SSID and password. Before you adapt the program, though, you will want to update the firmware.

Both firmware updates and program changes are handled over the USB cable, which you connect to a PC instead of a power supply for this purpose. Choose a cable that is not too long and of good quality; in particular, do not use a mere powercable. If you press the reset button once, the PyPortal reboots; if you press it twice, it switches to firmware update mode.

In both operating modes, the display provides its program memory as a drive. In normal operation, it goes by the name CIRCUITPY; in update mode the name is PORTALBOOT. On Linux, the device files known from USB storage media appear with a small difference: In operating mode, PyPortal announces itself as a partitioned mass storage device with the device name /dev/sd<X>1; in update mode it claims to be an unpartitioned stick named /dev/sd<X>.

On Linux, first check to see whether the drive has been mounted automatically. If this is the case, eject it and remount it with the command:

$ sudo mount -o sync /dev/sd<X> /mnt

The sync option ensures that all files are immediately written to the PyPortal. To install the firmware update, first download the current version, and then simply copy the file with the .uf2 suffix to the drive. The board then reboots, the PORTALBOOT drive disappears, and the CIRCUITPY drive appears.

Details of the update and, more specifically, links to the current firmware and how to work with CircuitPython can be found in the Adafruit [3] documentation. At the end of the day, working with the PyPortal is no different from working with other CircuitPython boards.

Figure 3 shows the layout of the files in operation mode. The root directory contains the code.py file, which contains the Python code of the main program that runs in an infinite loop, and the lib/ subdirectory contains libraries. Other files and directories depend on the application.

Figure 3: When connected to a Linux computer, PyPortal's memory appears to be a normal drive.

Weather Geek

Adafruit's sample program, as supplied with the product, retrieves a saying from a web server at regular intervals and shows it on the display. To log in to your WiFi network, the program needs the access credentials, which you enter in the secrets.py file. On closer inspection, the program turns out not to be very instructive, because it hides all the magic in the PyPortal class. This prompted me to develop a project of my own to illustrate how to display images and text.

The PyPortal is best suited for receiving and visualizing data. The program will query the weather from wttr.in. This slightly different kind of weather portal provides an ad-free weather report on the command line and is based on the Go program wego; fans of ASCII art will definitely get their money's worth. Figure 4 shows a deluxe version of its output. In a terminal window, you can call up this weather forecast for your location by typing curl wttr.in. Typing curl wttr.in/:help shows the syntax.

Figure 4: The wttr.in project outputs the required weather data in ASCII format on the terminal.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Adafruit IO API

    The Adafruit IO API offers a convenient means for network-ready sensors and other components.

  • CircuitPython

    The CircuitPython run-time environment runs on almost all microcomputers and microcontrollers, making it perfect for cross-platform programming.

  • Six Monospaced Free-Licensed Fonts
  • Gnome Fonts

    Linux’s text display still suffers from legacy issues, but it is well on the way to

    recovering. This article explains how Fontconfig, X, and Gnome work together for

    a brighter future.

  • Gravit Designer

    Edit vector graphics with Gravit Designer and save the results in the SVG, PNG, and JPEG formats.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95