My project description as simple as possible: I'm trying to send weight data to be displayed on a Matrix Portal through Adafruit IO. (A blinky smart scale)
I have the first part of the project working: I am successfully sending accurate weight data to an IO feed using a Raspberry PI, Python 3, and an HX711 load sensor. The graph on the Adafruit IO website looks great, and it is exactly what I need to move on to the next part (a recently updated weight value to scroll across the matrix).
I'm trying to follow the tutorial based on the "scrolling quotes" project because it uses the matrix portal, and IO. However, I'm getting tripped up pulling the most recent weight data and simply scrolling it across the matrix. Sometimes I can get the "matrixportal.get_io_data" command to pull down everything in the feed, and cause a memory buffer error. (but at least it is something!). Usually, I get a definition error or display a non-variable string with the matrixportal.set_text command.
I feel that I'm really close, but need a helpful tip or two. THANKS!
Code: Select all
"""
# This hacked code checks the current weight on squirrel oak's scale and scrolls it across the screen
"""
import time
import terminalio
import board
#import adafruit_requests as requests
from adafruit_io.adafruit_io import IO_HTTP
from adafruit_matrixportal.matrixportal import MatrixPortal
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=True)
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
matrixportal.add_text(
text_font=terminalio.FONT,
text_position=(0, (matrixportal.graphics.display.height // 2) - 1),
scrolling=True,
)
# Static 'Connecting' Text
matrixportal.add_text(
text_font=terminalio.FONT,
text_position=(2, (matrixportal.graphics.display.height // 2) - 1),
)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]
WEIGHT_FEED = "mailbox.weight"
SCROLL_DELAY = 0.02
UPDATE_DELAY = 100
weight = "weight_data"
def update_data():
print("Updating data from Adafruit IO")
matrixportal.set_text("Connecting", 1)
try:
weight_data = matrixportal.get_io_feed(WEIGHT_FEED)
weight.clear()
for json_data in weight_data:
weight.append(matrixportal.network.json_traverse(json_data, ["value"]))
print(weight_data)
except Exception as error:
print(error)
update_data()
last_update = time.monotonic()
matrixportal.set_text(" ", 1)
while True:
matrixportal.set_text(weight)
matrixportal.set_text_color(0x3361FF)
matrixportal.scroll_text(SCROLL_DELAY)
if time.monotonic() > last_update + UPDATE_DELAY:
update_data()
last_update = time.monotonic()