Skip to content

Instantly share code, notes, and snippets.

@joeycastillo
Created August 14, 2020 18:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeycastillo/a2ef23566188c3e1bce9268421a7794d to your computer and use it in GitHub Desktop.
Save joeycastillo/a2ef23566188c3e1bce9268421a7794d to your computer and use it in GitHub Desktop.
the big board of death
import adafruit_ht16k33.segments
import board
from digitalio import DigitalInOut, Direction
import time
from busio import I2C, SPI
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
JSON_URL = "http://thebigboard.cc/feeds/v1/scoreboard.json"
# connect to wifi
esp32_cs = DigitalInOut(board.D13)
esp32_ready = DigitalInOut(board.D11)
esp32_reset = DigitalInOut(board.D12)
spi = SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
requests.set_socket(socket, esp)
if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
print("ESP32 found and in idle mode")
print("Connecting to AP...")
while not esp.is_connected:
try:
esp.connect_AP(secrets["ssid"], secrets["password"])
except RuntimeError as e:
print("could not connect to AP, retrying: ", e)
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
# set up displays
for pin in [board.D5, board.D6, board.D9, board.D10]:
enable = DigitalInOut(pin)
enable.direction = Direction.OUTPUT
enable.value = True
time.sleep(1)
i2c_1 = board.I2C()
i2c_2 = I2C(board.A3, board.A2)
i2c_3 = I2C(board.RX, board.TX)
i2c_4 = I2C(board.A1, board.A4)
brightnesses = [0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.15, 0.15, 0.15, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
displays = list()
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_1, address=0x70))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_1, address=0x71))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_1, address=0x72))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_1, address=0x74))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_1, address=0x75))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_1, address=0x76))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_2, address=0x70))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_2, address=0x71))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_2, address=0x72))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_2, address=0x74))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_2, address=0x75))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_2, address=0x76))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_3, address=0x70))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_3, address=0x71))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_3, address=0x72))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_3, address=0x74))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_3, address=0x75))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_3, address=0x76))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_4, address=0x70))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_4, address=0x71))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_4, address=0x72))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_4, address=0x74))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_4, address=0x75))
except ValueError:
displays.append(None)
try:
displays.append(adafruit_ht16k33.segments.Seg14x4(i2c_4, address=0x76))
except ValueError:
displays.append(None)
while True:
print("Fetching json from", JSON_URL)
r = requests.get(JSON_URL)
bigboard = r.json()
r.close()
print("Got standings updated at", bigboard["updated"])
standings = bigboard["standings"]
covid_index = 0
for entry in standings:
if entry["cause"] == "COVID-19":
break
covid_index += 1
lines = []
for i in range(covid_index - 3, covid_index + 4):
lines.append("{0: <16}{1: >8}".format(standings[i]["cause"], standings[i]["deaths"]))
for i in range(0, len(displays)):
display = displays[i]
if display is not None:
display.brightness = brightnesses[i]
display.fill(0)
display_index = 0
for i in range(0, len(lines)):
line = lines[i]
for j in range(0, 3):
if displays[display_index] is not None:
s = lines[i][j * 8:(j + 1) * 8]
displays[display_index].print(s)
j += 1
display_index += 1
print("Display updated")
time.sleep(60 * 30) # wait half an hour before next update
--- /Users/joeycastillo/Downloads/Adafruit_CircuitPython_HT16K33-master/adafruit_ht16k33/segments.py 2020-04-09 09:34:36.000000000 -0400
+++ /Volumes/CIRCUITPY/lib/adafruit_ht16k33/segments.py 2020-07-15 21:45:10.000000000 -0400
@@ -184,12 +184,12 @@
offset = 0
else:
offset = 2
- for i in range(6):
+ for i in range(14):
self._set_buffer(i + offset, self._get_buffer(i + 2 * count))
def _put(self, char, index=0):
"""Put a character at the specified place."""
- if not 0 <= index <= 3:
+ if not 0 <= index <= 7:
return
if not 32 <= ord(char) <= 127:
return
@@ -206,8 +206,8 @@
"""Scroll the display and add a character at the end."""
if char != "." or self._get_buffer(7) & 0b01000000:
self.scroll()
- self._put(" ", 3)
- self._put(char, 3)
+ self._put(" ", 7)
+ self._put(char, 7)
def _text(self, text):
"""Display the specified text."""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment