Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5import board
6import busio
7import digitalio
8
9import adafruit_pcd8544
10
11# Initialize SPI bus and control pins
12spi = busio.SPI(board.SCK, MOSI=board.MOSI)
13dc = digitalio.DigitalInOut(board.D6) # data/command
14cs = digitalio.DigitalInOut(board.D5) # Chip select
15reset = digitalio.DigitalInOut(board.D9) # reset
16
17display = adafruit_pcd8544.PCD8544(spi, dc, cs, reset)
18
19display.bias = 4
20display.contrast = 60
21
22# Turn on the Backlight LED
23backlight = digitalio.DigitalInOut(board.D10) # backlight
24backlight.switch_to_output()
25backlight.value = True
26
27print("Pixel test")
28# Clear the display. Always call show after changing pixels to make the display
29# update visible!
30display.fill(0)
31display.show()
32
33# Set a pixel in the origin 0,0 position.
34display.pixel(0, 0, 1)
35# Set a pixel in the middle position.
36display.pixel(display.width // 2, display.height // 2, 1)
37# Set a pixel in the opposite corner position.
38display.pixel(display.width - 1, display.height - 1, 1)
39display.show()
40time.sleep(2)
41
42print("Lines test")
43# we'll draw from corner to corner, lets define all the pair coordinates here
44corners = (
45 (0, 0),
46 (0, display.height - 1),
47 (display.width - 1, 0),
48 (display.width - 1, display.height - 1),
49)
50
51display.fill(0)
52for corner_from in corners:
53 for corner_to in corners:
54 display.line(corner_from[0], corner_from[1], corner_to[0], corner_to[1], 1)
55display.show()
56time.sleep(2)
57
58print("Rectangle test")
59display.fill(0)
60w_delta = display.width / 10
61h_delta = display.height / 10
62for i in range(11):
63 display.rect(0, 0, int(w_delta * i), int(h_delta * i), 1)
64display.show()
65time.sleep(2)
66
67print("Text test")
68display.fill(0)
69display.text("hello world", 0, 0, 1)
70display.text("this is the", 0, 8, 1)
71display.text("CircuitPython", 0, 16, 1)
72display.text("adafruit lib-", 0, 24, 1)
73display.text("rary for the", 0, 32, 1)
74display.text("PCD8544! :) ", 0, 40, 1)
75
76display.show()
77
78while True:
79 display.invert = True
80 time.sleep(0.5)
81 display.invert = False
82 time.sleep(0.5)