micropython-pcd8544

MicroPython library for the PCD8544 LCD, used by Nokia 5110 displays.


Keywords
pcd8544, monochrome, lcd, nokia, micropython, esp8266, nokia-5110, nokia5110, wemos-d1-mini
License
MIT
Install
pip install micropython-pcd8544==1.1.0

Documentation

MicroPython PCD8544

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

demo

Pinout

+-----------------+
|                 |
| +-------------+ |
| | Nokia 5110  | |
| | PCD8544     | |
| | 84x48       | |
| |             | |
| +-------------+ |
+-----------------+
  | | | | | | | |
  1 2 3 4 5 6 7 8
  • 1 RST
  • 2 CE
  • 3 DC
  • 4 DIN
  • 5 CLK
  • 6 VCC
  • 7 BL
  • 8 GND

Example

Copy the file to your device, using ampy, webrepl or compiling and deploying. eg.

$ ampy put pcd8544.py

Hello World

import pcd8544
from machine import Pin, SPI

spi = SPI(1)
spi.init(baudrate=8000000, polarity=0, phase=0)
CE = Pin(2)
DC = Pin(15)
RST = Pin(4)

# backlight on
BL = Pin(12, Pin.OUT, value=1)

lcd = pcd8544.PCD8544(spi, CE, DC, RST)

# test pattern (50% on)
lcd.data(bytearray([0x55, 0xAA] * 42 * 6))

# bitmap smiley (horzontal msb)
lcd.clear()
# draw 8x16 in bank 0
lcd.position(0, 0)
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.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()
lcd.power_on()

# nokia logo bitmap
lcd.clear()
lcd.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\x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9\x77\xDA\xB5\xEE\x59\xB6\xEB\xDD\xB6\x69\xD6\xBF\xE8\x55\xEF\xB9\xD6\xED\xB5\x5B\xAB\xFF\xFD\xF7\xFF\x01\x01\x01\x01\xE1\xC1\x81\x03\x05\x0F\x1D\x2F\x7E\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'))

lcd.invert(True)
lcd.invert(False)

lcd.reset()

# adjust contrast, bias and temp
lcd.contrast(0x1f, pcd8544.BIAS_1_40, pcd8544.TEMP_COEFF_0)
lcd.contrast(0x3f, pcd8544.BIAS_1_48, pcd8544.TEMP_COEFF_0)
lcd.contrast(0x3c, pcd8544.BIAS_1_40, pcd8544.TEMP_COEFF_0)
lcd.contrast(0x42, pcd8544.BIAS_1_48, pcd8544.TEMP_COEFF_0)
lcd.contrast(0x3f, pcd8544.BIAS_1_40, pcd8544.TEMP_COEFF_2)

# use the framebuf
import framebuf
width = 84
height = 48
pages = height // 8
buffer = bytearray(pages * width)
framebuf = framebuf.FrameBuffer1(buffer, width, height)

framebuf.text('Hello', 0, 0, 1)
framebuf.pixel(30, 30, 1)
framebuf.pixel(31, 31, 1)
framebuf.pixel(32, 32, 1)
framebuf.pixel(33, 33, 1)
framebuf.pixel(34, 34, 1)
framebuf.hline(0, 20, 8, 1)
framebuf.vline(30, 8, 8, 1)
framebuf.rect(40, 16, 8, 8, 1)
framebuf.fill_rect(16, 32, 8, 8, 1)

lcd.position(0, 0)
lcd.data(buffer)

framebuf.fill(0)
lcd.data(buffer)

See 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

Vertical

Vertical

Parts

Connections

WeMos D1 Mini PCD8544 LCD
D2 (GPIO4) 0 RST
D4 (GPIO2) 1 CE
D8 (GPIO15) 2 DC
D7 (GPIO13) 3 Din
D5 (GPIO14) 4 Clk
3V3 5 Vcc
D6 (GPIO12) 6 BL
G 7 Gnd

Links