Simple test

Ensure your device works with this simple test.

examples/displayio_sh1107_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4"""
 5Author: Mark Roberts (mdroberts1243) from Adafruit code
 6This test will initialize the display using displayio and draw a solid white
 7background, a smaller black rectangle, miscellaneous stuff and some white text.
 8
 9"""
10
11
12import board
13import displayio
14import terminalio
15
16# can try import bitmap_label below for alternative
17from adafruit_display_text import label
18import adafruit_displayio_sh1107
19
20displayio.release_displays()
21# oled_reset = board.D9
22
23# Use for I2C
24i2c = board.I2C()
25display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
26
27# SH1107 is vertically oriented 64x128
28WIDTH = 128
29HEIGHT = 64
30BORDER = 2
31
32display = adafruit_displayio_sh1107.SH1107(
33    display_bus, width=WIDTH, height=HEIGHT, rotation=0
34)
35
36# Make the display context
37splash = displayio.Group()
38display.show(splash)
39
40color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
41color_palette = displayio.Palette(1)
42color_palette[0] = 0xFFFFFF  # White
43
44bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
45splash.append(bg_sprite)
46
47# Draw a smaller inner rectangle in black
48inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1)
49inner_palette = displayio.Palette(1)
50inner_palette[0] = 0x000000  # Black
51inner_sprite = displayio.TileGrid(
52    inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
53)
54splash.append(inner_sprite)
55
56# Draw some white squares
57sm_bitmap = displayio.Bitmap(8, 8, 1)
58sm_square = displayio.TileGrid(sm_bitmap, pixel_shader=color_palette, x=58, y=17)
59splash.append(sm_square)
60
61med_bitmap = displayio.Bitmap(16, 16, 1)
62med_square = displayio.TileGrid(med_bitmap, pixel_shader=color_palette, x=71, y=15)
63splash.append(med_square)
64
65lrg_bitmap = displayio.Bitmap(32, 32, 1)
66lrg_square = displayio.TileGrid(lrg_bitmap, pixel_shader=color_palette, x=91, y=28)
67splash.append(lrg_square)
68
69# Draw some label text
70text1 = "0123456789ABCDEF123456789AB"  # overly long to see where it clips
71text_area = label.Label(terminalio.FONT, text=text1, color=0xFFFFFF, x=8, y=8)
72splash.append(text_area)
73text2 = "SH1107"
74text_area2 = label.Label(
75    terminalio.FONT, text=text2, scale=2, color=0xFFFFFF, x=9, y=44
76)
77splash.append(text_area2)
78
79while True:
80    pass