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()  # uses board.SCL and board.SDA
25# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
26display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
27
28# SH1107 is vertically oriented 64x128
29WIDTH = 128
30HEIGHT = 64
31BORDER = 2
32
33display = adafruit_displayio_sh1107.SH1107(
34    display_bus, width=WIDTH, height=HEIGHT, rotation=0
35)
36
37# Make the display context
38splash = displayio.Group()
39display.root_group = splash
40
41color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
42color_palette = displayio.Palette(1)
43color_palette[0] = 0xFFFFFF  # White
44
45bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
46splash.append(bg_sprite)
47
48# Draw a smaller inner rectangle in black
49inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1)
50inner_palette = displayio.Palette(1)
51inner_palette[0] = 0x000000  # Black
52inner_sprite = displayio.TileGrid(
53    inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
54)
55splash.append(inner_sprite)
56
57# Draw some white squares
58sm_bitmap = displayio.Bitmap(8, 8, 1)
59sm_square = displayio.TileGrid(sm_bitmap, pixel_shader=color_palette, x=58, y=17)
60splash.append(sm_square)
61
62med_bitmap = displayio.Bitmap(16, 16, 1)
63med_square = displayio.TileGrid(med_bitmap, pixel_shader=color_palette, x=71, y=15)
64splash.append(med_square)
65
66lrg_bitmap = displayio.Bitmap(32, 32, 1)
67lrg_square = displayio.TileGrid(lrg_bitmap, pixel_shader=color_palette, x=91, y=28)
68splash.append(lrg_square)
69
70# Draw some label text
71text1 = "0123456789ABCDEF123456789AB"  # overly long to see where it clips
72text_area = label.Label(terminalio.FONT, text=text1, color=0xFFFFFF, x=8, y=8)
73splash.append(text_area)
74text2 = "SH1107"
75text_area2 = label.Label(
76    terminalio.FONT, text=text2, scale=2, color=0xFFFFFF, x=9, y=44
77)
78splash.append(text_area2)
79
80while True:
81    pass