Skip to content

Commit 1defe49

Browse files
committed
Shorter method names
_write_cmd() renamed to cmd() _write_data() renamed to data()
1 parent cf4535c commit 1defe49

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
PCD8544
2-
=======
1+
# MicroPython PCD8544
32

43
A MicroPython library for the PCD8544 84x48 LCD, used by the Nokia 5110 display.
54

@@ -55,24 +54,24 @@ BL = Pin(12, Pin.OUT, value=1)
5554
lcd = pcd8544.PCD8544(spi, CE, DC, RST)
5655
5756
# test pattern (50% on)
58-
lcd._write_data(bytearray([0x55, 0xAA] * 42 * 6))
57+
lcd.data(bytearray([0x55, 0xAA] * 42 * 6))
5958
6059
# bitmap smiley (horzontal msb)
6160
lcd.clear()
6261
# draw 8x16 in bank 0
6362
lcd.position(0, 0)
64-
lcd._write_data(bytearray(b'\xE0\x38\xE4\x22\xA2\xE1\xE1\x61\xE1\x21\xA2\xE2\xE4\x38\xE0\x00'))
63+
lcd.data(bytearray(b'\xE0\x38\xE4\x22\xA2\xE1\xE1\x61\xE1\x21\xA2\xE2\xE4\x38\xE0\x00'))
6564
# draw 8x16 in bank 1
6665
lcd.position(0, 1)
67-
lcd._write_data(bytearray(b'\x03\x0C\x10\x21\x21\x41\x48\x48\x48\x49\x25\x21\x10\x0C\x03\x00'))
66+
lcd.data(bytearray(b'\x03\x0C\x10\x21\x21\x41\x48\x48\x48\x49\x25\x21\x10\x0C\x03\x00'))
6867
6968
# toggle display, DDRAM persists image
7069
lcd.power_off()
7170
lcd.power_on()
7271
7372
# nokia logo bitmap
7473
lcd.clear()
75-
lcd._write_data(bytearray(b'\x80\x00\x00\x80\x00\x00\x80\x00\x00\x80\x00\x00\x80\x00\x00\x80\x00\x00\x80\x80\x40\x40\x40\x80\x80\xC0\xC0\x40\xC0\xA0\xE0\xC0\xE0\xE0\xF0\xF0\xF8\xF8\xF8\xFC\xFC\xFE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x01\x00\x01\x01\xFF\xFE\x03\x01\x01\x00\xF1\xF0\xF1\x71\xF1\xF1\xB1\xF1\x01\x01\x01\x03\xFE\xFF\x01\x01\x01\x01\xBE\x1B\x0D\x07\x03\x41\xE1\xF1\xF9\x6D\xFF\xFF\x00\x01\x01\x01\xFF\xFF\xEB\x3E\x0D\x03\x01\x41\x71\x70\x41\x01\x03\x0E\x3B\xEF\xFE\xFB\xEE\x7D\xF7\xFF\xFF\xFF\xFF\xFE\xFF\xF0\xF0\xF0\xF0\xFF\xFF\xFF\xFF\xFE\xFC\xF8\xF0\xF0\xF0\xF0\xF0\xF0\xFF\xFF\xF8\xF0\xF0\xF0\xF1\xF1\xF1\xF1\xF1\xF1\xF1\xF1\xF0\xF0\xF0\xF8\xFF\xFF\xF0\xF0\xF0\xF0\xFF\xFF\xFE\xFC\xF8\xF0\xF0\xF1\xF3\xF7\xFF\xFF\xF0\xF0\xF0\xF0\xFF\xF3\xF0\xF0\xF0\xFC\xFC\xFC\xFC\xFC\xFC\xFC\xFC\xF0\xF0\xF0\xF3\xFF\xFF\xFF\xFF\xFF'))
7675
7776
lcd.invert(True)
7877
lcd.invert(False)
@@ -106,14 +105,28 @@ framebuf.rect(40, 16, 8, 8, 1)
106105
framebuf.fill_rect(16, 32, 8, 8, 1)
107106
108107
lcd.position(0, 0)
109-
lcd._write_data(buffer)
108+
lcd.data(buffer)
110109
111110
framebuf.fill(0)
112-
lcd._write_data(buffer)
111+
lcd.data(buffer)
113112
```
114113

115114
See [pcd8544_examples.py](pcd8544_examples.py) for more.
116115

116+
## Addressing
117+
118+
Each animation frame represents 1 of 504 bytes written to the DDRAM. `lcd.data(bytearray(b'\xFF'))`
119+
120+
In horizontal mode you can use framebuf with MONO_VLSB format. Vertical mode does not have a compatible framebuf format.
121+
122+
**Horizontal**
123+
124+
![Horizontal](docs/pcd8544-horizontal.gif)
125+
126+
**Vertical**
127+
128+
![Vertical](docs/pcd8544-vertical.gif)
129+
117130
## Parts
118131

119132
* [WeMos D1 Mini](https://www.aliexpress.com/store/product/D1-mini-Mini-NodeMcu-4M-bytes-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266/1331105_32529101036.html) $4.00 USD

docs/pcd8544-horizontal.gif

11.9 KB
Loading

docs/pcd8544-vertical.gif

11.9 KB
Loading

pcd8544.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def init(self, horizontal=True, contrast=0x3f, bias=BIAS_1_40, temp=TEMP_COEFF_2
6666
self.fn |= ADDRESSING_VERT
6767

6868
self.contrast(contrast, bias, temp)
69-
self._write_cmd(DISPLAY_NORMAL)
69+
self.cmd(DISPLAY_NORMAL)
7070
self.clear()
7171

7272
def reset(self):
@@ -81,11 +81,11 @@ def reset(self):
8181
def power_on(self):
8282
self.cs(1)
8383
self.fn &= ~POWER_DOWN
84-
self._write_cmd(self.fn)
84+
self.cmd(self.fn)
8585

8686
def power_off(self):
8787
self.fn |= POWER_DOWN
88-
self._write_cmd(self.fn)
88+
self.cmd(self.fn)
8989

9090
def contrast(self, contrast=0x3f, bias=BIAS_1_40, temp=TEMP_COEFF_2):
9191
for cmd in (
@@ -101,28 +101,28 @@ def contrast(self, contrast=0x3f, bias=BIAS_1_40, temp=TEMP_COEFF_2):
101101
SET_VOP | contrast,
102102
# revert to basic instruction set
103103
self.fn & ~EXTENDED_INSTR):
104-
self._write_cmd(cmd)
104+
self.cmd(cmd)
105105

106106
def invert(self, invert):
107-
self._write_cmd(DISPLAY_INVERSE if invert else DISPLAY_NORMAL)
107+
self.cmd(DISPLAY_INVERSE if invert else DISPLAY_NORMAL)
108108

109109
def clear(self):
110110
# clear DDRAM, reset x,y position to 0,0
111-
self._write_data([0] * (self.height * self.width // 8))
111+
self.data([0] * (self.height * self.width // 8))
112112
self.position(0, 0)
113113

114114
def position(self, x, y):
115115
# set cursor to column x (0~83), bank y (0~5)
116-
self._write_cmd(COL_ADDR | x) # set x pos (0~83)
117-
self._write_cmd(BANK_ADDR | y) # set y pos (0~5)
116+
self.cmd(COL_ADDR | x) # set x pos (0~83)
117+
self.cmd(BANK_ADDR | y) # set y pos (0~5)
118118

119-
def _write_cmd(self, command):
119+
def cmd(self, command):
120120
self.dc(0)
121121
self.cs(0)
122122
self.spi.write(bytearray([command]))
123123
self.cs(1)
124124

125-
def _write_data(self, data):
125+
def data(self, data):
126126
self.dc(1)
127127
self.cs(0)
128128
self.spi.write(pack('B'*len(data), *data))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
setup(
88
name='micropython-pcd8544',
99
py_modules=['pcd8544'],
10-
version='1.0.0',
10+
version='1.1.0',
1111
description='MicroPython library for the PCD8544 LCD, used by Nokia 5110 displays.',
1212
long_description='This library lets you communicate with LCDs using the Philips PCD8544 84x48 monochrome LCD driver, for example the Nokia 5110 display.',
1313
keywords='pcd8544 monochrome lcd nokia micropython',

0 commit comments

Comments
 (0)