|
10 | 10 | import busio |
11 | 11 | from digitalio import DigitalInOut |
12 | 12 | from analogio import AnalogIn |
13 | | -import adafruit_adt7410 |
14 | | - |
| 13 | +import displayio |
| 14 | +from adafruit_display_text.label import Label |
| 15 | +from adafruit_bitmap_font import bitmap_font |
15 | 16 | from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager |
16 | 17 | from adafruit_io.adafruit_io import RESTClient, AdafruitIO_RequestError |
17 | 18 |
|
18 | | -# thermometer graphics helper |
19 | | -import wakeup_helper |
| 19 | +cwd = ("/"+__file__).rsplit('/', 1)[0] # the current working directory (where this file is) |
20 | 20 |
|
21 | 21 | # rate at which to refresh the pyportal screen, in seconds |
22 | 22 | PYPORTAL_REFRESH = 15 |
|
47 | 47 | raise KeyError('To use this code, you need to include your Adafruit IO username \ |
48 | 48 | and password in a secrets.py file on the CIRCUITPY drive.') |
49 | 49 |
|
50 | | -# Create an instance of the Adafruit IO REST client |
51 | | -io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) |
| 50 | +# Fonts within /fonts folder |
| 51 | +info_font = cwd+"/fonts/Nunito-Black-17.bdf" |
| 52 | +time_font = cwd+"/fonts/Nunito-Light-75.bdf" |
| 53 | + |
| 54 | +# create text object group |
| 55 | +text_group = displayio.Group(max_size=6) |
| 56 | +text_group.append(text_group) |
52 | 57 |
|
53 | | -# Get the temperature feed from Adafruit IO |
54 | | -temperature_feed = io.get_feed('temperature') |
| 58 | +print('loading fonts...') |
| 59 | +glyphs = b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.:/ ' |
55 | 60 |
|
56 | | -# init. graphics helper |
57 | | -gfx = wakeup_helper.Thermometer_GFX(celsius=False) |
| 61 | +time_font = bitmap_font.load_font(time_font) |
| 62 | +time_font.load_glyphs(glyphs) |
58 | 63 |
|
59 | | -# init. adt7410 |
60 | | -i2c_bus = busio.I2C(board.SCL, board.SDA) |
| 64 | +# Time |
| 65 | +time_text = Label( time_font, max_glyphs=40) |
| 66 | +time_text.x = 65 |
| 67 | +time_text.y = 120 |
| 68 | +text_group.append(time_text) |
| 69 | +board.DISPLAY.show(time_text) |
| 70 | + |
| 71 | +# Create an instance of the Adafruit IO REST client |
| 72 | +io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) |
61 | 73 |
|
62 | 74 | while True: |
63 | 75 | try: # WiFi Connection |
64 | | - # Get and display date and time form Adafruit IO |
| 76 | + # Get and display date and time from Adafruit IO |
65 | 77 | print('Getting time from Adafruit IO...') |
66 | 78 | datetime = io.receive_time() |
67 | 79 | print('displaying time...') |
68 | | - gfx.display_date_time(datetime) |
| 80 | + time_text.text = '%02d:%02d'%(datetime[3],datetime[4]) |
69 | 81 | except (ValueError, RuntimeError) as e: # WiFi Connection Failure |
70 | 82 | print("Failed to get data, retrying\n", e) |
71 | 83 | wifi.reset() |
|
0 commit comments