Simple test¶
Ensure your device works with this simple test.
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.
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
7from adafruit_qualia import Qualia
8from adafruit_qualia.graphics import Displays
9
10# Set up where we'll be fetching data from
11DATA_SOURCE = "https://www.adafruit.com/api/quotes.php"
12QUOTE_LOCATION = [0, "text"]
13AUTHOR_LOCATION = [0, "author"]
14
15qualia = Qualia(
16 Displays.SQUARE34,
17 url=DATA_SOURCE,
18 json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
19 default_bg=0x333333,
20)
21
22qualia.add_text(
23 text_position=(20, 120), # quote location
24 text_color=0xFFFFFF, # quote text color
25 text_wrap=25, # characters to wrap for quote
26 text_maxlen=180, # max text size for quote
27 text_scale=3, # quote text size
28)
29
30qualia.add_text(
31 text_position=(5, 240), # author location
32 text_color=0x8080FF, # author text color
33 text_wrap=0, # no wrap for author
34 text_maxlen=180, # max text size for quote & author
35 text_scale=3, # author text size
36)
37
38while True:
39 try:
40 value = qualia.fetch()
41 print("Response is", value)
42 except (ValueError, RuntimeError, ConnectionError, OSError) as e:
43 print("Some error occured, retrying! -", e)
44 time.sleep(60)
Generate and Center a QR code on the display and shows peripheral usage.
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
13from adafruit_qualia.graphics import Graphics, Displays
14from adafruit_qualia.peripherals import Peripherals
15
16# Background Information
17base = Graphics(Displays.ROUND21, default_bg=0x990099)
18
19# Set up Peripherals
20peripherals = Peripherals(i2c_bus=base.i2c_bus)
21
22# Set display to show
23display = base.display
24
25# WebPage to show in the QR
26webpage = "http://www.adafruit.com"
27
28# QR size Information
29qr_size = 9 # Pixels
30scale = 10
31
32# Create a barcode
33base.qrcode(
34 webpage,
35 qr_size=scale,
36 x=(display.width // 2) - ((qr_size + 5) * scale),
37 y=(display.height // 2) - ((qr_size + 4) * scale),
38)
39
40while True:
41 if peripherals.button_up:
42 peripherals.backlight = True
43 if peripherals.button_down:
44 peripherals.backlight = False
45 time.sleep(0.1)
Simple paint demo that works with multiple displays. Touchscreen required.
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"""
6import displayio
7from adafruit_qualia.graphics import Graphics, Displays
8
9# For other displays:
10# 2.1" Round = Displays.ROUND21
11# 3.4" Square = Displays.SQUARE34
12# 320 x 820 Bar - Displays.BAR320X820
13graphics = Graphics(Displays.SQUARE40, default_bg=None, auto_refresh=False)
14
15if graphics.touch is None:
16 raise RuntimeError("This example requires a touch screen.")
17
18# Main Program
19pixel_size = 6
20palette_width = 160
21palette_height = graphics.display.height // 8
22
23bitmap = displayio.Bitmap(graphics.display.width, graphics.display.height, 65535)
24
25# Create a TileGrid to hold the bitmap
26tile_grid = displayio.TileGrid(
27 bitmap,
28 pixel_shader=displayio.ColorConverter(input_colorspace=displayio.Colorspace.RGB565),
29)
30
31# Add the TileGrid to the Group
32graphics.splash.append(tile_grid)
33
34# Add the Group to the Display
35graphics.display.root_group = graphics.splash
36
37current_color = displayio.ColorConverter().convert(0xFFFFFF)
38
39for i in range(palette_width):
40 color_index = i * 255 // palette_width
41 rgb565 = displayio.ColorConverter().convert(
42 color_index | color_index << 8 | color_index << 16
43 )
44 r_mask = 0xF800
45 g_mask = 0x07E0
46 b_mask = 0x001F
47 for j in range(palette_height):
48 bitmap[i, j + palette_height] = rgb565 & b_mask
49 bitmap[i, j + palette_height * 2] = rgb565 & (b_mask | g_mask)
50 bitmap[i, j + palette_height * 3] = rgb565 & g_mask
51 bitmap[i, j + palette_height * 4] = rgb565 & (r_mask | g_mask)
52 bitmap[i, j + palette_height * 5] = rgb565 & r_mask
53 bitmap[i, j + palette_height * 6] = rgb565 & (r_mask | b_mask)
54 bitmap[i, j + palette_height * 7] = rgb565
55
56graphics.display.auto_refresh = True
57
58while True:
59 if graphics.touch.touched:
60 try:
61 for touch in graphics.touch.touches:
62 x = touch["x"]
63 y = touch["y"]
64 if (
65 not 0 <= x < graphics.display.width
66 or not 0 <= y < graphics.display.height
67 ):
68 continue # Skip out of bounds touches
69 if x < palette_width:
70 current_color = bitmap[x, y]
71 else:
72 for i in range(pixel_size):
73 for j in range(pixel_size):
74 x_pixel = x - (pixel_size // 2) + i
75 y_pixel = y - (pixel_size // 2) + j
76
77 if (
78 0 <= x_pixel < graphics.display.width
79 and 0 <= y_pixel < graphics.display.height
80 ):
81 bitmap[x_pixel, y_pixel] = current_color
82 except RuntimeError:
83 pass