spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) ecs = digitalio.DigitalInOut(board.CE0) dc = digitalio.DigitalInOut(board.D22) srcs = None rst = digitalio.DigitalInOut(board.D27) busy = digitalio.DigitalInOut(board.D17) # give them all to our driver # display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display display = Adafruit_SSD1675( 122, 250, # 2.13" HD mono display # display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display # display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display # display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display # display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display # display = Adafruit_IL0373(104, 212, # 2.13" Tri-color display spi, cs_pin=ecs, dc_pin=dc, sramcs_pin=srcs, rst_pin=rst, busy_pin=busy) # IF YOU HAVE A FLEXIBLE DISPLAY (2.13" or 2.9") uncomment these lines! # display.set_black_buffer(1, False) # display.set_color_buffer(1, False) display.rotation = 1 image = Image.new("RGB", (display.width, display.height))
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 10) #api url. you could probably change this if you wanted to monitor a remote Pihole api_url = 'http://localhost/admin/api.php' #locations for screen drawing height = 122 width = 250 x = width - 250 #0?! y = height - 122 from adafruit_epd.ssd1675 import Adafruit_SSD1675 display = Adafruit_SSD1675(122, 250, spi, cs_pin=ecs, dc_pin=dc, sramcs_pin=srcs, rst_pin=rst, busy_pin=busy) display.rotation = 3 #clear the screen display.fill(Adafruit_EPD.WHITE) #duh, its two colors, but you can mess with this if you have a tricolor display WHITE = (255, 255, 255) BLACK = (0, 0, 0) image = Image.new("RGB", (250, 122), color=WHITE) draw = ImageDraw.Draw(image)
from os import environ from time import sleep from datetime import datetime, timedelta import requests from weather_graphic import Conditions, Weather_Graphic from digitalio import DigitalInOut from busio import SPI import board from adafruit_epd.ssd1675 import Adafruit_SSD1675 display = Adafruit_SSD1675( 122, 250, SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO), cs_pin=DigitalInOut(board.CE0), dc_pin=DigitalInOut(board.D22), sramcs_pin=None, rst_pin=DigitalInOut(board.D27), busy_pin=DigitalInOut(board.D17), ) display.rotation = 3 LAT, LON = "39.571", "-97.662" url = "http://api.openweathermap.org/data/2.5/weather" params = { "appid": environ['OPEN_WEATHER_TOKEN'], "lat": LAT, "lon": LON, }
print("start: --- %s seconds ---" % (time.time() - start_time)) # create the spi device and pins we will need spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) ecs = digitalio.DigitalInOut(board.CE0) dc = digitalio.DigitalInOut(board.D22) srcs = None rst = digitalio.DigitalInOut(board.D27) busy = digitalio.DigitalInOut(board.D17) # give them all to our driver display = Adafruit_SSD1675( 122, # 104, 250, # 212, # 2.13" Tri-color display spi, cs_pin=ecs, dc_pin=dc, sramcs_pin=None, rst_pin=rst, busy_pin=busy, ) display.rotation = 2 up_button = digitalio.DigitalInOut(board.D5) up_button.switch_to_input() down_button = digitalio.DigitalInOut(board.D6) down_button.switch_to_input() print("^^ e-ink prep: --- %s seconds ---" % (time.time() - start_time))
def main(): spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) i2c = busio.I2C(board.SCL, board.SDA) ecs = digitalio.DigitalInOut(board.CE0) dc = digitalio.DigitalInOut(board.D22) rst = digitalio.DigitalInOut(board.D27) busy = digitalio.DigitalInOut(board.D17) # You'll need to get a token from openweathermap.org, looks like: # 'b6907d289e10d714a6e88b30761fae22' OPEN_WEATHER_TOKEN = 'f1525c6af313ad137fea6d36606822c9' # Use cityname, country code where countrycode is ISO3166 format. # E.g. "New York, US" or "London, GB" LOCATION = "Wenatchee, US" DATA_SOURCE_URL = "http://api.openweathermap.org/data/2.5/weather" if len(OPEN_WEATHER_TOKEN) == 0: raise RuntimeError( "You need to set your token first. If you don't already have one, you can register for a free account at https://home.openweathermap.org/users/sign_up" ) # Set up where we'll be fetching data from params = {"q": LOCATION, "appid": OPEN_WEATHER_TOKEN} data_source = DATA_SOURCE_URL + "?" + urllib.parse.urlencode(params) # Initialize the Display display = Adafruit_SSD1675( 122, 250, spi, cs_pin=ecs, dc_pin=dc, sramcs_pin=None, rst_pin=rst, busy_pin=busy, ) display.rotation = 1 gfx = Weather_Graphics(display, am_pm=True, celsius=False) weather_refresh = None # Try to read from the weather device try: bme280 = Adafruit_BME280_I2C(i2c) except InputError as e: #TODO actually catch the proper exception and handle it pass while not exit.is_set(): try: # only query the weather every 10 minutes (and on first run) if (not weather_refresh) or (time.monotonic() - weather_refresh) > 300: response = urllib.request.urlopen(data_source) if response.getcode() == 200: value = response.read() print("Response is", value) gfx.display_weather(value, bme280) weather_refresh = time.monotonic() else: print("Unable to retrieve data at {}".format(url)) gfx.update_time() print('gonna wait for 3 mins') exit.wait(180) # wait 5 minutes before updating anything again print('done waiting for 3 mins') except subprocess.CalledProcessError as e: print('caught error in subprocess') print(e) else: print('exiting') gfx.clear_display() time.sleep(1) sys.exit(0)