Skip to content

Commit 7a07f5f

Browse files
authored
Merge pull request #673 from caternuson/displayio_examples
CircuitPython displayio examples
2 parents 2b2bd39 + 6011a75 commit 7a07f5f

14 files changed

Lines changed: 4593 additions & 0 deletions

CircuitPython_displayio/Helvetica-Bold-16.bdf

Lines changed: 4194 additions & 0 deletions
Large diffs are not rendered by default.
3.19 KB
Binary file not shown.
1.7 KB
Binary file not shown.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import board
2+
import displayio
3+
import adafruit_ili9341
4+
5+
# Release any previously configured displays
6+
displayio.release_displays()
7+
8+
# Setup SPI bus
9+
spi_bus = board.SPI()
10+
11+
# Digital pins to use
12+
tft_cs = board.D10
13+
tft_dc = board.D9
14+
15+
# Setup the display bus
16+
display_bus = displayio.FourWire(spi_bus, command=tft_dc, chip_select=tft_cs)
17+
18+
# Setup the Display
19+
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
20+
21+
#
22+
# DONE - now you can use the display however you want
23+
#
24+
25+
bitmap = displayio.Bitmap(320, 240, 2)
26+
27+
palette = displayio.Palette(2)
28+
palette[0] = 0
29+
palette[1] = 0xFFFFFF
30+
31+
for x in range(10, 20):
32+
for y in range(10, 20):
33+
bitmap[x, y] = 1
34+
35+
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
36+
37+
group = displayio.Group()
38+
group.append(tile_grid)
39+
display.show(group)
40+
display.refresh_soon()
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import board
2+
import displayio
3+
4+
# Release any previously configured displays
5+
displayio.release_displays()
6+
7+
# Setup SPI bus
8+
spi_bus = board.SPI()
9+
10+
# Digital pins to use
11+
tft_cs = board.D10
12+
tft_dc = board.D9
13+
14+
# Setup the display bus
15+
display_bus = displayio.FourWire(spi_bus, command=tft_dc, chip_select=tft_cs)
16+
17+
# Setup the initialization sequence
18+
# stolen from adafruit_ili9341.py
19+
INIT_SEQUENCE = (
20+
b"\x01\x80\x80" # Software reset then delay 0x80 (128ms)
21+
b"\xEF\x03\x03\x80\x02"
22+
b"\xCF\x03\x00\xC1\x30"
23+
b"\xED\x04\x64\x03\x12\x81"
24+
b"\xE8\x03\x85\x00\x78"
25+
b"\xCB\x05\x39\x2C\x00\x34\x02"
26+
b"\xF7\x01\x20"
27+
b"\xEA\x02\x00\x00"
28+
b"\xc0\x01\x23" # Power control VRH[5:0]
29+
b"\xc1\x01\x10" # Power control SAP[2:0];BT[3:0]
30+
b"\xc5\x02\x3e\x28" # VCM control
31+
b"\xc7\x01\x86" # VCM control2
32+
b"\x36\x01\x38" # Memory Access Control
33+
b"\x37\x01\x00" # Vertical scroll zero
34+
b"\x3a\x01\x55" # COLMOD: Pixel Format Set
35+
b"\xb1\x02\x00\x18" # Frame Rate Control (In Normal Mode/Full Colors)
36+
b"\xb6\x03\x08\x82\x27" # Display Function Control
37+
b"\xF2\x01\x00" # 3Gamma Function Disable
38+
b"\x26\x01\x01" # Gamma curve selected
39+
b"\xe0\x0f\x0F\x31\x2B\x0C\x0E\x08\x4E\xF1\x37\x07\x10\x03\x0E\x09\x00" # Set Gamma
40+
b"\xe1\x0f\x00\x0E\x14\x03\x11\x07\x31\xC1\x48\x08\x0F\x0C\x31\x36\x0F" # Set Gamma
41+
b"\x11\x80\x78" # Exit Sleep then delay 0x78 (120ms)
42+
b"\x29\x80\x78" # Display on then delay 0x78 (120ms)
43+
)
44+
45+
# Setup the Display
46+
display = displayio.Display(display_bus, INIT_SEQUENCE, width=320, height=240)
47+
48+
#
49+
# DONE - now you can use the display however you want
50+
#
51+
52+
bitmap = displayio.Bitmap(320, 240, 2)
53+
54+
palette = displayio.Palette(2)
55+
palette[0] = 0
56+
palette[1] = 0xFFFFFF
57+
58+
for x in range(10, 20):
59+
for y in range(10, 20):
60+
bitmap[x, y] = 1
61+
62+
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
63+
64+
group = displayio.Group()
65+
group.append(tile_grid)
66+
display.show(group)
67+
display.refresh_soon()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import board
2+
from adafruit_bitmap_font import bitmap_font
3+
from adafruit_display_text import label
4+
5+
display = board.DISPLAY
6+
7+
# Set text, font, and color
8+
text = "HELLO WORLD"
9+
font = bitmap_font.load_font("/Helvetica-Bold-16.bdf")
10+
color = 0xFF00FF
11+
12+
# Create the tet label
13+
text_area = label.Label(font, text=text, color=color)
14+
15+
# Set the location
16+
text_area.x = 20
17+
text_area.y = 20
18+
19+
# Show it
20+
display.show(text_area)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import board
2+
import displayio
3+
import adafruit_imageload
4+
5+
display = board.DISPLAY
6+
7+
bitmap, palette = adafruit_imageload.load("/purple.bmp",
8+
bitmap=displayio.Bitmap,
9+
palette=displayio.Palette)
10+
11+
# Create a TileGrid to hold the bitmap
12+
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
13+
14+
# Create a Group to hold the TileGrid
15+
group = displayio.Group()
16+
17+
# Add the TileGrid to the Group
18+
group.append(tile_grid)
19+
20+
# Add the Group to the Display
21+
display.show(group)
22+
23+
# Loop forever so you can enjoy your image
24+
while True:
25+
pass
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import board
2+
import displayio
3+
4+
display = board.DISPLAY
5+
6+
# Open the file
7+
with open("/purple.bmp", "rb") as bitmap_file:
8+
9+
# Setup the file as the bitmap data source
10+
bitmap = displayio.OnDiskBitmap(bitmap_file)
11+
12+
# Create a TileGrid to hold the bitmap
13+
tile_grid = displayio.TileGrid(bitmap, pixel_shader=displayio.ColorConverter())
14+
15+
# Create a Group to hold the TileGrid
16+
group = displayio.Group()
17+
18+
# Add the TileGrid to the Group
19+
group.append(tile_grid)
20+
21+
# Add the Group to the Display
22+
display.show(group)
23+
24+
# Loop forever so you can enjoy your image
25+
while True:
26+
pass
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import board
2+
import displayio
3+
4+
# Release any previously configured displays
5+
displayio.release_displays()
6+
7+
# Setup the display bus
8+
# Tested with a Metro M4 Express
9+
display_bus = displayio.ParallelBus(data0=board.D13,
10+
command=board.D6,
11+
chip_select=board.D7,
12+
write=board.D5,
13+
read=board.D4)
14+
15+
# Setup the initialization sequence
16+
# stolen from adafruit_ili9341.py
17+
INIT_SEQUENCE = (
18+
b"\x01\x80\x80" # Software reset then delay 0x80 (128ms)
19+
b"\xEF\x03\x03\x80\x02"
20+
b"\xCF\x03\x00\xC1\x30"
21+
b"\xED\x04\x64\x03\x12\x81"
22+
b"\xE8\x03\x85\x00\x78"
23+
b"\xCB\x05\x39\x2C\x00\x34\x02"
24+
b"\xF7\x01\x20"
25+
b"\xEA\x02\x00\x00"
26+
b"\xc0\x01\x23" # Power control VRH[5:0]
27+
b"\xc1\x01\x10" # Power control SAP[2:0];BT[3:0]
28+
b"\xc5\x02\x3e\x28" # VCM control
29+
b"\xc7\x01\x86" # VCM control2
30+
b"\x36\x01\x38" # Memory Access Control
31+
b"\x37\x01\x00" # Vertical scroll zero
32+
b"\x3a\x01\x55" # COLMOD: Pixel Format Set
33+
b"\xb1\x02\x00\x18" # Frame Rate Control (In Normal Mode/Full Colors)
34+
b"\xb6\x03\x08\x82\x27" # Display Function Control
35+
b"\xF2\x01\x00" # 3Gamma Function Disable
36+
b"\x26\x01\x01" # Gamma curve selected
37+
b"\xe0\x0f\x0F\x31\x2B\x0C\x0E\x08\x4E\xF1\x37\x07\x10\x03\x0E\x09\x00" # Set Gamma
38+
b"\xe1\x0f\x00\x0E\x14\x03\x11\x07\x31\xC1\x48\x08\x0F\x0C\x31\x36\x0F" # Set Gamma
39+
b"\x11\x80\x78" # Exit Sleep then delay 0x78 (120ms)
40+
b"\x29\x80\x78" # Display on then delay 0x78 (120ms)
41+
)
42+
43+
# Setup the Display
44+
display = displayio.Display(display_bus, INIT_SEQUENCE, width=320, height=240)
45+
46+
#
47+
# DONE - now you can use the display however you want
48+
#
49+
50+
bitmap = displayio.Bitmap(320, 240, 2)
51+
52+
palette = displayio.Palette(2)
53+
palette[0] = 0
54+
palette[1] = 0xFFFFFF
55+
56+
for x in range(10, 20):
57+
for y in range(10, 20):
58+
bitmap[x, y] = 1
59+
60+
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
61+
62+
group = displayio.Group()
63+
group.append(tile_grid)
64+
display.show(group)
65+
display.refresh_soon()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import board
2+
import displayio
3+
4+
display = board.DISPLAY
5+
6+
# Create a bitmap with two colors
7+
bitmap = displayio.Bitmap(display.width, display.height, 2)
8+
9+
# Create a two color palette
10+
palette = displayio.Palette(2)
11+
palette[0] = 0x000000
12+
palette[1] = 0xffffff
13+
14+
# Create a TileGrid using the Bitmap and Palette
15+
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
16+
17+
# Create a Group
18+
group = displayio.Group()
19+
20+
# Add the TileGrid to the Group
21+
group.append(tile_grid)
22+
23+
# Add the Group to the Display
24+
display.show(group)
25+
26+
# Draw a pixel
27+
bitmap[80, 50] = 1
28+
29+
# Draw even more pixels
30+
for x in range(150, 170):
31+
for y in range(100, 110):
32+
bitmap[x, y] = 1

0 commit comments

Comments
 (0)