# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT """ Soundboard example with buttons. """ import time from adafruit_pyportal import PyPortal from adafruit_button import Button SHOW_BUTTONS = False # the current working directory (where this file is) cwd = ("/" + __file__).rsplit("/", 1)[0] # No internet use version of pyportal pyportal = PyPortal(default_bg=cwd + "/button_background.bmp") spots = [] spots.append({ "label": "1", "pos": (10, 10), "size": (60, 60), "file": "01.wav" }) spots.append({ "label": "2", "pos": (90, 10), "size": (60, 60), "file": "02.wav" }) spots.append({
import os import random import board import time from adafruit_pyportal import PyPortal pyportal = PyPortal(status_neopixel=board.NEOPIXEL, default_bg="/badge.bmp") calypso_imgs = [] reset_active = False def shuffle(l): """ Return a randomly shuffled list given an ordered list. """ final_list = [] for _ in l: final_list.append(l.pop(random.randrange(0, len(l)))) return final_list def in_region(region, point): """ Detect if a point exists in a region. Region: (x, y, width, height) Point: (x, y) Returns True or False depending on if the point exists in the region.
PROFILE_SIZE = 2 # plot thickness PROFILE_COLOR = 0x00FF55 # plot color GRID_SIZE = 2 GRID_COLOR = 0x2020FF GRID_STYLE = 3 TEMP_SIZE = 2 TEMP_COLOR = 0xFF0000 LABEL_COLOR = 0x8080FF AXIS_SIZE = 2 AXIS_COLOR = 0xFFFF00 WIDTH = board.DISPLAY.width HEIGHT = board.DISPLAY.height pyportal = PyPortal() palette = displayio.Palette(5) palette[0] = 0x0 palette[1] = PROFILE_COLOR palette[2] = GRID_COLOR palette[3] = TEMP_COLOR palette[4] = AXIS_COLOR palette.make_transparent(0) plot = displayio.Bitmap(WIDTH, HEIGHT, 8) pyportal.splash.append(displayio.TileGrid(plot, pixel_shader=palette)) ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=(
# Set up where we'll be fetching data from DATA_SOURCE = "https://www.adafruit.com/api/quotes.php" QUOTE_LOCATION = [0, 'text'] AUTHOR_LOCATION = [0, 'author'] # the current working directory (where this file is) cwd = ("/" + __file__).rsplit('/', 1)[0] pyportal = PyPortal( url=DATA_SOURCE, json_path=(QUOTE_LOCATION, AUTHOR_LOCATION), status_neopixel=board.NEOPIXEL, default_bg=cwd + "/quote_background.bmp", text_font=cwd + "/fonts/Arial-ItalicMT-17.bdf", text_position=( (20, 40), # quote location (5, 190)), # author location text_color=( 0xFFFFFF, # quote text color 0x8080FF), # author text color text_wrap=( 35, # characters to wrap for quote 0), # no wrap for author text_maxlen=(180, 30), # max text size for quote & author ) # speed up projects with lots of text by preloading the font! pyportal.preload_font() while True: try: value = pyportal.fetch()
# If you want to set the time for experimentation # yr, mon, day, h, min, sec #import rtc #rtc.RTC().datetime = time.struct_time((2019, 1, 1, 23, 59, 00, 0, 0, -1)) # determine the current working directory # needed so we know where to find files cwd = ("/" + __file__).rsplit('/', 1)[0] # Initialize the pyportal object and let us know what data to fetch and where # to display it mogwai_image = cwd + "/mogwai_background.bmp" mogwai_sound = cwd + "/mogwai_alarm.wav" gremlin_image = cwd + "/gremlin_background.bmp" gremlin_sound = cwd + "/gremlin_alarm.wav" pyportal = PyPortal(status_neopixel=board.NEOPIXEL, default_bg="pyportal_startup.bmp") big_font = bitmap_font.load_font(cwd + "/fonts/DSEG14ModernMiniBI-44.bdf") big_font.load_glyphs(b'0123456789:AP') # pre-load glyphs for fast printing time_textarea = Label(big_font, max_glyphs=15) time_textarea.x = 0 time_textarea.y = 130 time_textarea.color = 0xFF0000 pyportal.splash.append(time_textarea) # To help us know if we've changed the times, print them out! gremlin_hour, gremlin_min = gremlin_time[3:5] print("Gremlin time: %02d:%02d" % (gremlin_hour, gremlin_min)) mogwai_hour, mogwai_min = mogwai_time[3:5] print("Mogwai time: %02d:%02d" % (mogwai_hour, mogwai_min))
import board from adafruit_pyportal import PyPortal # Set up where we'll be fetching data from DATA_SOURCE = "http://tspann-MBP15-HW14277:8080/nifi-api/flow/status" DATA_LOCATION = ["controllerStatus", "flowFilesQueued"] def text_transform(val): format_str = "FlowFilesQueued in NiFi = {:d}" return format_str.format(val) # the current working directory (where this file is) cwd = ("/"+__file__).rsplit('/', 1)[0] pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd+"/quote_background.bmp", text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf", text_position=(20, 20), text_color=0xFFFFFF, text_transform=text_transform) pyportal.preload_font(b'$012345789') # preload numbers while True: try: value = pyportal.fetch() except (ValueError, RuntimeError) as e: print("Some error occured, retrying! -", e) time.sleep(60) #
soundBeep = '/sounds/beep.wav' soundTab = '/sounds/tab.wav' # ------------- Other Helper Functions------------- # # Helper for cycling through a number set of 1 to x. def numberUP(num, max_val): num += 1 if num <= max_val: return num else: return 1 # ------------- Screen Setup ------------- # pyportal = PyPortal() display = board.DISPLAY display.rotation = 270 # Backlight function # Value between 0 and 1 where 0 is OFF, 0.5 is 50% and 1 is 100% brightness. def set_backlight(val): val = max(0, min(1.0, val)) board.DISPLAY.auto_brightness = False board.DISPLAY.brightness = val # Set the Backlight set_backlight(0.3)
# PyPortal Initialization background_color = 0x0 # black brightness = 0.3 # 30% num_pixels = 5 # 5 pixel strip auto_write = False # call strip.show() to change neopixel vals strip = neopixel.NeoPixel(board.D4, num_pixels, brightness=brightness, auto_write=auto_write) strip.fill(0) pyportal = PyPortal(default_bg=background_color) buttons = create_buttons() for button in buttons: pyportal.splash.append(button.group) current_color = 0 current_offset = 0 while True: touch = pyportal.touchscreen.touch_point if touch: for button in buttons: if button.contains(touch): print("Touched", button.name) current_color = button.fill_color
from adafruit_bitmap_font import bitmap_font from adafruit_display_text.text_area import TextArea # Set up where we'll be fetching data from DATA_SOURCE = "http://api.open-notify.org/astros.json" DATA_LOCATION = [["number"], ["people"]] # determine the current working directory # needed so we know where to find files cwd = ("/" + __file__).rsplit('/', 1)[0] # Initialize the pyportal object and let us know what data to fetch and where # to display it pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd + "/astronauts_background.bmp", text_font=cwd + "/fonts/Helvetica-Bold-100.bdf", text_position=((180, 0), None), text_color=(0xFFFFFF, None)) names_font = bitmap_font.load_font(cwd + "/fonts/Helvetica-Bold-16.bdf") # pre-load glyphs for fast printing names_font.load_glyphs( b'abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- ()') names_position = (100, 130) names_color = 0xFF00FF while True: try: value = pyportal.fetch() print("Response is", value)
EVENT_MINUTE = 00 EVENT_DURATION = 3600 # in seconds! # Instead of messing around with timezones, just put in # the *location* of the event, and we'll automatically set the PyPortal's # time to that location. Then compute the math from there # for a list of valid locations, see http://worldtimeapi.org/api/timezone EVENT_LOCATION = "America/New_York" # set to None if its for your local time # the current working directory (where this file is) cwd = ("/"+__file__).rsplit('/', 1)[0] event_background = cwd+"/countdown_event.bmp" countdown_background = cwd+"/countdown_background.bmp" # Initialize the pyportal object and let us know what data to fetch and where # to display it pyportal = PyPortal(status_neopixel=board.NEOPIXEL, default_bg=countdown_background) big_font = bitmap_font.load_font(cwd+"/fonts/Helvetica-Bold-36.bdf") big_font.load_glyphs(b'0123456789') # pre-load glyphs for fast printing days_position = (25, 212) hours_position = (110, 212) minutes_position = (220, 212) text_color = 0x000000 text_areas = [] for pos in (days_position, hours_position, minutes_position): textarea = Label(big_font, text=' ') textarea.x = pos[0] textarea.y = pos[1] textarea.color = text_color
format_str = "{:,.2f} Bitcoins\n = {:,d}" if CURRENCY == 'USD': format_str = "{:,.2f} Bitcoins\n = ${:,d}" if CURRENCY == 'EUR': format_str = "{:,.2f} Bitcoins\n = €{:,d}" if CURRENCY == 'GBP': format_str = "{:,.2f} Bitcoins\n = £{:,d}" return format_str.format(NUM_BITCOINS, int(val * NUM_BITCOINS)) # the current working directory (where this file is) cwd = ("/" + __file__).rsplit('/', 1)[0] pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd + "/bitcoin_background.bmp", text_font=cwd + "/fonts/Arial-BoldItalic-12-Complete.bdf", text_position=(192, 130), text_color=0x0, text_transform=text_transform) pyportal.preload_font() # preload alphanums pyportal.preload_font((0x00A3, 0x20AC)) # preload gbp/euro symbol while True: try: value = pyportal.fetch() print("Response is", value) except (ValueError, RuntimeError) as e: print("Some error occured, retrying! -", e) time.sleep(3 * 60) # wait 3 minutes
vo_sound = [ "/vo/pathfnd_45.wav", "/vo/pathfnd_46.wav", "/vo/pathfnd_47.wav", "/vo/pathfnd_48.wav", "/vo/pathfnd_49.wav", "/vo/pathfnd_51.wav", "/vo/pathfnd_52.wav", "/vo/pathfnd_53.wav", "/vo/pathfnd_54.wav", "/vo/pathfnd_55.wav", "/vo/pathfnd_56.wav", ] pyportal = PyPortal(status_neopixel=board.NEOPIXEL) # Open the file with open(emote_img[0], "rb") as bitmap_file: # Setup the file as the bitmap data source bitmap = displayio.OnDiskBitmap(bitmap_file) # Create a TileGrid to hold the bitmap tile_grid = displayio.TileGrid(bitmap, pixel_shader=getattr( bitmap, 'pixel_shader', displayio.ColorConverter())) # Create a Group to hold the TileGrid group = displayio.Group() # Add the TileGrid to the Group group.append(tile_grid) # Add the Group to the Display
esp32_reset = DigitalInOut(board.ESP_RESET) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( esp, secrets, status_light) # Initialize PyPortal Display display = board.DISPLAY WIDTH = board.DISPLAY.width HEIGHT = board.DISPLAY.height # Initialize new PyPortal object pyportal = PyPortal(esp=esp, external_spi=spi) # Set backlight level pyportal.set_backlight(0.5) # Create a new DisplayIO group splash = displayio.Group(max_size=15) # show splash group display.show(splash) # Palette for water bitmap palette = displayio.Palette(2) palette[0] = 0x000000 palette[1] = WATER_COLOR palette.make_transparent(0)
BASE_DATA = "https://raw.githubusercontent.com/adafruit/OTD/master/electronics/" # a function that returns whatever is passed in def identity(x): return x # create pyportal object w no data source (we'll feed it text later) pyportal = PyPortal( url=BASE_DATA, debug=True, json_path=(DAY, PERSON, NOTABLE, YEAR, ACCOMPLISH, WEB), status_neopixel=board.NEOPIXEL, default_bg=cwd + "/on_this_day_bg.bmp", text_font=cwd + "fonts/Arial-ItalicMT-17.bdf", text_transform=[identity] * 6, # we do this so the date doesnt get commas text_position=((10, 70), (10, 100), (10, 130), (60, 160), (105, 190), (10, 220)), text_color=(0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF), text_maxlen=(50, 50, 50, 50, 50, 50), # cut off characters ) while True: try: print("Getting time from internet!") pyportal.get_local_time() refresh_time = time.monotonic() except RuntimeError as e: print("Some error occured, retrying! -", e) continue
status_backgrounds = { GREEN_LABEL: "images/full.bmp", YELLOW_LABEL: "images/low.bmp", RED_LABEL: "images/empty.bmp", } strip = neopixel.NeoPixel( board.D4, n=24, brightness=0.1, auto_write=False, # Requires calling strip.show() to change neopixel values ) arial_font = bitmap_font.load_font("/fonts/LeagueSpartan-Bold-16.bdf") background_color = 0x0 pyportal = PyPortal(default_bg=background_color) pixel_pattern = SparkleAnimation(strip=strip, frequency=12) buttons = create_buttons() button_group = displayio.Group() back_button_group = displayio.Group() social_status_label = label.Label( bitmap_font.load_font("/fonts/Junction-regular-24.bdf"), text="Social Battery", color=0xFFFFFF, x=30, y=30, ) init() while True:
# --| User Config |--------------------------------------------------- UPDATE_RATE = 60 # minutes MAX_STORMS = 3 # limit storms NAME_COLOR = 0xFFFFFF # label text color NAME_BG_COLOR = 0x000000 # label background color ARROW_COLOR = 0x0000FF # movement direction arrow color ARROW_LENGTH = 15 # movement direction arrow length LAT_RANGE = (45, 5) # set to match map LON_RANGE = (-100, -40) # set to match map # -------------------------------------------------------------------- # setup pyportal pyportal = PyPortal( url="https://www.nhc.noaa.gov/CurrentStorms.json", json_path=["activeStorms"], status_neopixel=board.NEOPIXEL, default_bg="/map.bmp", ) # setup display group for storms icons_bmp, icons_pal = adafruit_imageload.load("/storm_icons.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) for i, c in enumerate(icons_pal): if c == 0xFFFF00: icons_pal.make_transparent(i) storm_icons = displayio.Group(max_size=MAX_STORMS) pyportal.splash.append(storm_icons) STORM_CLASS = ("TD", "TS", "HU") # setup info label
# NOTE: Make sure you've created your secrets.py file before running this example # https://learn.adafruit.com/adafruit-pyportal/internet-connect#whats-a-secrets-file-17-2 import board from adafruit_pyportal import PyPortal # Set a data source URL TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html" # Create the PyPortal object pyportal = PyPortal(url=TEXT_URL, status_neopixel=board.NEOPIXEL) # Set display to show REPL board.DISPLAY.show(None) # Go get that data print("Fetching text from", TEXT_URL) data = pyportal.fetch() # Print out what we got print("-" * 40) print(data) print("-" * 40)
raise # Use cityname, country code where countrycode is ISO3166 format. # E.g. "New York, US" or "London, GB" LOCATION = "Manhattan, US" # Set up where we'll be fetching data from DATA_SOURCE = "http://api.openweathermap.org/data/2.5/weather?q=" + LOCATION DATA_SOURCE += "&appid=" + secrets["openweather_token"] # You'll need to get a token from openweather.org, looks like 'b6907d289e10d714a6e88b30761fae22' DATA_LOCATION = [] # Initialize the pyportal object and let us know what data to fetch and where # to display it pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, default_bg=0x000000) gfx = openweather_graphics.OpenWeather_Graphics(pyportal.splash, am_pm=True, celsius=False) localtile_refresh = None weather_refresh = None while True: # only query the online time once per hour (and on first run) if (not localtile_refresh) or (time.monotonic() - localtile_refresh) > 3600: try: print("Getting time from internet!") pyportal.get_local_time()
from adafruit_pyportal import PyPortal # Set up where we'll be fetching data from DATA_SOURCE = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY" # There's a few different places we look for data in the photo of the day IMAGE_LOCATION = ["url"] TITLE_LOCATION = ["title"] DATE_LOCATION = ["date"] cwd = __file__.rsplit('/', 1)[0] pyportal = PyPortal( url=DATA_SOURCE, json_path=(TITLE_LOCATION, DATE_LOCATION), status_neopixel=board.NEOPIXEL, default_bg=cwd + "/nasa_background.bmp", text_font=cwd + "/fonts/Arial-12.bdf", text_position=((5, 220), (5, 200)), text_color=(0xFFFFFF, 0xFFFFFF), text_maxlen=(50, 50), # cut off characters image_json_path=IMAGE_LOCATION, image_resize=(320, 240), image_position=(0, 0)) while True: response = None try: response = pyportal.fetch() print("Response is", response) except RuntimeError as e: print("Some error occured, retrying! -", e) time.sleep(30 * 60) # 30 minutes till next check
This example will access shields.io API, grab the SVG graphic and then use regular expression search to locate the number of online discord users, then display it on a screen. If you can find something that spits out text, we can display it! """ import time import board from adafruit_pyportal import PyPortal # Set up where we'll be fetching data from DATA_SOURCE = "https://img.shields.io/discord/327254708534116352.svg" # a regular expression for finding the data within the SVG xml text! DATA_LOCATION = [r">([0-9]+ online)<"] cwd = ("/" + __file__).rsplit('/', 1)[0] pyportal = PyPortal(url=DATA_SOURCE, regexp_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd + "/discord_background.bmp", text_font=cwd + "/fonts/Collegiate-50.bdf", text_position=(75, 170), text_color=0x000000) while True: try: value = pyportal.fetch() print("Response is", value) except RuntimeError as e: print("Some error occured, retrying! -", e) time.sleep(60)
from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise # Change this to your state and county, replacing spaces for underscores and in lowercase STATE = "new_york" COUNTY = "new_york" DATA_SOURCE = "https://electioncal.us/en/" + STATE + "/" + COUNTY + "/voter.json" DATA_LOCATION = [] # Initialize the pyportal object and let us know what data to fetch and where # to display it pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=0x000000) gfx = electioncal_graphics.Electioncal_Graphics(pyportal.splash, am_pm=True) display_refresh = None while True: # only query the online time once per hour (and on first run) if (not display_refresh) or (time.monotonic() - display_refresh) > 3600: try: print("Getting time from internet!") pyportal.get_local_time() display_refresh = time.monotonic() except RuntimeError as e: print("Some error occured, retrying! -", e) continue
import analogio import displayio import adafruit_logging as logging # Set up where we'll be fetching data from DATA_SOURCE = 'http://api.openweathermap.org/data/2.5/weather?id=' + secrets[ 'city_id'] DATA_SOURCE += '&appid=' + secrets['openweather_token'] # You'll need to get a token from openweather.org, looks like 'b6907d289e10d714a6e88b30761fae22' DATA_LOCATION = [] #################### # setup hardware pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL) light = analogio.AnalogIn(board.LIGHT) snooze_button = DigitalInOut(board.D3) snooze_button.direction = Direction.INPUT snooze_button.pull = Pull.UP #################### # variables # alarm support alarm_background = 'red_alert.bmp' alarm_file = 'alarm.wav'
except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise # # Use cityname, country code where countrycode is ISO3166 format. # # E.g. "New York, US" or "London, GB" # set to your local the tide predition STATION from the NOAA tide prediction site STATION = "8441241" # Set up a placeholder for DATA_SOURCE that we will update later on DATA_SOURCE = " " DATA_LOCATION = [] # Initialize the pyportal object and set the tides background pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd + "/tides.bmp") pyportal.preload_font() big_font = bitmap_font.load_font(cwd + "/fonts/Arial-Bold-24-Complete.bdf") little_font = bitmap_font.load_font(cwd + "/fonts/Arial-Bold-12.bdf") pyportal.preload_font( b'0123456789fallingrising') # pre-load glyphs for fast printing directionp = (100, 195) high1p = (25, 25) low1p = (25, 85) high2p = (210, 25) low2p = (210, 85) high1t = (25, 50) low1t = (25, 110)
# Get wifi details and more from a settings.py file try: from settings import settings except ImportError: print("WiFi settings are kept in settings.py, please add them there!") raise # Set up where we'll be fetching data from DATA_SOURCE = "https://io.adafruit.com/api/v2/stats?x-aio-key=" + settings[ 'adafruitio_key'] DATA_LOCATION1 = ["io_plus", "io_plus_subscriptions"] DATA_LOCATION2 = ["users", "users_active_30_days"] cwd = __file__.rsplit('/', 1)[0] pyportal = PyPortal(url=DATA_SOURCE, json_path=(DATA_LOCATION1, DATA_LOCATION2), status_neopixel=board.NEOPIXEL, default_bg=cwd + "/adafruitio_background.bmp", text_font=cwd + "/fonts/Collegiate-24.bdf", text_position=((165, 145), (165, 178)), text_color=(0x00FF00, 0x0000FF)) while True: try: value = pyportal.fetch() print("Response is", value) except RuntimeError as e: print("Some error occured, retrying! -", e) time.sleep(60)
11: "November", 12: "December" } esp32_cs = digitalio.DigitalInOut(board.ESP_CS) esp32_ready = digitalio.DigitalInOut(board.ESP_BUSY) esp32_reset = digitalio.DigitalInOut(board.ESP_RESET) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset, debug=False) requests.set_socket(socket, esp) # initialize pyportal pyportal = PyPortal(esp=esp, external_spi=spi, default_bg = None) # set pyportal's backlight brightness pyportal.set_backlight(0.2) if esp.status == adafruit_esp32spi.WL_IDLE_STATUS: print("ESP32 found and in idle mode") print("Firmware vers.", esp.firmware_version) print("MAC addr:", [hex(i) for i in esp.MAC_address]) print("Connecting to AP...") while not esp.is_connected: try: esp.connect_AP(secrets['ssid'], secrets['password']) except RuntimeError as e:
if val == "FortyFiveUp": return "→↑" return val # the current working directory (where this file is) cwd = ("/" + __file__).rsplit('/', 1)[0] pyportal = PyPortal( url=DATA_SOURCE, json_path=(BG_VALUE, BG_DIRECTION), status_neopixel=board.NEOPIXEL, default_bg=0xFFFFFF, text_font=cwd + "/fonts/Arial-Bold-24-Complete.bdf", 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 text_transform=(text_transform_bg, text_transform_direction), ) # speed up projects with lots of text by preloading the font! pyportal.preload_font(b'mg/dl012345789') pyportal.preload_font((0x2191, 0x2192, 0x2193)) #pyportal.preload_font() while True:
TIME_COLOR = 0x111111 # time color LAT_MAX = 80 # latitude (deg) of map top/bottom edge UPDATE_RATE = 10 # update rate in seconds #------------------------------------------- DATA_SOURCE = "http://api.open-notify.org/iss-now.json" DATA_LOCATION = ["iss_position"] WIDTH = board.DISPLAY.width HEIGHT = board.DISPLAY.height # determine the current working directory needed so we know where to find files cwd = ("/" + __file__).rsplit('/', 1)[0] pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, text_font=None, default_bg=cwd + "/map.bmp") # Connect to the internet and get local time pyportal.get_local_time() # Date and time label date_label = Label(FONT, text="0000-00-00", color=DATE_COLOR, x=165, y=223) time_label = Label(FONT, text="00:00:00", color=TIME_COLOR, x=240, y=223) pyportal.splash.append(date_label) pyportal.splash.append(time_label) # ISS trail trail_bitmap = displayio.Bitmap(3, 3, 1) trail_palette = displayio.Palette(1)
# Adafruit IO Account IO_USER = secrets['aio_username'] IO_KEY = secrets['aio_key'] # Adafruit IO Feed IO_FEED = 'zapemail' DATA_SOURCE = "https://io.adafruit.com/api/v2/{0}/feeds/{1}?X-AIO-Key={2}".format(IO_USER, IO_FEED, IO_KEY) FEED_VALUE_LOCATION = ['last_value'] cwd = ("/"+__file__).rsplit('/', 1)[0] pyportal = PyPortal(url=DATA_SOURCE, json_path=FEED_VALUE_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd+"/pyportal_email.bmp", text_font=cwd+"/fonts/Helvetica-Oblique-17.bdf", text_position=(30, 65), text_color=0xFFFFFF, text_wrap=35, # wrap feed after 35 chars text_maxlen=160) # speed up projects with lots of text by preloading the font! pyportal.preload_font() while True: try: print('Fetching Adafruit IO Feed Value..') value = pyportal.fetch() print("Response is", value) except RuntimeError as e: print("Some error occured, retrying! -", e)
DATA_SOURCE = "https://api.github.com/repos/adafruit/circuitpython" CAPTION = "www.github.com/adafruit/circuitpython" # If we have an access token, w can query more often if 'github_token' in secrets: DATA_SOURCE += "?access_token=" + secrets['github_token'] # The data we want to display DATA_LOCATION = ["stargazers_count"] cwd = ("/" + __file__).rsplit('/', 1)[0] pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd + "/stars_background.bmp", text_font=cwd + "/fonts/Collegiate-50.bdf", text_position=(200, 100), text_color=0xFFFFFF, caption_text=CAPTION, caption_font=cwd + "/fonts/Arial.bdf", caption_position=(40, 220), caption_color=0xFFFFFF) # track the last value so we can play a sound when it updates last_value = 0 while True: try: value = pyportal.fetch() print("Response is", value) if last_value < value: # ooh it went up! print("New star!")
cwd = ("/" + __file__).rsplit('/', 1)[0] #CAPTION_FONT_FILE = cwd+'/fonts/Helvetica-Bold-16.bdf' CAPTION_FONT_FILE = cwd + '/fonts/HelveticaNeue-24.bdf' #CAPTION_FONT_FILE = cws+'/Helvetica-Bold-100.bdf' #AQI_FONT_FILE = cwd+'/fonts/Arial-Bold-12.bdf' AQI_FONT_FILE = cwd + '/fonts/HelveticaNeue-24.bdf' FOOTER_FONT_FILE = cwd + '/fonts/HelveticaNeueMedium-12.bdf' #pyportal = PyPortal(url=aqiurl, # status_neopixel=board.NEOPIXEL, # default_bg=0x000000, # caption_font=CAPTION_FONT_FILE) pyportal = PyPortal(url=aqiurl, default_bg=0x000000, caption_font=CAPTION_FONT_FILE) canvas = displayio.Group(max_size=36) pyportal.splash.append(canvas) AQI_font = bitmap_font.load_font(AQI_FONT_FILE) Footer_font = bitmap_font.load_font(FOOTER_FONT_FILE) status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.1) status_light[0] = (00, 0, 00) #status_light[0] = (30, 00, 00, 10) while True: worst = 0 json_payload = '' try: