March 24, 2019

The PyPortal Lands

The PyPortal Lands

So Adafruit's latest is the PyPortal, an Atmel-SAMD51-powered, Python-running board with a touchable LCD display, an ESP32 for WiFi and BT, and a form factor which makes it easy to mount. I got mine with the Adabox subscription and it came with an acrylic enclosure and a tube you could fill with pennies (UK pennies work) to weight down the enclosure which has a curve in the back where it can sit.

It runs CircuitPython, Adafruit's fork of MicroPython built for ease of development and deployment across Adafruits various boards. And with the PyPortal, that includes a PyPortal class, used in lots of their examples, which makes the business of creating an internet connected dashboard a breeze... or at least a reasonable gust. Here's some code I hacked up from another example to turn it into an Petition monitor for the Revoke Article 50 petition...

UPDATE 25/3/19: There's now a Github repository codepope/RevokeArticle50 with the essential assets for this app in it.

This example goes and gets the number of signers to the Petition to revoke article 50 in the UK

import time
import board
from adafruit_pyportal import PyPortal

# Get wifi details and more from a file
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in, please add them there!")

# pylint: disable=line-too-long
DATA_LOCATION1 = [ "signature_count" ]

# the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]
pyportal = PyPortal(url=DATA_SOURCE,
                    text_position=(50, 80),
                    caption_position=(50, 180),

while True:
        sigs = pyportal.fetch()
        sigs = int(sigs)
        print("Signatures:", sigs)
    except RuntimeError as e:
        print("Some error occured, retrying! -", e)


That PyPortal class is taking URLs for JSON data, status LED, backdrops (GIMP recommended to get that clean BMP feel), fonts (FontForge for making BDFs but oh such hard work and well crashy on the Mac), captions and positions. You then get to orchestrate it retrieving the data and thats pretty much it.