Overview
Build your Apple Health Stat Board using itsaSNAP and CircuitPython. This project uses the Adafruit Matrix Portal S3 to make network calls to retrieve data and a 64x64 panel to display that data.
itaSNAP now has HealthKit capabilities, which allows users to query specific Apple Health data and send it to Adafruit IO. This displays your weekly steps, workouts, and distance traveled during a workout.
itsaSNAP for iOS
itsaSNAP is a simple iOS app designed for exploring Adafruit IO. It allows you to send data to your Adafruit IO feeds. You can also link it to control or monitor your internet-connected projects. This lets you control and check Adafruit devices from your phone, anywhere.
It also allows us use of Apple's Shortcuts app to create a code-free automation from your iOS device.
Or
Optional:
Page last edited October 02, 2024
Get Started with Adafruit IO
Adafruit IO is integrated with your adafruit.com account so you don't need to create yet another online account! You need an Adafruit account to use Adafruit IO because to make sure the data you upload is available to only you (unless you decide to publish your data).
I have an Adafruit.com Account already
If you already have an Adafruit account, then you already have access to Adafruit IO. It doesn't matter how you signed up, your account will make all three available.
To access Adafruit IO, simply visit https://io.adafruit.com to start streaming, logging, and interacting with your data.
Create an Adafruit Account (for Adafruit IO)
An Adafruit account makes Adafruit content and services available to you in one place. Your account provides access to the Adafruit shop, the Adafruit Learning System, and Adafruit IO. This means only one account, one username, and one password are necessary to engage with the content and services that Adafruit offers.
If you do not have an Adafruit account, signing up for a new Adafruit account only takes a couple of steps.
Begin by visiting https://accounts.adafruit.com.
Click the Sign Up button under the "Need An Adafruit Account?" title, below the Sign In section.
This will take you to the Sign Up page.
Fill in the requested information, and click the Create Account button.
For example, to begin working with Adafruit IO, click the IO link between the Forum and LIVE! Links.
That's all there is to creating a new Adafruit account and navigating to Adafruit IO.
Page last edited October 02, 2024
Download the ItsaSnap by Adafruit App
This section will guide you through downloading and installing the ItsaSnap by Adafruit app.
Download and Install ItsaSnap
To install and download ItsaSnap for your iOS device,
- Open the App Store.
- Tap on the "Search" icon at the bottom of the screen.
- Type "ItsaSnap by Adafruit" or "ItsaSnap" in the search bar and tap "Search".
- Locate the ItsaSnap app in the search results and tap on it
5. Tap the "Get" button to download and install the app on your device.
You may be prompted to enter your Apple ID password or use Face ID/Touch ID to confirm the installation
After you have downloaded and installed ItsaSnap, open the app.
You will need to enter your Adafruit username and Adafruit IO Key (which is different from your Adafruit account password).
Your Adafruit IO key is a long string of letters and numbers. To make it easier to add to the app, we've also included a QR code scanner that allows you to easily copy the Adafruit IO Key from the Adafruit IO website to the app.
On the ItaSnap app, the QR code scanner is located below the Adafruit IO Key and above the login button. To access it, press the 'Scan QR code for IO Key' button. This will open the QR code scanner.
To find the QR code for your Adafruit IO account, navigate go to the overview page. Once there, click the yellow button with a key in the center (it's next to the "New Device" button) to reveal your Adafruit IO Key.
After clicking it, a window with your information will appear. Then, find the QR code and scan it, and log in.
Page last edited October 02, 2024
Install CircuitPython
CircuitPython is a derivative of MicroPython 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 drive to iterate.
Set up CircuitPython Quick Start!
Follow this quick step-by-step for super-fast Python power :)
Further Information
For more detailed info on installing CircuitPython, check out Installing CircuitPython.
Click the link above and download the latest UF2 file.
Download and save it to your desktop (or wherever is handy).
Plug your MatrixPortal S3 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.
Click the Reset button (indicated by the green arrow) on your board. When you see the NeoPixel RGB LED (indicated by the magenta arrow) turn purple, press it again. At that point, the NeoPixel should turn green. If it turns red, check the USB cable, try another USB port, etc.
If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!
You will see a new disk drive appear called MATRXS3BOOT.
Drag the adafruit_circuitpython_etc.uf2 file over to MATRXS3BOOT.
Page last edited October 02, 2024
Setting Up Your Credentials
To make network inquiriess using your MatrixPortal, you'll need to provide your WiFi and Adafruit IO credentials in a settings.toml file.
Plug your Matrix Portal S3 into your computer via a known good data + power USB cable. Your board should show up as a thumb drive in your File Explorer / Finder (depending on your operating system) named CIRCUITPY.
Create a file with the name settings.toml in the root directory of the CIRCUITPY drive.
Add the following below:
The file should contain the keys CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD, CIRCUITPY_WEB_API_PASSWORD, AIO_USERNAME, and AIO_KEY.
Once these are defined, CircuitPython will automatically connect to the network and start the webserver used for the workflow.
The web server is on port 80 unless overridden by CIRCUITPY_WEB_API_PORT. It also enables MDNS.
Here is an example settings.toml:
# To auto-connect to WiFi CIRCUITPY_WIFI_SSID="YOUR-WIFI-NETWORK-NAME" CIRCUITPY_WIFI_PASSWORD="YOUR-WIFI-NETWORK-PASSWORD" # For Adafruit IO AIO_USERNAME="YOUR-USERNAME" AIO_KEY="YOUR-AO-KEY" # To enable modifying files from the web. Change this too! # Leave the User field blank in the browser. CIRCUITPY_WEB_API_PASSWORD="passw0rd" CIRCUITPY_WEB_API_PORT=80
Page last edited October 02, 2024
LED Matrix Diffuser
LED Diffusion Acrylic
You can add an LED diffusion acrylic faceplate to the your LED matrix display. (Pictured here with the ON AIR project)
This can help protect the LEDs as well as enhance the look of the sign both indoors and out by reducing glare and specular highlights of the plastic matrix grid.
Measure and Cut the Plastic
You can use the sign to measure and mark cut lines on the paper backing of the acrylic sheet.
Then, use a tablesaw or bandsaw with a fine toothed blade and a guide or sled to make the cuts.
Note: it is possible to score and snap acrylic, but it can be very tricky to get an even snap without proper clamping.
Peel away the paper backing from both sides and set the acrylic onto your matrix display with the matte finished side facing out.
Uglu Dashes
The best method we've found for adhering acrylic to the matrix display is to use Uglu Dashes clear adhesive rectangles from Pro Tapes. They are incredibly strong (although can be removed if necessary), easy to apply, and are invisible once attached.
Use one at each corner and one each at the halfway point of the long edges, then press the acrylic and matrix panel together for about 20 seconds.
Here you can see the impact of using the diffusion acrylic. (Pictured here with the ON AIR sign project)
Stand
A very simple and attractive way to display your matrix is with the adjustable bent-wire stand.
Alternately, you can use a frame, 3D printed brackets, tape, glue, or even large binder clips to secure the acrylic to the sign and then mount it on on a wall, shelf, or display cabinet.
These mini-magnet feet can be used to stick the sign to a ferrous surface.
Page last edited October 02, 2024
Create an Adafruit IO Feed
Adafruit IO's main feature is creating feeds to write or read data in a centralized place. In this project, you will create an Adafruit IO feed to send and read weather data to that feed.
In a web browser, navigate to io.adafruit.com/feeds and click "+ New Feed"
Give your new feed a name. The description is optional. Click Create to create the new feed.
Under My Feeds, you should see the stepCount feed you created. Repeat this same process with "numOfWorkouts" and "distance". Please take note of your feed keys, which is located here; you will need it later.
Page last edited October 02, 2024
Code the Apple Health Board
Once you've finished setting up your Matrix Portal S3 with CircuitPython and have connected to the Internet, you can download the Project Bundle to access the code and necessary libraries.
To do this, click the Download Project Bundle button in the window below. It will download to your computer as a zipped folder.
# SPDX-FileCopyrightText: Copyright (c) 2024 Trevor Beaton for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import board
import terminalio
import displayio
from adafruit_matrixportal.matrixportal import MatrixPortal
from adafruit_display_text import label
# --- Display setup ---
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=True, width=64, height=64)
# Use the built-in font
font = terminalio.FONT
# Define colors
ORANGE = 0xFFA500
WHITE = 0xFFFFFF
RED = 0xFF0000
# Create a Group to hold all the text areas and the heart
group = displayio.Group()
# Create a small heart bitmap
heart_bitmap = displayio.Bitmap(7, 7, 2)
heart_palette = displayio.Palette(2)
heart_palette[0] = 0x000000 # Black (transparent)
heart_palette[1] = RED # Red heart
# Draw the heart
heart_pixels = [
0,1,1,0,1,1,0,
1,1,1,1,1,1,1,
1,1,1,1,1,1,1,
0,1,1,1,1,1,0,
0,0,1,1,1,0,0,
0,0,0,1,0,0,0,
]
for heart_idx, pixel in enumerate(heart_pixels):
heart_bitmap[heart_idx % 7, heart_idx // 7] = pixel
# Create a TileGrid using the heart bitmap and palette
heart_tile = displayio.TileGrid(heart_bitmap, pixel_shader=heart_palette, x=56, y=1)
group.append(heart_tile)
# Add text labels for titles and values
for label_idx in range(3):
# Title
title_label = label.Label(font, text="", color=ORANGE, x=2, y=7 + label_idx*21)
group.append(title_label)
# Value
value_label = label.Label(font, text="", color=WHITE, x=2, y=17 + label_idx*21)
group.append(value_label)
# Add the group to the display
matrixportal.display.show(group)
# Define feed keys for your data
TITLES = ["STEPS", "WORKOUTS", "MILES"]
VALUE_FEEDS = ["stepcount", "numofworkouts", "distance"]
UPDATE_DELAY = 1800 # Update every 30 minutes
def get_feed_data(feed_key):
try:
data = matrixportal.get_io_data(feed_key)
if data:
return data[0]["value"]
except (ValueError, RuntimeError) as feed_error:
print(f"Error fetching data from feed {feed_key}: {feed_error}")
return None
def update_display():
for display_idx, (title, value_feed) in enumerate(zip(TITLES, VALUE_FEEDS)):
value = get_feed_data(value_feed) or "N/A"
group[display_idx*2 + 1].text = title # Update title
group[display_idx*2 + 2].text = str(value) # Update value
# Initial display update
update_display()
# Main loop
while True:
try:
time.sleep(UPDATE_DELAY)
update_display()
except (ValueError, RuntimeError) as loop_error:
print("Some error occurred, retrying! -", loop_error)
continue
Upload the Code and Libraries
After downloading the Project Bundle, plug your Matrix Portal S3 into the computer's USB port with a known good USB data + power cable. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called CIRCUITPY. Unzip the folder and copy the following items to the CIRCUITPY drive.
- lib folder
- Images folder
- code.py
The CIRCUITPY drive should look like this after copying the lib folder, images folder, and the code.py file.
Display Setup
This line initializes the MatrixPortal with a 64x64 LED matrix. The status_neopixel parameter allows for using the onboard NeoPixel for status indication. The width and height sets the parameters for the display.
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=True, width=64, height=64)
Adding Text Labels
This loop creates three pairs of labels: one pair each for steps, workouts, and miles. Each pair has a title label (in orange) and a value label (in white).
for label_idx in range(3):
title_label = label.Label(font, text="", color=ORANGE, x=2, y=7 + label_idx*21)
group.append(title_label)
value_label = label.Label(font, text="", color=WHITE, x=2, y=17 + label_idx*21)
group.append(value_label)
Fetching Data
This function attempts to retrieve the latest value from a specified Adafruit IO feed. It uses the Using matrixportal.get_io_data returns a list of data points.
def get_feed_data(feed_key):
try:
data = matrixportal.get_io_data(feed_key)
if data:
return data[0]["value"]
except (ValueError, RuntimeError) as feed_error:
print(f"Error fetching data from feed {feed_key}: {feed_error}")
return None
Updating the Display
This function updates the display with new data for each fitness metric. It iterates through the TITLES and VALUE_FEEDS lists using zip().
def update_display():
for display_idx, (title, value_feed) in enumerate(zip(TITLES, VALUE_FEEDS)):
value = get_feed_data(value_feed) or "N/A"
group[display_idx*2 + 1].text = title # Update title
group[display_idx*2 + 2].text = str(value) # Update value
Main loop
The main loop runs, updating the display every 30 minutes (1800 seconds, as defined by UPDATE_DELAY). If an error occurs during the update process, it's caught, printed, and the loop continues, ensuring the program doesn't crash due to temporary issues like network problems.
while True:
try:
time.sleep(UPDATE_DELAY)
update_display()
except (ValueError, RuntimeError) as loop_error:
print("Some error occurred, retrying! -", loop_error)
continue
Page last edited October 02, 2024
Creating the "itsaSNAP Apple Fitness Stats Fetcher" shortcut
You can use Apple Shortcuts to configure itsaSNAP functions for querying and sending your Apple Health data to Adafruit IO. You can download the Shortcut from the link provided or create it yourself using the steps below.
This step will demonstrate using itsaSNAP with Apple Shortcuts to send a value to an Adafruit IO feed when the shortcut is run.
Open Apple Shortcuts on your iPhone or iPad. To create a new shortcut, tap the "+" button.
Open Apple Shortcuts on your iPhone or iPad. To create a new shortcut, tap the "+" button.
Tap "Add Action". Then, search for itsaSNAP, then look for and tap "Weekly Step Count".
This action queries weekly step count data starting from Sunday. Now, you need to send this data to your Adafruit IO feed. Tap on the keyboard bar, search for itsaSNAP, and select Send Value.
Configure Action
Add your feed key and the value you want to send to your Feed here. Tap the Value field and select Weekly Step Count from the keyboard bar.
Repeat this process for the Weekly Workout Count and Weekly Distance Travelled actions.
Now that your shortcut is assembled, try giving it a test run. Press the Play button at the bottom of the screen.
If all works well, multiple message prompts will notify you that your data has been sent to your Adafruit IO feeds.
Page last edited October 02, 2024
Setting up Apple Shortcuts Automation
To create a new automation, go to the automation screen and tap the "+" button.
Here you can select which types of triggers can initiate an action. For now, we'll use "Time of Day" to set a time to schedule a time to run the Apple Shortcut.
Select "Time of Day" as the trigger for the automation.
Add the time of day here. I prefer to send this update at sunrise, have it repeat daily, and run immediately (you will be notified whenever the shortcut task is attempted).
Once you're all set - tap Done.
In the My Shortcuts row, select the shortcut action you made earlier.
Upon selecting your Apple shortcut, your automation will be set. Be sure to set your automation for any time you want. I've set my shortcuts to run multiple times of the day.
Page last edited October 02, 2024
Use
Check your stats!
Plug the Matrix Portal S3 into USB-C power. Run your "Apple Health Stat Fetcher" shortcut, then press the reset button on the Matrix Portal after completing the shortcut.
The display should change to reflect the users' step count, number of workouts completed, and distance traveled while working out.
If you witness an error message displayed on your board, make sure the feed you choose has a value to display, or double-check the feed you would like to show.
Page last edited October 02, 2024