-
Notifications
You must be signed in to change notification settings - Fork 2
/
ST7920_test.py
83 lines (68 loc) · 6.92 KB
/
ST7920_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
"""
Marko Pinteric 2021
ST7920 graphic LCD controller test
- fast parallel communication using C code
- requires ST7920.py and parallel.so in the same folder
- data for fast transfer have to be supplied in contiguous block of bytes
- supports writing and reading, reading is optional
for more information see: http://www.pinteric.com/displays.html
"""
from ST7920 import ST7920
import time
# used to form large contiguous block of bytes
import numpy
from ctypes import c_void_p, c_uint8
# 4 bit communication, backlight PWM power on GPIO18, backlight off on start
st = ST7920(20, 5, 6, 13, 19, -1, -1, -1, -1, 16, 21, -1, 18, backlight=0, pwm=True)
st.setbacklight(1)
# print variable width font text
st.message_full("""128 x 64
DISPLAY
ST7920
CHIP""",'c')
time.sleep(5)
# print 8x16px font text
st.message_half("""More about using
and programming
the ST7920 chip
in Python
at Raspberry Pi
on
pinteric.com/
displays.html""",'c')
time.sleep(5)
# show the second page
st.extendedon(True)
st.scrollon(True)
st.setiposition(32)
time.sleep(5)
# create contiguous data for the dog picture using numpy method, one per line (both upper and lower page)
dogpicture = numpy.array([[0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0xC0,0x00,0x01,0xC0,0x00,0x00,0x00,0x00],[0x00,0x00,0x00,0x3F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0xC0,0x00,0x07,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x3F,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0xC0,0x00,0x0E,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0xFF,0x38,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0xC0,0x00,0x1C,0x00,0x00,0x00,0x00,0x00],[0x00,0x01,0xC0,0x30,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0xC0,0x00,0x70,0x00,0x00,0x00,0x00,0x00],[0x00,0x07,0x80,0x18,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x60,0x00,0xE0,0x00,0x00,0x00,0x00,0x00],[0x03,0xFF,0x00,0x18,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x60,0x01,0xC0,0x00,0x00,0x00,0x00,0x00],[0x03,0xF0,0x00,0x0C,0x06,0x00,0x00,0x00,0x07,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x60,0x01,0x80,0x00,0x00,0x00,0x00,0x00],[0x06,0x00,0x00,0x0C,0x07,0x00,0x00,0x00,0x7F,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x03,0xF0,0x03,0x00,0x00,0x00,0x00,0x00,0x00],[0x06,0x00,0x00,0x0C,0x07,0x80,0x00,0x03,0xF8,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xC0,0x03,0xF0,0x03,0x00,0x00,0x00,0x00,0x00,0x00],[0x06,0x00,0x00,0x06,0x0D,0xFF,0xFF,0x1F,0x80,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0xF8,0x03,0x38,0x03,0x00,0x00,0x00,0x00,0x00,0x00],[0x03,0x00,0x00,0x06,0x0C,0x7F,0xFF,0xFC,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x3C,0x03,0x98,0x03,0x00,0x00,0x00,0x00,0x00,0x00],[0x03,0x00,0x00,0x06,0x18,0x00,0x00,0x40,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0F,0x01,0x8C,0x03,0x00,0x00,0x00,0x00,0x00,0x00],[0x03,0x80,0x00,0x07,0x38,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x1F,0x80,0xCC,0x01,0x80,0x00,0x00,0x00,0x00,0x00],[0x01,0xC0,0x00,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x19,0xC0,0xE6,0x01,0x80,0x00,0x00,0x00,0x00,0x00],[0x00,0xF8,0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x18,0xE0,0x66,0x03,0x80,0x00,0x00,0x00,0x00,0x00],[0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x18,0x70,0x3C,0x07,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x07,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x30,0xF8,0x3C,0x0E,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x3F,0xDC,0x38,0x1C,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x0F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFC,0x0F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x06,0x1F,0x07,0x70,0x78,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x01,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x1F,0x00,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x0F,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x03,0xF8,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x07,0x01,0xFF,0xC1,0xC0,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xF7,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x07,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFE,0x0E,0x0F,0x80,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3D,0xC0,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x78,0x60,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x61,0xF8,0x30,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x10,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x98,0x30,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x30,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x08,0x30,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x60,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x0F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00],[0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x60,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]], dtype = 'uint8')
# send the dog picture to the second page
st.cleargraphic()
st.graphicon(True)
for i in range(32):
st.setgraphicposition(0,i+64)
st.writedata(dogpicture[i])
time.sleep(3)
# clear text and return to the second page
st.extendedon(False)
st.clearchar()
st.extendedon(True)
st.setiposition(32)
time.sleep(3)
# change backlight brightness
for i in range(4):
st.setbacklight(0.5)
time.sleep(0.25)
st.setbacklight(1)
time.sleep(0.25)
# turn graphic off and return to the first page
st.extendedon(True)
st.graphicon(False)
st.setiposition(0)
st.extendedon(False)
# close the chip
st.setbacklight(0)
st.close()