Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Need Help on Matrix portal M4 MicroPython
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Need Help on Matrix portal M4 MicroPython

by mariocruz on Tue Nov 24, 2020 5:08 pm

Cant show 2 Json objects in a scrolling text. I get an error "tuple to int"

Code: Select all | TOGGLE FULL SIZE
  File "code.py", line 35, in <module>
  File "code.py", line 31, in <module>
  File "adafruit_matrixportal/matrixportal.py", line 432, in fetch
  File "adafruit_matrixportal/matrixportal.py", line 287, in set_text
TypeError: can't convert tuple to int


Code:-----------
Code: Select all | TOGGLE FULL SIZE
import time
import board
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal

# Testing getting back Quotes
DATA_SOURCE = "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=IBM&apikey=Demo"
DATA_LOCATION = ["Global Quote","05. price"]
DATA_VOL = ["Global Quote","06. volume"]

# the current working directory (where this file is)
cwd = ("/" + __file__).rsplit("/", 1)[0]

matrixportal = MatrixPortal(
    url=DATA_SOURCE, json_path=(DATA_LOCATION,DATA_VOL), status_neopixel=board.NEOPIXEL,
)

matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=((1, 20),(2,30)),
    #text_position=(1, 20),
    text_color=(0xFFFFFF),
    scrolling=True,
)

last_check = None

while True:
    if last_check is None or time.monotonic() > last_check + 180:
        try:
            value = matrixportal.fetch()
            print("Response is",value)
            last_check = time.monotonic()
        except (ValueError, RuntimeError) as e:
            print("Some error occured, retrying! -", e)
    matrixportal.scroll()
    time.sleep(.01)

mariocruz
 
Posts: 3
Joined: Fri May 13, 2016 2:04 pm

Re: Need Help on Matrix portal M4 MicroPython

by dastels on Tue Nov 24, 2020 5:21 pm

I'm looking into this. Will report back in a bit.

Dave

dastels
 
Posts: 6070
Joined: Tue Oct 20, 2015 3:22 pm

Re: Need Help on Matrix portal M4 MicroPython

by dastels on Tue Nov 24, 2020 6:04 pm

You need to add two separate text areas. I.e. call matrixportal.add_text() twice.

Dave

dastels
 
Posts: 6070
Joined: Tue Oct 20, 2015 3:22 pm

Re: Need Help on Matrix portal M4 MicroPython

by mariocruz on Tue Nov 24, 2020 6:06 pm

Thanks for yer quick reply will try that.

mariocruz
 
Posts: 3
Joined: Fri May 13, 2016 2:04 pm

Re: Need Help on Matrix portal M4 MicroPython

by mariocruz on Tue Nov 24, 2020 9:45 pm

Here is the code fixed in case anyone finds this post later Thank you @dastels:
Code: Select all | TOGGLE FULL SIZE
 
import time
import board
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal

# Testing getting back Stock Quotes
DATA_SOURCE = "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=IBM&apikey=Demo"
DATA_LOCATION = ["Global Quote","05. price"]
DATA_VOL = ["Global Quote","06. volume"]

# the current working directory (where this file is)
cwd = ("/" + __file__).rsplit("/", 1)[0]

matrixportal = MatrixPortal(
    url=DATA_SOURCE, json_path=(DATA_LOCATION,DATA_VOL), status_neopixel=board.NEOPIXEL,
)

matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(1, 10),
    text_color=(0xAA0000),
    scrolling=True,
)

matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(1, 25),
    text_color=(0x0000AA),
    scrolling=True,
)

last_check = None

while True:
    if last_check is None or time.monotonic() > last_check + 180:
        try:
            value = matrixportal.fetch()
            print("Response is",value)
            last_check = time.monotonic()
        except (ValueError, RuntimeError) as e:
            print("Some error occured, retrying! -", e)
    matrixportal.scroll()
    time.sleep(.0155)

mariocruz
 
Posts: 3
Joined: Fri May 13, 2016 2:04 pm

Please be positive and constructive with your questions and comments.