0

Debugging MatrixPortal Issue
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Debugging MatrixPortal Issue

by sayvazov on Tue Apr 06, 2021 5:09 pm

Hi all,

I'm working with a MatrixPortal I got through one of the Adaboxes a little while ago and am at a loss as to what's going on here. I'm really just working with pretty simple behavior: I'm connecting to an Adafruit IO feed and displaying the data on an led matrix. My issue is: the MatrixPortal will work just fine for many hours at a time and at some point randomly starts error looping on a "RuntimeError: ESP32 timed out on SPI select."

I found a thread here and have gone through updating both the board and AirLift firmware, but still see it pop up. Any ideas as to what might be happening?

As a side question: is there a CircuitPython command to reset the board? Or even to reset the network connection? An error loop would be a lot less annoying to deal with if I could gracefully recover. As it is, I have to manually hit the reset button.

sayvazov
 
Posts: 7
Joined: Fri May 24, 2019 8:53 pm

Re: Debugging MatrixPortal Issue

by adafruit_support_carter on Tue Apr 06, 2021 5:31 pm

Sounds like something intermittent. So it might be network related. Or even AIO related if you are hitting an upload rate limit to your account. Would it work for your case to use a try/except to catch the error and retry?

You can hard reset with microcontroller.reset():
https://circuitpython.readthedocs.io/en ... ller.reset
and can soft reset with supervisor.reload():
https://circuitpython.readthedocs.io/en ... sor.reload

adafruit_support_carter
 
Posts: 20591
Joined: Tue Nov 29, 2016 2:45 pm

Re: Debugging MatrixPortal Issue

by sayvazov on Tue Apr 06, 2021 6:18 pm

adafruit_support_carter wrote:Sounds like something intermittent. So it might be network related. Or even AIO related if you are hitting an upload rate limit to your account. Would it work for your case to use a try/except to catch the error and retry?


That's what I'm currently doing. Once it gets one of these SPI errors, it never succeeds again. As in, it works for 8 hours doing the try/except loop and then doesn't work ever again.

I'll try the reset code, thanks!

sayvazov
 
Posts: 7
Joined: Fri May 24, 2019 8:53 pm

Re: Debugging MatrixPortal Issue

by adafruit_support_carter on Wed Apr 07, 2021 2:12 pm

FWIW, we just added a new Learn Guide page on resetting:
https://learn.adafruit.com/circuitpytho ... -resetting

adafruit_support_carter
 
Posts: 20591
Joined: Tue Nov 29, 2016 2:45 pm

Re: Debugging MatrixPortal Issue

by sayvazov on Thu May 13, 2021 5:06 pm

Hi, reviving this thread. I've been trying to to work on this for a little while now, but it seems using the reset code has revealed another issue. My MatrixPortal will sometimes just... hang. I thought at first it was a code issue, or a problem with the way I'm handling the reset, but it seems to just get stuck - when connected to my computer, it disappears as a drive as well. If I run a simple script that doesn't touch networking, this doesn't seem to happen. Digging around, I thought I had seen github issues of a similar nature, but I can't seem to find them now. Any ideas? It's also very possible I damaged the matrixportal at some point in the last 6 months and I should just get a new one, but thought I'd post again first.

sayvazov
 
Posts: 7
Joined: Fri May 24, 2019 8:53 pm

Re: Debugging MatrixPortal Issue

by adafruit_support_carter on Mon May 17, 2021 11:11 am

What if you completely remove code.py so there's nothing that gets run automatically. Can you get to the serial REPL OK?

adafruit_support_carter
 
Posts: 20591
Joined: Tue Nov 29, 2016 2:45 pm

Re: Debugging MatrixPortal Issue

by sayvazov on Sun Jun 20, 2021 5:19 pm

Coming back to this about a month late. Maybe I'm not describing the issue properly. I'm trying to get a sort of permanent display set up to show updates from an Adafruit IO stream. I've now tried with a second MatrixPortal and seeing a similar issue.

I can get it to work just fine for many hours, sometimes days at a time. But then, mysteriously and seemingly without reason, it would enter a loop of errors. On the previous MatrixPortal, this would be a completely inexplicable error, where it would just... disappear. It disappears as an attached device to my PC, doesn't update the display, serial stream just ends. The new MatrixPortal seems to enter an error loop of "Repeated Socket Failure" and no amount of software resetting seems to help. I can't quite figure out what effect microcontroller.reset() has, because I have to eject it from my PC as per the suggestion. However, in all of these cases, hitting the reset switch gets it working just fine.

sayvazov
 
