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