Trouble getting MatrixPortal to connect
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.
Please be positive and constructive with your questions and comments.

Trouble getting MatrixPortal to connect

by qarlwithaq on Wed May 05, 2021 12:16 am

I'm trying to get a tutorial project from Adabox 16 running but having some issues. I think it's an IO thing, but I might be wrong.

I'm following along with this guide
https://learn.adafruit.com/aio-quote-bo ... uote-board

And using this guide for the internet connection setup.
https://learn.adafruit.com/adafruit-mat ... et-connect

This is the secrets.py code I have
Code: Select all | TOGGLE FULL SIZE
# This file is where you keep secret settings, passwords, and tokens!
# If you put them in the code you risk committing that info or sharing it

secrets = {
    'ssid' : 'my actual wifi network name',
    'password' : 'my actual wifi network password',
    'timezone' : "America/New_York",  # http://worldtimeapi.org/timezones
    'aio_username' : 'my actual Adafruit IO username',
    'aio_key' : 'my actual Adafruit IO key',
# Write your code here :-)

And then test code on the internet connect guide works fine, I see bitcoin prices and a "This is a test of Adafruit WiFi! If you can read this, its working :)" message
Code: Select all | TOGGLE FULL SIZE
# SPDX-FileCopyrightText: 2019 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import board
import busio
from digitalio import DigitalInOut
import adafruit_requests as requests
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi

# Get wifi details and more from a secrets.py file
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")

print("ESP32 SPI webclient test")

TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"

# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

# If you have an AirLift Shield:
# esp32_cs = DigitalInOut(board.D10)
# esp32_ready = DigitalInOut(board.D7)
# esp32_reset = DigitalInOut(board.D5)

# If you have an AirLift Featherwing or ItsyBitsy Airlift:
# esp32_cs = DigitalInOut(board.D13)
# esp32_ready = DigitalInOut(board.D11)
# esp32_reset = DigitalInOut(board.D12)

# If you have an externally connected ESP32:
# NOTE: You may need to change the pins to reflect your wiring
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)

spi = busio.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("Firmware vers.", esp.firmware_version)
print("MAC addr:", [hex(i) for i in esp.MAC_address])

for ap in esp.scan_networks():
    print("\t%s\t\tRSSI: %d" % (str(ap["ssid"], "utf-8"), ap["rssi"]))

print("Connecting to AP...")
while not esp.is_connected:
        esp.connect_AP(secrets["ssid"], secrets["password"])
    except RuntimeError as e:
        print("could not connect to AP, retrying: ", e)
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
print("My IP address is", esp.pretty_ip(esp.ip_address))
    "IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))
print("Ping google.com: %d ms" % esp.ping("google.com"))

# esp._debug = True
print("Fetching text from", TEXT_URL)
r = requests.get(TEXT_URL)
print("-" * 40)
print("-" * 40)

print("Fetching json from", JSON_URL)
r = requests.get(JSON_URL)
print("-" * 40)
print("-" * 40)


And then this is the code I'm trying for my quotes:
Code: Select all | TOGGLE FULL SIZE
# Quote board matrix display
# uses AdafruitIO to serve up a quote text feed and color feed
# random quotes are displayed, updates periodically to look for new quotes
# avoids repeating the same quote twice in a row

import time
import random
import board
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal

# --- Display setup ---
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=True)

# Create a new label with the color and text selected
    text_position=(0, (matrixportal.graphics.display.height // 2) - 1),

# Static 'Connecting' Text
    text_position=(2, (matrixportal.graphics.display.height // 2) - 1),

QUOTES_FEED = "sign-quotes.signtext"
COLORS_FEED = "sign-quotes.signcolor"

quotes = []
colors = []
last_color = None
last_quote = None

def update_data():
    print("Updating data from Adafruit IO")
    matrixportal.set_text("Connecting", 1)

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

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

    if not quotes or not colors:
        raise RuntimeError("Please add at least one quote and color to your feeds")
    matrixportal.set_text(" ", 1)

last_update = time.monotonic()
matrixportal.set_text(" ", 1)
quote_index = None
color_index = None

while True:
    # Choose a random quote from quotes
    if len(quotes) > 1 and last_quote is not None:
        while quote_index == last_quote:
            quote_index = random.randrange(0, len(quotes))
        quote_index = random.randrange(0, len(quotes))
    last_quote = quote_index

    # Choose a random color from colors
    if len(colors) > 1 and last_color is not None:
        while color_index == last_color:
            color_index = random.randrange(0, len(colors))
        color_index = random.randrange(0, len(colors))
    last_color = color_index

    # Set the quote text

    # Set the text color

    # Scroll it

    if time.monotonic() > last_update + UPDATE_DELAY:
        last_update = time.monotonic()

And in the terminal/serial monitor of Mu, I get the following message after saving the code and resetting:
Code: Select all | TOGGLE FULL SIZE
Feed key must contain lower case English letters, numbers, and dash.
Feed key must contain lower case English letters, numbers, and dash.
Traceback (most recent call last):
  File "code.py", line 68, in <module>
  File "code.py", line 64, in update_data
RuntimeError: Please add at least one quote and color to your feeds

Code done running.
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.

Press any key to enter the REPL. Use CTRL-D to reload.

And it looks like an obvious problem, but I followed the Adafruit IO guide to the letter, so my feed names are correctly formatted with just lowercase letters and a single dash, and I have a few quotes and a few colors. I've triple-checked that my IO username and key are correct, and that everything is set up properly on my IO page, and it still isn't working.
Posts: 4
Joined: Thu Jan 30, 2014 2:01 am

Re: Trouble getting MatrixPortal to connect

by brubell on Wed May 05, 2021 11:17 am

Please upgrade your CircuitPython Adafruit IO library to the latest version on: https://github.com/adafruit/Adafruit_Ci ... O/releases

We just fixed a bug which people were having with Grouped feeds.

Posts: 1377
Joined: Fri Jul 17, 2015 10:33 pm

Re: Trouble getting MatrixPortal to connect

by qarlwithaq on Thu May 06, 2021 12:45 pm

That fixed it! Thanks so much!
Posts: 4
Joined: Thu Jan 30, 2014 2:01 am

Please be positive and constructive with your questions and comments.