Simple test

Ensure your device works with this simple test.

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