Skip to content

Commit 108f763

Browse files
committed
adding cp and python demo code
1 parent c1c2897 commit 108f763

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed
Binary file not shown.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import board
6+
import time
7+
import displayio
8+
import terminalio
9+
from adafruit_display_text.bitmap_label import Label
10+
import adafruit_imageload
11+
from fourwire import FourWire
12+
from vectorio import Circle
13+
from adafruit_gc9a01a import GC9A01A
14+
15+
spi = board.SPI()
16+
tft_cs = board.D5
17+
tft_dc = board.D6
18+
tft_reset = board.D9
19+
20+
displayio.release_displays()
21+
22+
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset)
23+
display = GC9A01A(display_bus, width=240, height=240)
24+
25+
# --- Default Shapes/Text Demo ---
26+
main_group = displayio.Group()
27+
display.root_group = main_group
28+
29+
bg_bitmap = displayio.Bitmap(240, 240, 2)
30+
color_palette = displayio.Palette(2)
31+
color_palette[0] = 0x00FF00 # Bright Green
32+
color_palette[1] = 0xAA0088 # Purple
33+
34+
bg_sprite = displayio.TileGrid(bg_bitmap, pixel_shader=color_palette, x=0, y=0)
35+
main_group.append(bg_sprite)
36+
37+
inner_circle = Circle(pixel_shader=color_palette, x=120, y=120, radius=100, color_index=1)
38+
main_group.append(inner_circle)
39+
40+
text_group = displayio.Group(scale=2, x=50, y=120)
41+
text = "Hello World!"
42+
text_area = Label(terminalio.FONT, text=text, color=0xFFFF00)
43+
text_group.append(text_area) # Subgroup for text scaling
44+
main_group.append(text_group)
45+
46+
# --- ImageLoad Demo ---
47+
blinka_group = displayio.Group()
48+
bitmap, palette = adafruit_imageload.load("/blinka_round.bmp",
49+
bitmap=displayio.Bitmap,
50+
palette=displayio.Palette)
51+
52+
grid = displayio.TileGrid(bitmap, pixel_shader=palette)
53+
blinka_group.append(grid)
54+
55+
while True:
56+
# show shapes/text
57+
display.root_group = main_group
58+
time.sleep(2)
59+
# show blinka bitmap
60+
display.root_group = blinka_group
61+
time.sleep(2)
Loading
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
2+
# SPDX-FileCopyrightText: Adapted from Melissa LeBlanc-Williams's Pi Demo Code
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
'''Raspberry Pi Graphics example for the 240x240 Round TFT'''
7+
8+
import time
9+
import digitalio
10+
import board
11+
from PIL import Image, ImageDraw, ImageFont
12+
from adafruit_rgb_display import gc9a01a
13+
14+
BORDER = 20
15+
FONTSIZE = 24
16+
17+
cs_pin = digitalio.DigitalInOut(board.CE0)
18+
dc_pin = digitalio.DigitalInOut(board.D25)
19+
reset_pin = digitalio.DigitalInOut(board.D27)
20+
21+
BAUDRATE = 24000000
22+
23+
spi = board.SPI()
24+
25+
disp = gc9a01a.GC9A01A(spi, rotation=180,
26+
width=135, height=240,
27+
x_offset=53, y_offset=40,
28+
cs=cs_pin,
29+
dc=dc_pin,
30+
rst=reset_pin,
31+
baudrate=BAUDRATE,
32+
)
33+
34+
width = disp.width
35+
height = disp.height
36+
37+
# -------TEXT AND SHAPES---------
38+
image1 = Image.new("RGB", (width, height))
39+
draw1 = ImageDraw.Draw(image1)
40+
draw1.rectangle((0, 0, width, height), fill=(0, 255, 0)) # Green background
41+
42+
draw1.rectangle(
43+
(BORDER, BORDER, width - BORDER - 1, height - BORDER - 1), fill=(170, 0, 136)
44+
)
45+
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", FONTSIZE)
46+
text = "Hello\nWorld!"
47+
(font_width, font_height) = font.getsize(text)
48+
draw1.text(
49+
(30, height // 2 - font_height // 2-12),
50+
text,
51+
font=font,
52+
fill=(255, 255, 0),
53+
)
54+
55+
# ------BLINKA JPEG DISPLAY----------
56+
image2 = Image.open("blinka_round.jpg")
57+
image_ratio = image2.width / image2.height
58+
screen_ratio = width / height
59+
scaled_width = width
60+
scaled_height = image2.height * width // image2.width
61+
image2 = image2.resize((scaled_width, scaled_height), Image.BICUBIC)
62+
x = scaled_width // 2 - width // 2
63+
y = scaled_height // 2 - height // 2
64+
image2 = image2.crop((x, y, x + width, y + height))
65+
66+
while True:
67+
disp.image(image1) # show text
68+
time.sleep(2)
69+
disp.image(image2) # show blinka
70+
time.sleep(2)

0 commit comments

Comments
 (0)