Adafruit PyPortal US User manual

PyPortal US Election Calendar
Created by Álvaro Figueroa
Last updated on 2021-03-17 01:18:28 PM EDT
2 3
4
8
8 9
10
11 12
12
13 14 14
15 16
16 16 16 19 19
19 19 21 21
21 24 25
26
27 29 31 33 35 37
39 40
40 40 40
Guide Contents
Guide Contents Overview
Parts
Install CircuitPython
Set up CircuitPython Quick Start! PyPortal Default Files
CircuitPython Libraries
Installing the CircuitPython Library Bundle Example Files
Copying Libraries to Your Board
Example: ImportError Due to Missing Library Library Install on Non-Express Boards Updating CircuitPython Libraries/Examples
PyPortal CircuitPython Setup Code PyPortal with CircuitPython
Location Adafruit IO Time Server CircuitPython Code How It Works PyPortal Constructor
Background
Time API Query and JSON Fetch JSON Traversal
Font
Graphics Text Position Text Color
Build The PyPortal Stand
Prep Sandwich Legs Add Long Screws Screw It All Together Bonus! Penny Roll Weight
Laser Cutter Files for PyPortal Stand Troubleshooting
Problems with the WiFi Problems setting up the county/state PyPortal library on other devices
© Adafruit Industries https://learn.adafruit.com/pyportal-electioncal-us Page 2 of 41
Overview
Voting is important to make the voice of the people as loud as possible.
But, it is also very complicated to remember all of the involved dates, so much so that you are almost certain to miss a registration date.
To try to make it easier for us with forgetful minds, a community driven effort has been gathering all of the hard to find information and dates, and compiling it on the Electioncal Website (https://adafru.it/M7F).
It's designed to share this information as an iCalendar url, which is super easy to add to your favorite desktop software or to your mobile phone.
© Adafruit Industries https://learn.adafruit.com/pyportal-electioncal-us Page 3 of 41
But sometimes we need a little visual reminder, and a beautiful way to do it, is with a PyPortal.
We are going to use CircuitPython to connect to the Internet, download and process the data, and then display it in a nice and clean way, so we can always keep the pulse on our Election Calendar.
Parts
© Adafruit Industries https://learn.adafruit.com/pyportal-electioncal-us Page 4 of 41
Adafruit PyPortal - CircuitPython Powered Internet Display
PyPortal, our easy-to-use IoT device that allows you to create all the things for the “Internet of Things” in minutes. Make custom touch screen interface... Out of Stock
Out of
Stock
© Adafruit Industries https://learn.adafruit.com/pyportal-electioncal-us Page 5 of 41
Adafruit PyPortal Desktop Stand Enclosure Kit
PyPortal is our easy-to-use IoT device that allows you to create all the things for the “Internet of Things” in minutes. Create little pocket... $9.95 In Stock
Fully Reversible Pink/Purple USB A to micro B Cable - 1m long
This cable is not only super-fashionable, with a woven pink and purple Blinka-like pattern, it's also fully reversible! That's right, you will save seconds a day by... Out of Stock
Add to Cart
Out of
Stock
© Adafruit Industries https://learn.adafruit.com/pyportal-electioncal-us Page 6 of 41
5V 1A (1000mA) USB port power supply - UL Listed
Need a USB jack for charging or powering a project, but don't want to lug around a computer? This switching supply gives a clean regulated output at up to 1000mA! 110 or 240 input,... $5.95 In Stock
Add to Cart
© Adafruit Industries https://learn.adafruit.com/pyportal-electioncal-us Page 7 of 41
Install CircuitPython
CircuitPython (https://adafru.it/tB7) is a derivative of MicroPython (https://adafru.it/BeZ) designed to
simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the CIRCUITPY "flash" drive to iterate.
The following instructions will show you how to install CircuitPython. If you've already installed CircuitPython but are looking to update it or reinstall it, the same steps work for that as well!
Set up CircuitPython Quick Start!
Follow this quick step-by-step for super-fast Python power :)
https://adafru.it/Egk
https://adafru.it/HFd
Click the link above to download the latest version of
CircuitPython for the PyPortal.
Download and save it to your desktop (or wherever is handy).
Plug your PyPortal into your computer using a known-good USB cable.
A lot of people end up using charge-only USB cables and it
is very frustrating! So make sure you have a USB cable you
know is good for data sync.
Double-click the Reset button on the top in the middle (magenta arrow) on your board, and you will see the NeoPixel RGB LED (green arrow) turn green. If it turns red, check the USB cable, try another USB port, etc. Note: The little red LED next to the USB connector will pulse red. That's ok!
If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!
https://adafru.it/Egk
https://adafru.it/HFd
© Adafruit Industries https://learn.adafruit.com/pyportal-electioncal-us Page 8 of 41
You will see a new disk drive appear called PORTALBOOT.
Drag the adafruit-circuitpython-pyportal-<whatever>.uf2 file to PORTALBOOT.
The LED will flash. Then, the PORTALBOOT drive will disappear and a new disk drive called CIRCUITPY will appear.
If you haven't added any code to your board, the only file that will be present is boot_out.txt. This is absolutely normal! It's time for you to add your code.py and get started!
That's it, you're done! :)
PyPortal Default Files
Click below to download a zip of the files that shipped on the PyPortal or PyPortal Pynt.
https://adafru.it/Env
https://adafru.it/HFf
https://adafru.it/Env
https://adafru.it/HFf
© Adafruit Industries https://learn.adafruit.com/pyportal-electioncal-us Page 9 of 41
CircuitPython Libraries
As we continue to develop CircuitPython and create new releases, we will stop supporting older releases. Visit https://circuitpython.org/downloads to download the latest version of CircuitPython for your board. You must download the CircuitPython Library Bundle that matches your version of CircuitPython. Please update CircuitPython and then visit https://circuitpython.org/libraries to download the latest Library Bundle.
Each CircuitPython program you run needs to have a lot of information to work. The reason CircuitPython is so simple to use is that most of that information is stored in other files and works in the background. These files are called
libraries
. Some of them are built into CircuitPython. Others are stored on your CIRCUITPY drive in a folder called lib. Part of what makes CircuitPython so awesome is its ability to store code separately from the firmware itself. Storing code separately from the firmware makes it easier to update both the code you write and the libraries you depend.
Your board may ship with a lib folder already, it's in the base directory of the drive. If not, simply create the folder yourself. When you first install CircuitPython, an empty lib directory will be created for you.
CircuitPython libraries work in the same way as regular Python modules so the Python
docs (https://adafru.it/rar) are a great reference for how it all should work. In Python terms, we can place
our library files in the lib directory because its part of the Python path by default.
One downside of this approach of separate libraries is that they are not built in. To use them, one needs to copy them to the CIRCUITPY drive before they can be used. Fortunately, we provide a bundle full of our libraries.
Our bundle and releases also feature optimized versions of the libraries with the .mpy file extension. These files take less space on the drive and have a smaller memory footprint as they are loaded.
© Adafruit Industries https://learn.adafruit.com/pyportal-electioncal-us Page 10 of 41
Installing the CircuitPython Library Bundle
We're constantly updating and improving our libraries, so we don't (at this time) ship our CircuitPython boards with the full library bundle. Instead, you can find example code in the guides for your board that depends on external libraries. Some of these libraries may be available from us at Adafruit, some may be written by community members!
Either way, as you start to explore CircuitPython, you'll want to know how to get libraries on board.
You can grab the latest Adafruit CircuitPython Bundle release by clicking the button below.
Note: Match up the bundle version with the version of CircuitPython you are running - 3.x library for running any version of CircuitPython 3, 4.x for running any version of CircuitPython 4, etc. If you mix libraries with major CircuitPython versions, you will most likely get errors due to changes in library interfaces possible during major version changes.
https://adafru.it/ENC
If you need another version, you can also visit the bundle release page (https://adafru.it/Ayy) which will let you select exactly what version you're looking for, as well as information about changes.
Either way, download the version that matches your CircuitPython firmware version. If you don't know the version, look at the initial prompt in the CircuitPython REPL, which reports the version. For example, if you're running v4.0.1, download the 4.x library bundle. There's also a py bundle which contains the uncompressed python files, you probably
don't
want that unless you are doing advanced work on
libraries.
After downloading the zip, extract its contents. This is usually done by double clicking on the zip. On Mac OSX, it places the file in the same directory as the zip.
Open the bundle folder. Inside you'll find two information files, and two folders. One folder is the lib bundle, and the other folder is the examples bundle.
https://adafru.it/ENC
© Adafruit Industries https://learn.adafruit.com/pyportal-electioncal-us Page 11 of 41
Now open the lib folder. When you open the folder, you'll see a large number of mpy files and folders
Example Files
All example files from each library are now included in the bundles, as well as an examples-only bundle. These are included for two main reasons:
Allow for quick testing of devices. Provide an example base of code, that is easily built upon for individualized purposes.
Copying Libraries to Your Board
First you'll want to create a lib folder on your CIRCUITPY drive. Open the drive, right click, choose the option to create a new folder, and call it lib. Then, open the lib folder you extracted from the downloaded zip. Inside you'll find a number of folders and .mpy files. Find the library you'd like to use, and copy it to the lib folder on CIRCUITPY.
This also applies to example files. They are only supplied as raw .py files, so they may need to be converted to .mpy using the mpy-cross utility if you encounter MemoryErrors . This is discussed in the
CircuitPython Essentials Guide (https://adafru.it/CTw). Usage is the same as described above in the
© Adafruit Industries https://learn.adafruit.com/pyportal-electioncal-us Page 12 of 41
Express Boards section. Note: If you do not place examples in a separate folder, you would remove the examples from the import statement.
If a library has multiple .mpy files contained in a folder, be sure to copy the entire folder to CIRCUITPY/lib.
Example: ImportError Due to Missing Library
If you choose to load libraries as you need them, you may write up code that tries to use a library you haven't yet loaded. We're going to demonstrate what happens when you try to utilise a library that you don't have loaded on your board, and cover the steps required to resolve the issue.
This demonstration will only return an error if you do not have the required library loaded into the lib folder on your CIRCUITPY drive.
Let's use a modified version of the blinky example.
import board import time import simpleio
led = simpleio.DigitalOut(board.D13)
while True: led.value = True time.sleep(0.5) led.value = False time.sleep(0.5)
Save this file. Nothing happens to your board. Let's check the serial console to see what's going on.
We have an ImportError . It says there is no module named 'simpleio' . That's the one we just included in our code!
Click the link above to download the correct bundle. Extract the lib folder from the downloaded bundle file. Scroll down to find simpleio.mpy. This is the library file we're looking for! Follow the steps above to load an individual library file.
The LED starts blinking again! Let's check the serial console.
© Adafruit Industries https://learn.adafruit.com/pyportal-electioncal-us Page 13 of 41
Loading...
+ 28 hidden pages