Simple test

Ensure your device works with this simple test.

examples/matrixportal_simpletest.py
 1# SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4"""
 5This example checks the current Bitcoin price and displays it in the middle of the screen
 6"""
 7
 8import time
 9
10import board
11import terminalio
12
13from adafruit_matrixportal.matrixportal import MatrixPortal
14
15# You can display in 'GBP', 'EUR' or 'USD'
16CURRENCY = "USD"
17# Set up where we'll be fetching data from
18DATA_SOURCE = "https://api.coindesk.com/v1/bpi/currentprice.json"
19DATA_LOCATION = ["bpi", CURRENCY, "rate_float"]
20
21
22def text_transform(val):
23    if CURRENCY == "USD":
24        return f"${val:d}"
25    if CURRENCY == "EUR":
26        return f"‎€{val:d}"
27    if CURRENCY == "GBP":
28        return f{val:d}"
29    return f"{val:d}"
30
31
32# the current working directory (where this file is)
33cwd = ("/" + __file__).rsplit("/", 1)[0]
34
35matrixportal = MatrixPortal(
36    url=DATA_SOURCE,
37    json_path=DATA_LOCATION,
38    status_neopixel=board.NEOPIXEL,
39)
40
41matrixportal.add_text(
42    text_font=terminalio.FONT,
43    text_position=(16, 16),
44    text_color=0xFFFFFF,
45    text_transform=text_transform,
46)
47matrixportal.preload_font(b"$012345789")  # preload numbers
48matrixportal.preload_font((0x00A3, 0x20AC))  # preload gbp/euro symbol
49
50while True:
51    try:
52        value = matrixportal.fetch()
53        print("Response is", value)
54    except (ValueError, RuntimeError) as e:
55        print("Some error occured, retrying! -", e)
56
57    time.sleep(3 * 60)  # wait 3 minutes

Other tests

Scrolling Bitcoin Test

examples/matrixportal_scrolling_bitcoin.py
 1# SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4"""
 5This example checks the current Bitcoin price and scrolls it across the screen
 6"""
 7
 8import time
 9
10import board
11import terminalio
12
13from adafruit_matrixportal.matrixportal import MatrixPortal
14
15# You can display in 'GBP', 'EUR' or 'USD'
16CURRENCY = "USD"
17# Set up where we'll be fetching data from
18DATA_SOURCE = "https://api.coindesk.com/v1/bpi/currentprice.json"
19DATA_LOCATION = ["bpi", CURRENCY, "rate_float"]
20
21
22def text_transform(val):
23    if CURRENCY == "USD":
24        return f"${val:d}"
25    if CURRENCY == "EUR":
26        return f"‎€{val:d}"
27    if CURRENCY == "GBP":
28        return f{val:d}"
29    return f"{val:d}"
30
31
32# the current working directory (where this file is)
33cwd = ("/" + __file__).rsplit("/", 1)[0]
34
35matrixportal = MatrixPortal(
36    url=DATA_SOURCE,
37    json_path=DATA_LOCATION,
38    status_neopixel=board.NEOPIXEL,
39)
40
41matrixportal.add_text(
42    text_font=terminalio.FONT,
43    text_position=(16, 16),
44    text_color=0xFFFFFF,
45    text_transform=text_transform,
46    scrolling=True,
47)
48matrixportal.preload_font(b"$012345789")  # preload numbers
49matrixportal.preload_font((0x00A3, 0x20AC))  # preload gbp/euro symbol
50
51last_check = None
52
53while True:
54    if last_check is None or time.monotonic() > last_check + 180:
55        try:
56            value = matrixportal.fetch()
57            print("Response is", value)
58            last_check = time.monotonic()
59        except (ValueError, RuntimeError) as e:
60            print("Some error occured, retrying! -", e)
61    matrixportal.scroll()
62    time.sleep(0.03)