Posts: 7
Joined: Fri May 24, 2019 8:53 pm

Re: Debugging MatrixPortal Issue

by adafruit_support_carter on Tue Jun 22, 2021 11:09 am

These seems like potentially two different issues.

My issue is: the MatrixPortal will work just fine for many hours at a time and at some point randomly starts error looping on a "RuntimeError: ESP32 timed out on SPI select."

This sounds like a basic issue talking to the ESP32 over SPI. That is not network related. It's how the main controller talks to the ESP32.

The new MatrixPortal seems to enter an error loop of "Repeated Socket Failure"

This sounds like an intermittent network issue. The controller is talking to the ESP32 just fine, but something is happening at the network level.

Are these issues specific to the two different MatrixPortals?

adafruit_support_carter
 
Posts: 20591
Joined: Tue Nov 29, 2016 2:45 pm

Re: Debugging MatrixPortal Issue

by sayvazov on Thu Jun 24, 2021 5:27 pm

No, at this point, some different combination of these errors (and the seemingly separate matrixportal just crashes and needs to be manually reset problem) has happened to both boards. I haven't done it with the new board yet, but the older one I had tried updating the CircuitPython version, the AirLift firmware, and the library versions. Seems like no luck, though I can't promise I saw every issue with every combination.

Is the arduino code perhaps different enough that rewriting to that API would allow me to avoid what's clearly a problematic code path? Or is there something that I'm doing in the code that could be causing this? My only call to any networking code is an "io.receive_data" call. I tried looking through Github, but didn't see any open issues that lined up with what I'm seeing, but am admittedly not experienced enough in networking to really be sure.

sayvazov
 
Posts: 7
Joined: Fri May 24, 2019 8:53 pm

Re: Debugging MatrixPortal Issue

by adafruit_support_carter on Thu Jun 24, 2021 5:46 pm

See if you can come up with the smallest demo that shows the issue and post the complete code listing here.

adafruit_support_carter
 
Posts: 20591
Joined: Tue Nov 29, 2016 2:45 pm

Re: Debugging MatrixPortal Issue

by sayvazov on Sun Jul 11, 2021 4:59 pm

Sure. You'll need the normal secrets.py for your network and a corresponding adafruit io feed - creatively called "counter" but the following is as minimal as I can get it while using the same calls. And obviously corresponding libraries.

Code: Select all | TOGGLE FULL SIZE
import terminalio
import time
import microcontroller

import adafruit_requests as requests
from adafruit_matrixportal.matrixportal import MatrixPortal
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError

UPDATE_FREQUENCY = 1  # 15 seconds

print("Initializing internet connection." )
try:
    from secrets import secrets
except ImportError:
    print("Failed to load wifi details from secrets.")
    raise

TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
matrixportal = MatrixPortal()

# Setup Text
matrixportal.add_text(text_font=terminalio.FONT,
                      text_position=(3, 4), scrolling=False, text_scale = 0.15)

matrixportal.add_text(text_font=terminalio.FONT,
                      text_position=(3, 15), scrolling=False, text_scale = 0.15)

matrixportal.set_text("Counter", 0)
matrixportal.set_text("Timer", 0)

# Set up networking.
try:
    matrixportal.network.connect()
except:
    print("Failed to connect to wifi")
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]
# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(aio_username, aio_key, requests)
feed = io.get_feed("counter")

last_update = time.monotonic()


# ACTUAL MAIN LOOP.
format = "%Y-%m-%d %T"
last_update = time.monotonic()
first_update = last_update
while True:
    print("Loop Start ")
    time.sleep(2)
    time_from_update = time.monotonic() - last_update
    last_update = time.monotonic()
    time_from_start = last_update - first_update
    print(time_from_start)
    try:
        print("I'm working!")
        received_data = io.receive_data(feed["key"])
        new_data = received_data["value"]
        matrixportal.set_text(f"{str(new_data)} count", 0)
        matrixportal.set_text(f"{str(time_from_start)} time", 1)
    except Exception as e:
        print("Exception")
        print (e)

print("Somehow exited a forever loop")

sayvazov
 
Posts: 7
Joined: Fri May 24, 2019 8:53 pm

Re: Debugging MatrixPortal Issue

by adafruit_support_carter on Mon Jul 12, 2021 12:27 pm

Thanks. And the output when you hit the issue is something like:
Code: Select all | TOGGLE FULL SIZE
Loop Start
{some time stamp here}
I'm working!
Exception
Repeated Socket Failure

forever in a loop? Printing out every 2 seconds?

adafruit_support_carter
 
Posts: 20591
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.