Displaying your realtime Blood Glucose from NightScout on an AdaFruit PyPortal
AdaFruit makes an adorable tiny little Circuit Python IoT device called the PyPortal that's just about perfect for the kids - and me. It a little dakBoard, if you will - a tiny totally programmable display with Wi-Fi and lots of possibilities and sensors. Even better, you can just plug it in over USB and edit the code.py file directly on the drive that will appear. When you save code.py the device soft reboots and runs your code.
I've been using Visual Studio Code to program Circuit Python and it's become my most favorite IoT experience so far because it's just so easy. The "Developer's Inner Loop" of code, deploy, debug is so fast.
As you may know, I use a Dexcom CGM (Continuous Glucose Meter) to manage my Type 1 Diabetes. I feed the data every 5 minutes into an instance of the Nightscout Open Source software hosted in Azure. That gives me a REST API to my own body.
I use that REST API to make "glanceable displays" where I - or my family - can see my blood sugar quickly and easily.
I put my blood sugar in places like:
And today, on a tiny PyPortal device. The code is simple, noting that I don't speak Python, so Pull Requests are always appreciated.
from adafruit_pyportal import PyPortal
# Set up where we'll be fetching data from
DATA_SOURCE = "https://NIGHTSCOUTWEBSITE/api/v1/entries.json?count=1"
BG_VALUE = [0, 'sgv']
BG_DIRECTION = [0, 'direction']
RED = 0xFF0000;
ORANGE = 0xFFA500;
YELLOW = 0xFFFF00;
GREEN = 0x00FF00;
if val > 200:
elif val > 150:
elif val < 60:
elif val < 80:
return str(val) + ' mg/dl'
if val == "Flat":
if val == "SingleUp":
if val == "DoubleUp":
if val == "DoubleDown":
if val == "SingleDown":
if val == "FortyFiveDown":
if val == "FortyFiveUp":
# the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)
pyportal = PyPortal(url=DATA_SOURCE,
text_position=((90, 120), # VALUE location
(140, 160)), # DIRECTION location
text_color=(0x000000, # sugar text color
0x000000), # direction text color
text_wrap=(35, # characters to wrap for sugar
0), # no wrap for direction
text_maxlen=(180, 30), # max text size for sugar & direction
# speed up projects with lots of text by preloading the font!
pyportal.preload_font((0x2191, 0x2192, 0x2193))
value = pyportal.fetch()
print("Response is", value)
except RuntimeError as e:
print("Some error occured, retrying! -", e)
I've put the code up at https://github.com/shanselman/NightscoutPyPortal. I want to get (make a custom?) a larger BDF (Bitmap Font) that is about twice the size AND includes 45 degree arrows ↗ and ↘ as the font I have is just 24 point and only includes arrows at 90 degrees. Still, great fun and took just an hour!
NOTE: I used the Chortkeh BDF Font viewer to look at the Bitmap Fonts on Windows. I still need to find a larger 48+ PT Arial.
What information would YOU display on a PyPortal?
Sponsor: Manage GitHub Pull Requests right from the IDE with the latest JetBrains Rider. An integrated performance profiler on Windows comes to the rescue as well.
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
from a fellow nightscout/loop user
Comments are closed.
I was wondering could the Nights out Solution be made into a fully deployable solution on Azure? What I am thinking is an ARM template that deploys the infrastructure with an Azure DevOps pipeline that will configure it.
Basically, I want to make it easy as possible for other Type-1 people to get stuck in and give it a try. If that sounds like a good idea to you I would be happy to starting putting this together.