JoyIT-st7920 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ Metadata-Version: 2.4
2
+ Name: JoyIT_st7920
3
+ Version: 1.0.1
4
+ Summary: Library to use the SBC-LCD128x64 with the Raspberry Pi
5
+ Home-page: https://github.com/joy-it/JoyIT_st7920
6
+ Author: Joy-IT
7
+ Author-email: Joy-IT <service@joy-it.net>
8
+ Project-URL: Homepage, https://github.com/joy-it/JoyIT_st7920
9
+ Project-URL: Issues, https://github.com/joy-it/JoyIT_st7920/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.7
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: gpiozero
16
+ Requires-Dist: spidev
17
+ Requires-Dist: Pillow
18
+ Dynamic: author
19
+ Dynamic: home-page
20
+ Dynamic: license-file
21
+ Dynamic: requires-python
22
+
23
+ # JoyIT_st7920
24
+ Library to use the SBC-LCD128x64 with the Raspberry Pi
25
+
26
+ ## Installation
27
+ You can install this library from PyPI.
28
+ To install it for the current user on your Raspberry Pi, use the following command:
29
+ ```
30
+ pip install JoyIT_st7920
31
+ ```
32
+
33
+ ## Example
34
+ You need to clone this repository on your Raspberry Pi to be able to execute the example code.
35
+ ```
36
+ git clone https://github.com/joy-it/JoyIT_st7920
37
+ ```
38
+ Afterward, you need to move into the directory and activate the virtual environment with the following commands.
39
+ ```
40
+ cd JoyIT_st7920
41
+ python -m venv --system-site-packages env
42
+ source env/bin/activate
43
+ ```
44
+ Then you can execute the example with the following command.
45
+ ```
46
+ cd examples
47
+ python example.py
48
+ ```
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ JoyIT_st7920.egg-info/PKG-INFO
6
+ JoyIT_st7920.egg-info/SOURCES.txt
7
+ JoyIT_st7920.egg-info/dependency_links.txt
8
+ JoyIT_st7920.egg-info/not-zip-safe
9
+ JoyIT_st7920.egg-info/requires.txt
10
+ JoyIT_st7920.egg-info/top_level.txt
11
+ st7920/__init__.py
12
+ st7920/st7920.py
@@ -0,0 +1,3 @@
1
+ gpiozero
2
+ spidev
3
+ Pillow
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Joy-IT
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,48 @@
1
+ Metadata-Version: 2.4
2
+ Name: JoyIT_st7920
3
+ Version: 1.0.1
4
+ Summary: Library to use the SBC-LCD128x64 with the Raspberry Pi
5
+ Home-page: https://github.com/joy-it/JoyIT_st7920
6
+ Author: Joy-IT
7
+ Author-email: Joy-IT <service@joy-it.net>
8
+ Project-URL: Homepage, https://github.com/joy-it/JoyIT_st7920
9
+ Project-URL: Issues, https://github.com/joy-it/JoyIT_st7920/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.7
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: gpiozero
16
+ Requires-Dist: spidev
17
+ Requires-Dist: Pillow
18
+ Dynamic: author
19
+ Dynamic: home-page
20
+ Dynamic: license-file
21
+ Dynamic: requires-python
22
+
23
+ # JoyIT_st7920
24
+ Library to use the SBC-LCD128x64 with the Raspberry Pi
25
+
26
+ ## Installation
27
+ You can install this library from PyPI.
28
+ To install it for the current user on your Raspberry Pi, use the following command:
29
+ ```
30
+ pip install JoyIT_st7920
31
+ ```
32
+
33
+ ## Example
34
+ You need to clone this repository on your Raspberry Pi to be able to execute the example code.
35
+ ```
36
+ git clone https://github.com/joy-it/JoyIT_st7920
37
+ ```
38
+ Afterward, you need to move into the directory and activate the virtual environment with the following commands.
39
+ ```
40
+ cd JoyIT_st7920
41
+ python -m venv --system-site-packages env
42
+ source env/bin/activate
43
+ ```
44
+ Then you can execute the example with the following command.
45
+ ```
46
+ cd examples
47
+ python example.py
48
+ ```
@@ -0,0 +1,26 @@
1
+ # JoyIT_st7920
2
+ Library to use the SBC-LCD128x64 with the Raspberry Pi
3
+
4
+ ## Installation
5
+ You can install this library from PyPI.
6
+ To install it for the current user on your Raspberry Pi, use the following command:
7
+ ```
8
+ pip install JoyIT_st7920
9
+ ```
10
+
11
+ ## Example
12
+ You need to clone this repository on your Raspberry Pi to be able to execute the example code.
13
+ ```
14
+ git clone https://github.com/joy-it/JoyIT_st7920
15
+ ```
16
+ Afterward, you need to move into the directory and activate the virtual environment with the following commands.
17
+ ```
18
+ cd JoyIT_st7920
19
+ python -m venv --system-site-packages env
20
+ source env/bin/activate
21
+ ```
22
+ Then you can execute the example with the following command.
23
+ ```
24
+ cd examples
25
+ python example.py
26
+ ```
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "JoyIT_st7920"
7
+ version = "1.0.1"
8
+ dependencies = ['gpiozero', 'spidev', 'Pillow']
9
+ authors = [
10
+ { name="Joy-IT", email="service@joy-it.net" },
11
+ ]
12
+ description = "Library to use the SBC-LCD128x64 with the Raspberry Pi"
13
+ readme = "README.md"
14
+ requires-python = ">=3.8"
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/joy-it/JoyIT_st7920"
22
+ Issues = "https://github.com/joy-it/JoyIT_st7920/issues"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,20 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="JoyIT_st7920",
5
+ version="1.0.0",
6
+ description="Library to use the SBC-LCD128x64 with the Raspberry Pi",
7
+ author="Joy-IT",
8
+ author_email="service@joy-it.net",
9
+ packages=find_packages(),
10
+ long_description=open('README.md').read(),
11
+ long_description_content_type='text/markdown',
12
+ url='https://github.com/joy-it/JoyIT_st7920',
13
+ classifiers=[
14
+ "Programming Language :: Python :: 3",
15
+ 'License :: OSI Approved :: MIT License',
16
+ 'Operating System :: OS Independent',
17
+ ],
18
+ python_requires='>=3.7',
19
+ zip_safe=False,
20
+ )
@@ -0,0 +1,3 @@
1
+ from .st7920 import *
2
+
3
+ name = "st7920"
@@ -0,0 +1,181 @@
1
+ import spidev
2
+ import time
3
+ from PIL import Image
4
+ from gpiozero import OutputDevice
5
+
6
+ class ST7920:
7
+ def __init__(self, spi_bus=0, spi_device=0, reset_pin = 22):
8
+ """
9
+ Initilize ST7920 with SPI
10
+ """
11
+ self.spi = spidev.SpiDev()
12
+ self.spi.open(spi_bus, spi_device)
13
+ self.spi.max_speed_hz = 500000
14
+ self.spi.mode = 0
15
+
16
+ self.reset_pin = OutputDevice(reset_pin)
17
+ self.init_display()
18
+ self.clear()
19
+
20
+ def _send_command(self, cmd):
21
+ """
22
+ Send command to display
23
+ """
24
+ data = [0xF8, cmd & 0xF0, (cmd << 4) & 0xF0]
25
+ self.spi.writebytes(data)
26
+ time.sleep(0.001)
27
+
28
+ def _send_data(self, data):
29
+ """
30
+ Send data to display
31
+ """
32
+ packet = [0xFA, data & 0xF0, (data << 4) & 0xF0]
33
+ self.spi.writebytes(packet)
34
+ time.sleep(0.001)
35
+
36
+ def init_display(self):
37
+ """
38
+ Establish communication with display
39
+ """
40
+ time.sleep(0.05)
41
+ self._send_command(0x30)
42
+ self._send_command(0x30)
43
+ self._send_command(0x0C)
44
+ self._send_command(0x01)
45
+ time.sleep(0.01)
46
+
47
+ def clear_graphics(self):
48
+ """
49
+ Clear image on display
50
+ """
51
+ self._send_command(0x30)
52
+ self._send_command(0x34)
53
+ self._send_command(0x36)
54
+ for y in range(64):
55
+ if y < 32:
56
+ self._send_command(0x80 | y)
57
+ self._send_command(0x80)
58
+ else:
59
+ self._send_command(0x80 | (y - 32))
60
+ self._send_command(0x88)
61
+ for _ in range(16):
62
+ self._send_data(0x00)
63
+
64
+ def clear(self):
65
+ """
66
+ Clear display
67
+ """
68
+ self._send_command(0x01)
69
+ time.sleep(0.01)
70
+ self.reset_pin.off()
71
+ time.sleep(0.1)
72
+ self.reset_pin.on()
73
+ time.sleep(0.1)
74
+ self.clear_graphics()
75
+ self._send_command(0x30)
76
+ self._send_command(0x0C)
77
+
78
+ def close(self):
79
+ """
80
+ Close connection
81
+ """
82
+ self.spi.close()
83
+
84
+ def write_text(self, text):
85
+ """
86
+ Write text on display
87
+ """
88
+ for char in text:
89
+ self._send_data(ord(char))
90
+
91
+ def home(self):
92
+ """
93
+ Set cursor to (0,0)
94
+ """
95
+ self._send_command(0x02)
96
+ time.sleep(0.01)
97
+
98
+ def display_on(self, cursor=False, blink=False):
99
+ """
100
+ Activate display with visible cursor (False/True) and or blinking cursor (False/True)
101
+ """
102
+ cmd = 0x0C
103
+ if cursor:
104
+ cmd |= 0x02
105
+ if blink:
106
+ cmd |= 0x01
107
+ self._send_command(cmd)
108
+
109
+ def display_off(self):
110
+ """
111
+ Turn display off
112
+ """
113
+ self._send_command(0x08)
114
+
115
+ def set_cursor(self, row: int, col: int):
116
+ """
117
+ Set cursor to position (row, col)
118
+ """
119
+ if row == 0:
120
+ address = 0x80 + col
121
+ elif row == 1:
122
+ address = 0x90 + col
123
+ else:
124
+ raise ValueError("Zeile muss 0 oder 1 sein.")
125
+ self._send_command(address)
126
+
127
+ def write_at(self, row: int, col: int, text: str):
128
+ """
129
+ Method to write text at position (row, col)
130
+ """
131
+ self.set_cursor(row, col)
132
+ self.write_text(text)
133
+
134
+ def shift_display_left(self):
135
+ """
136
+ Shift display to the left
137
+ """
138
+ self._send_command(0x18)
139
+
140
+ def shift_display_right(self):
141
+ """
142
+ Shift display to the right
143
+ """
144
+ self._send_command(0x1C)
145
+
146
+ def entry_mode(self, increment=True, shift=False):
147
+ """
148
+ Setup entry mode
149
+ """
150
+ cmd = 0x04
151
+ if increment:
152
+ cmd |= 0x02
153
+ if shift:
154
+ cmd |= 0x01
155
+ self._send_command(cmd)
156
+
157
+ def draw_image(self, image: Image.Image):
158
+ """
159
+ draw image on display
160
+ """
161
+ self._send_command(0x30)
162
+ self._send_command(0x34)
163
+ self._send_command(0x36)
164
+ if image.size != (128, 64):
165
+ raise ValueError("Image has to be 128x64 Pixel")
166
+ image = image.convert("1")
167
+ pixels = image.load()
168
+ for y in range(64):
169
+ if y < 32:
170
+ self._send_command(0x80 | y)
171
+ self._send_command(0x80)
172
+ else:
173
+ self._send_command(0x80 | (y - 32))
174
+ self._send_command(0x88)
175
+ for x in range(0, 128, 8):
176
+ byte = 0
177
+ for bit in range(8):
178
+ if pixels[x + bit, y] == 0:
179
+ byte |= (1 << (7 - bit))
180
+ self._send_data(byte)
181
+