Help displaying IO feed value on MatrixPortal

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
squirrel_oak
 
Posts: 22
Joined: Sun Sep 26, 2021 11:03 am

Help displaying IO feed value on MatrixPortal

Post by squirrel_oak »

I'm a beginner coder here.

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()


User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Help displaying IO feed value on MatrixPortal

Post by mikeysklar »

It looks like you are using get_io_feed() instead of get_io_data() in the code you provided.

Code: Select all

   try:
        weight_data = matrixportal.get_io_feed(WEIGHT_FEED)
        weight.clear()
Link to scrolling quotes example:

https://learn.adafruit.com/creating-pro ... e-examples

Code: Select all

try:
    quotes_data = matrixportal.get_io_data(QUOTES_FEED)
    quotes.clear()
    for json_data in quotes_data:
        quotes.append(matrixportal.network.json_traverse(json_data, ["value"]))
    print(quotes)
# pylint: disable=broad-except
except Exception as error:
    print(error)

try:
    color_data = matrixportal.get_io_data(COLORS_FEED)
    colors.clear()
    for json_data in color_data:
        colors.append(matrixportal.network.json_traverse(json_data, ["value"]))
    print(colors)
# pylint: disable=broad-except
except Exception as error:
    print(error)

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”