Adafruit NASA User Manual

PyPortal NASA Image of the Day Viewer
Created by John Park
Last updated on 2021-03-17 01:17:44 PM EDT
2 3
3
6
6 7
8 8 9 9 9
13
15 16 17
18 21
21 21 22 22 22 22 23 24
Guide Contents
Guide Contents Overview
Parts
Install CircuitPython
Set up CircuitPython Quick Start! PyPortal Default Files
PyPortal CircuitPython Setup Adafruit CircuitPython Bundle Internet Connect! What's a secrets file? Connect to WiFi Requests
HTTP GET with Requests HTTP POST with Requests Advanced Requests Usage
WiFi Manager Code PyPortal NASA Image Viewer
NASA Open API Key Adafruit IO Time Server Add CircuitPython Code and Assets Editing the Code Add NASA API Key boot.py Project Code How It Works
Background Splash Screen Font JSON
© Adafruit Industries https://learn.adafruit.com/pyportal-nasa-image-of-the-day-viewer Page 2 of 29
Overview
SPAAAAAACE! Who doesn't want to look endlessly fascinating photos of space? !
NASA's Astronomy Picture of the Day (APOD) website provides just what the title says, a new, incredible space photo each day. Now, you can set up your PyPortal to be a dedicated viewer for these glorious images!
You'll use CircuitPython to code it, and the PyPortal library will make it simple to query the NASA Open API for the image.
Parts
© Adafruit Industries https://learn.adafruit.com/pyportal-nasa-image-of-the-day-viewer Page 3 of 29
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-nasa-image-of-the-day-viewer Page 4 of 29
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-nasa-image-of-the-day-viewer Page 5 of 29
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-nasa-image-of-the-day-viewer Page 6 of 29
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-nasa-image-of-the-day-viewer Page 7 of 29
PyPortal CircuitPython Setup
To use all the amazing features of your PyPortal with CircuitPython, you must first install a number of libraries. This page covers that process.
Adafruit CircuitPython Bundle
Download the Adafruit CircuitPython Library Bundle. You can find the latest release here:
https://adafru.it/ENC
Download the adafruit-circuitpython-bundle-*.x-mpy-*.zip bundle zip file where *.x MATCHES THE VERSION OF CIRCUITPYTHON YOU INSTALLED, and unzip a folder of the same name. Inside you'll find a lib folder. You have two options:
You can add the lib folder to your CIRCUITPY drive. This will ensure you have
all the drivers
. But it will take a bunch of space on the 8 MB disk Add each library as you need it, this will reduce the space usage but you'll need to put in a little more effort.
At a minimum we recommend the following libraries, in fact we more than recommend. They're basically required. So grab them and install them into CIRCUITPY/lib now!
adafruit_esp32spi - This is the library that gives you internet access via the ESP32 using (you guessed it!) SPI transport. You need this for anything Internet adafruit_requests - This library allows us to perform HTTP requests and get responses back from servers. GET/POST/PUT/PATCH - they're all in here! adafruit_pyportal - This is our friendly wrapper library that does a lot of our projects, displays graphics and text, fetches data from the internet. Nearly all of our projects depend on it!
adafruit_portalbase - This library is the base library that adafruit_pyportal library is built on top of. adafruit_touchscreen - a library for reading touches from the resistive touchscreen. Handles all the
analog noodling, rotation and calibration for you.
adafruit_io - this library helps connect the PyPortal to our free datalogging and viewing service adafruit_imageload - an image display helper, required for any graphics! adafruit_display_text - not surprisingly, it displays text on the screen adafruit_bitmap_font - we have fancy font support, and its easy to make new fonts. This library reads
and parses font files.
adafruit_slideshow - for making image slideshows - handy for quick display of graphics and sound neopixel - for controlling the onboard neopixel adafruit_adt7410 - library to read the temperature from the on-board Analog Devices ADT7410
precision temperature sensor
adafruit_sdcard - support for reading/writing data from the onboard SD card slot. adafruit_bus_device - low level support for I2C/SPI adafruit_fakerequests - This library allows you to create fake HTTP requests by using local files.
https://adafru.it/ENC
© Adafruit Industries https://learn.adafruit.com/pyportal-nasa-image-of-the-day-viewer Page 8 of 29
Internet Connect!
Once you have CircuitPython setup and libraries installed we can get your board connected to the Internet. Note that access to enterprise level secured WiFi networks is not currently supported, only WiFi networks that require SSID and password.
To get connected, you will need to start by creating a
secrets file
.
What's a secrets file?
We expect people to share tons of projects as they build CircuitPython WiFi widgets. What we want to avoid is people accidentally sharing their passwords or secret tokens and API keys. So, we designed all our examples to use a secrets.py file, that is in your CIRCUITPY drive, to hold secret/private/custom data.
That way you can share your main project without worrying about accidentally sharing private stuff.
Your secrets.py file should look like this:
# This file is where you keep secret settings, passwords, and tokens! # If you put them in the code you risk committing that info or sharing it
secrets = { 'ssid' : 'home ssid', 'password' : 'my password', 'timezone' : "America/New_York", # http://worldtimeapi.org/timezones 'github_token' : 'fawfj23rakjnfawiefa', 'hackaday_token' : 'h4xx0rs3kret', }
Inside is a python dictionary named secrets with a line for each entry. Each entry has an entry name (say
'ssid' ) and then a colon to separate it from the entry key 'home ssid' and finally a comma ,
At a minimum you'll need the ssid and password for your local WiFi setup. As you make projects you may need more tokens and keys, just add them one line at a time. See for example other tokens such as one
for accessing github or the hackaday API. Other non-secret data like your timezone can also go here, just cause it's called secrets doesn't mean you can't have general customization data in there!
For the correct time zone string, look at http://worldtimeapi.org/timezones (https://adafru.it/EcP) and remember that if your city is not listed, look for a city in the same time zone, for example Boston, New York, Philadelphia, Washington DC, and Miami are all on the same time as New York.
Of course, don't share your secrets.py - keep that out of GitHub, Discord or other project-sharing sites.
Connect to WiFi
OK now you have your secrets setup - you can connect to the Internet. Lets use the ESP32SPI and the Requests libraries - you'll need to visit the CircuitPython bundle and install (https://adafru.it/ENC):
adafruit_bus_device
adafruit_esp32spi
adafruit_requests
neopixel
Into your lib folder. Once that's done, load up the following example using Mu or your favorite editor:
© Adafruit Industries https://learn.adafruit.com/pyportal-nasa-image-of-the-day-viewer Page 9 of 29
Loading...
+ 20 hidden pages