Simple test¶
Ensure your device works with this simple test.
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"""
7import time
8import board
9import terminalio
10from adafruit_matrixportal.matrixportal import MatrixPortal
11
12# You can display in 'GBP', 'EUR' or 'USD'
13CURRENCY = "USD"
14# Set up where we'll be fetching data from
15DATA_SOURCE = "https://api.coindesk.com/v1/bpi/currentprice.json"
16DATA_LOCATION = ["bpi", CURRENCY, "rate_float"]
17
18
19def text_transform(val):
20 if CURRENCY == "USD":
21 return "$%d" % val
22 if CURRENCY == "EUR":
23 return "€%d" % val
24 if CURRENCY == "GBP":
25 return "£%d" % val
26 return "%d" % val
27
28
29# the current working directory (where this file is)
30cwd = ("/" + __file__).rsplit("/", 1)[0]
31
32matrixportal = MatrixPortal(
33 url=DATA_SOURCE,
34 json_path=DATA_LOCATION,
35 status_neopixel=board.NEOPIXEL,
36)
37
38matrixportal.add_text(
39 text_font=terminalio.FONT,
40 text_position=(16, 16),
41 text_color=0xFFFFFF,
42 text_transform=text_transform,
43)
44matrixportal.preload_font(b"$012345789") # preload numbers
45matrixportal.preload_font((0x00A3, 0x20AC)) # preload gbp/euro symbol
46
47while True:
48 try:
49 value = matrixportal.fetch()
50 print("Response is", value)
51 except (ValueError, RuntimeError) as e:
52 print("Some error occured, retrying! -", e)
53
54 time.sleep(3 * 60) # wait 3 minutes
Other tests¶
Scrolling Bitcoin Test
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"""
7import time
8import board
9import terminalio
10from adafruit_matrixportal.matrixportal import MatrixPortal
11
12# You can display in 'GBP', 'EUR' or 'USD'
13CURRENCY = "USD"
14# Set up where we'll be fetching data from
15DATA_SOURCE = "https://api.coindesk.com/v1/bpi/currentprice.json"
16DATA_LOCATION = ["bpi", CURRENCY, "rate_float"]
17
18
19def text_transform(val):
20 if CURRENCY == "USD":
21 return "$%d" % val
22 if CURRENCY == "EUR":
23 return "€%d" % val
24 if CURRENCY == "GBP":
25 return "£%d" % val
26 return "%d" % val
27
28
29# the current working directory (where this file is)
30cwd = ("/" + __file__).rsplit("/", 1)[0]
31
32matrixportal = MatrixPortal(
33 url=DATA_SOURCE,
34 json_path=DATA_LOCATION,
35 status_neopixel=board.NEOPIXEL,
36)
37
38matrixportal.add_text(
39 text_font=terminalio.FONT,
40 text_position=(16, 16),
41 text_color=0xFFFFFF,
42 text_transform=text_transform,
43 scrolling=True,
44)
45matrixportal.preload_font(b"$012345789") # preload numbers
46matrixportal.preload_font((0x00A3, 0x20AC)) # preload gbp/euro symbol
47
48last_check = None
49
50while True:
51 if last_check is None or time.monotonic() > last_check + 180:
52 try:
53 value = matrixportal.fetch()
54 print("Response is", value)
55 last_check = time.monotonic()
56 except (ValueError, RuntimeError) as e:
57 print("Some error occured, retrying! -", e)
58 matrixportal.scroll()
59 time.sleep(0.03)