diff --git a/README.md b/README.md index aeb4127..ccdee91 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -PCD8544 -======= +# MicroPython PCD8544 A MicroPython library for the PCD8544 84x48 LCD, used by the Nokia 5110 display. @@ -55,16 +54,16 @@ BL = Pin(12, Pin.OUT, value=1) lcd = pcd8544.PCD8544(spi, CE, DC, RST) # test pattern (50% on) -lcd._write_data(bytearray([0x55, 0xAA] * 42 * 6)) +lcd.data(bytearray([0x55, 0xAA] * 42 * 6)) # bitmap smiley (horzontal msb) lcd.clear() # draw 8x16 in bank 0 lcd.position(0, 0) -lcd._write_data(bytearray(b'\xE0\x38\xE4\x22\xA2\xE1\xE1\x61\xE1\x21\xA2\xE2\xE4\x38\xE0\x00')) +lcd.data(bytearray(b'\xE0\x38\xE4\x22\xA2\xE1\xE1\x61\xE1\x21\xA2\xE2\xE4\x38\xE0\x00')) # draw 8x16 in bank 1 lcd.position(0, 1) -lcd._write_data(bytearray(b'\x03\x0C\x10\x21\x21\x41\x48\x48\x48\x49\x25\x21\x10\x0C\x03\x00')) +lcd.data(bytearray(b'\x03\x0C\x10\x21\x21\x41\x48\x48\x48\x49\x25\x21\x10\x0C\x03\x00')) # toggle display, DDRAM persists image lcd.power_off() @@ -72,7 +71,7 @@ lcd.power_on() # nokia logo bitmap lcd.clear() -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\xEE\xF4\xF0\xF0\x70\x30\x00\x80\x00\x00\x80\x00\x0C\x9C\x1C\x38\xB8\x38\x38\xB8\xF8\xF0\xF0\xF0\xF0\xF0\xF0\xF0\xF0\xF0\xF0\xF0\xF0\xF0\xF0\xF0\xF0\xF0\xF8\xF8\xF8\xF8\x88\x20\x8A\x20\x08\x22\x08\x00\x0A\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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')) lcd.invert(True) lcd.invert(False) @@ -106,14 +105,28 @@ framebuf.rect(40, 16, 8, 8, 1) framebuf.fill_rect(16, 32, 8, 8, 1) lcd.position(0, 0) -lcd._write_data(buffer) +lcd.data(buffer) framebuf.fill(0) -lcd._write_data(buffer) +lcd.data(buffer) ``` See [pcd8544_examples.py](pcd8544_examples.py) for more. +## Addressing + +Each animation frame represents 1 of 504 bytes written to the DDRAM. `lcd.data(bytearray(b'\xFF'))` + +In horizontal mode you can use framebuf with MONO_VLSB format. Vertical mode does not have a compatible framebuf format. + +**Horizontal** + +![Horizontal](docs/pcd8544-horizontal.gif) + +**Vertical** + +![Vertical](docs/pcd8544-vertical.gif) + ## Parts * [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 diff --git a/docs/pcd8544-horizontal.gif b/docs/pcd8544-horizontal.gif new file mode 100644 index 0000000..9b5c28a Binary files /dev/null and b/docs/pcd8544-horizontal.gif differ diff --git a/docs/pcd8544-vertical.gif b/docs/pcd8544-vertical.gif new file mode 100644 index 0000000..b479304 Binary files /dev/null and b/docs/pcd8544-vertical.gif differ diff --git a/pcd8544.py b/pcd8544.py index 94502dd..66fe40c 100644 --- a/pcd8544.py +++ b/pcd8544.py @@ -66,7 +66,7 @@ def init(self, horizontal=True, contrast=0x3f, bias=BIAS_1_40, temp=TEMP_COEFF_2 self.fn |= ADDRESSING_VERT self.contrast(contrast, bias, temp) - self._write_cmd(DISPLAY_NORMAL) + self.cmd(DISPLAY_NORMAL) self.clear() def reset(self): @@ -81,11 +81,11 @@ def reset(self): def power_on(self): self.cs(1) self.fn &= ~POWER_DOWN - self._write_cmd(self.fn) + self.cmd(self.fn) def power_off(self): self.fn |= POWER_DOWN - self._write_cmd(self.fn) + self.cmd(self.fn) def contrast(self, contrast=0x3f, bias=BIAS_1_40, temp=TEMP_COEFF_2): for cmd in ( @@ -101,28 +101,28 @@ def contrast(self, contrast=0x3f, bias=BIAS_1_40, temp=TEMP_COEFF_2): SET_VOP | contrast, # revert to basic instruction set self.fn & ~EXTENDED_INSTR): - self._write_cmd(cmd) + self.cmd(cmd) def invert(self, invert): - self._write_cmd(DISPLAY_INVERSE if invert else DISPLAY_NORMAL) + self.cmd(DISPLAY_INVERSE if invert else DISPLAY_NORMAL) def clear(self): # clear DDRAM, reset x,y position to 0,0 - self._write_data([0] * (self.height * self.width // 8)) + self.data([0] * (self.height * self.width // 8)) self.position(0, 0) def position(self, x, y): # set cursor to column x (0~83), bank y (0~5) - self._write_cmd(COL_ADDR | x) # set x pos (0~83) - self._write_cmd(BANK_ADDR | y) # set y pos (0~5) + self.cmd(COL_ADDR | x) # set x pos (0~83) + self.cmd(BANK_ADDR | y) # set y pos (0~5) - def _write_cmd(self, command): + def cmd(self, command): self.dc(0) self.cs(0) self.spi.write(bytearray([command])) self.cs(1) - def _write_data(self, data): + def data(self, data): self.dc(1) self.cs(0) self.spi.write(pack('B'*len(data), *data)) diff --git a/setup.py b/setup.py index 4d72a30..6bfd2c0 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='micropython-pcd8544', py_modules=['pcd8544'], - version='1.0.0', + version='1.1.0', description='MicroPython library for the PCD8544 LCD, used by Nokia 5110 displays.', long_description='This library lets you communicate with LCDs using the Philips PCD8544 84x48 monochrome LCD driver, for example the Nokia 5110 display.', keywords='pcd8544 monochrome lcd nokia micropython',