Simple test

Ensure your device works with this simple test.

examples/qualia_simpletest.py
 1# SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4#
 5# NOTE: Make sure you've set up your settings.toml file before running this example
 6# https://learn.adafruit.com/getting-started-with-web-workflow-using-the-code-editor/
 7
 8from adafruit_qualia import Qualia
 9from adafruit_qualia.graphics import Displays
10
11# Set a data source URL
12TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
13
14# Create the Qualia object
15qualia = Qualia(Displays.SQUARE34, url=TEXT_URL)
16
17# Go get that data
18print("Fetching text from", TEXT_URL)
19data = qualia.fetch()
20
21# Print out what we got
22print("-" * 40)
23print(data)
24print("-" * 40)

Other Examples

PyPortal like usage with this quotes demo.

examples/qualia_quotes.py
 1# SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries
 2# SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams for Adafruit Industries
 3#
 4# SPDX-License-Identifier: MIT
 5
 6import time
 7
 8from adafruit_qualia import Qualia
 9from adafruit_qualia.graphics import Displays
10
11# Set up where we'll be fetching data from
12DATA_SOURCE = "https://www.adafruit.com/api/quotes.php"
13QUOTE_LOCATION = [0, "text"]
14AUTHOR_LOCATION = [0, "author"]
15
16qualia = Qualia(
17    Displays.SQUARE34,
18    url=DATA_SOURCE,
19    json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
20    default_bg=0x333333,
21)
22
23qualia.add_text(
24    text_position=(20, 120),  # quote location
25    text_color=0xFFFFFF,  # quote text color
26    text_wrap=25,  # characters to wrap for quote
27    text_maxlen=180,  # max text size for quote
28    text_scale=3,  # quote text size
29)
30
31qualia.add_text(
32    text_position=(5, 240),  # author location
33    text_color=0x8080FF,  # author text color
34    text_wrap=0,  # no wrap for author
35    text_maxlen=180,  # max text size for quote & author
36    text_scale=3,  # author text size
37)
38
39while True:
40    try:
41        value = qualia.fetch()
42        print("Response is", value)
43    except (ValueError, RuntimeError, ConnectionError, OSError) as e:
44        print("Some error occured, retrying! -", e)
45    time.sleep(60)

Generate and Center a QR code on the display and shows peripheral usage.

examples/qualia_qrcode_generation.py
 1# SPDX-FileCopyrightText: 2021 Jose David M.
 2# SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams for Adafruit Industries
 3#
 4# SPDX-License-Identifier: MIT
 5
 6# NOTE: Make sure you've set up your settings.toml file before running this example
 7# https://learn.adafruit.com/getting-started-with-web-workflow-using-the-code-editor/
 8"""
 9This example shows a web address QR on the display
10"""
11
12import time
13
14from adafruit_qualia.graphics import Displays, Graphics
15from adafruit_qualia.peripherals import Peripherals
16
17# Background Information
18base = Graphics(Displays.ROUND21, default_bg=0x990099)
19
20# Set up Peripherals
21peripherals = Peripherals(i2c_bus=base.i2c_bus)
22
23# Set display to show
24display = base.display
25
26# WebPage to show in the QR
27webpage = "http://www.adafruit.com"
28
29# QR size Information
30qr_size = 9  # Pixels
31scale = 10
32
33# Create a barcode
34base.qrcode(
35    webpage,
36    qr_size=scale,
37    x=(display.width // 2) - ((qr_size + 5) * scale),
38    y=(display.height // 2) - ((qr_size + 4) * scale),
39)
40
41while True:
42    if peripherals.button_up:
43        peripherals.backlight = True
44    if peripherals.button_down:
45        peripherals.backlight = False
46    time.sleep(0.1)

Simple paint demo that works with multiple displays. Touchscreen required.

examples/qualia_paint.py
 1# SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3"""
 4Simple painting demo that works with on any touch display
 5"""
 6
 7import displayio
 8
 9from adafruit_qualia.graphics import Displays, Graphics
10
11# For other displays:
12# 2.1" Round = Displays.ROUND21
13# 3.4" Square = Displays.SQUARE34
14# 320 x 820 Bar - Displays.BAR320X820
15# 320 x 960 Bar - Displays.BAR320X960
16graphics = Graphics(Displays.SQUARE40, default_bg=None, auto_refresh=False)
17
18if graphics.touch is None:
19    raise RuntimeError("This example requires a touch screen.")
20
21# Main Program
22pixel_size = 6
23palette_width = 160
24palette_height = graphics.display.height // 8
25
26bitmap = displayio.Bitmap(graphics.display.width, graphics.display.height, 65535)
27
28# Create a TileGrid to hold the bitmap
29tile_grid = displayio.TileGrid(
30    bitmap,
31    pixel_shader=displayio.ColorConverter(input_colorspace=displayio.Colorspace.RGB565),
32)
33
34# Add the TileGrid to the Group
35graphics.root_group.append(tile_grid)
36
37# Add the Group to the Display
38graphics.display.root_group = graphics.root_group
39
40current_color = displayio.ColorConverter().convert(0xFFFFFF)
41
42for i in range(palette_width):
43    color_index = i * 255 // palette_width
44    rgb565 = displayio.ColorConverter().convert(color_index | color_index << 8 | color_index << 16)
45    r_mask = 0xF800
46    g_mask = 0x07E0
47    b_mask = 0x001F
48    for j in range(palette_height):
49        bitmap[i, j + palette_height] = rgb565 & b_mask
50        bitmap[i, j + palette_height * 2] = rgb565 & (b_mask | g_mask)
51        bitmap[i, j + palette_height * 3] = rgb565 & g_mask
52        bitmap[i, j + palette_height * 4] = rgb565 & (r_mask | g_mask)
53        bitmap[i, j + palette_height * 5] = rgb565 & r_mask
54        bitmap[i, j + palette_height * 6] = rgb565 & (r_mask | b_mask)
55        bitmap[i, j + palette_height * 7] = rgb565
56
57graphics.display.auto_refresh = True
58
59while True:
60    if graphics.touch.touched:
61        try:
62            for touch in graphics.touch.touches:
63                x = touch["x"]
64                y = touch["y"]
65                if not 0 <= x < graphics.display.width or not 0 <= y < graphics.display.height:
66                    continue  # Skip out of bounds touches
67                if x < palette_width:
68                    current_color = bitmap[x, y]
69                else:
70                    for i in range(pixel_size):
71                        for j in range(pixel_size):
72                            x_pixel = x - (pixel_size // 2) + i
73                            y_pixel = y - (pixel_size // 2) + j
74
75                            if (
76                                0 <= x_pixel < graphics.display.width
77                                and 0 <= y_pixel < graphics.display.height
78                            ):
79                                bitmap[x_pixel, y_pixel] = current_color
80        except RuntimeError:
81            pass