mbirth / wipy-upcd8544

MicroPython module for the PCD8544 lcd module (Nokia 5110)
MIT License
11 stars 5 forks source link

ESP8266 support #1

Closed mcauser closed 7 years ago

mcauser commented 8 years ago

Two small changes to make it work on ESP8266 (WeMos D1 Mini):

  1. struct not found, ustruct works though
try:
    import struct
except:
    import ustruct as struct
  1. spi.init() works differently on ESP8266
#spi.init(spi.MASTER, baudrate=328125, bits=8, polarity=0, phase=1, firstbit=spi.MSB)
spi.init(baudrate=328125)

Not sure how to get the same spi code working across 3 platforms, pyboard, wipy and esp8266. Try catch doesn't seem quite right around spi.init().

Working example using framebuf:

import machine
import upcd8544

spi = machine.SPI(baudrate=100000, polarity=1, phase=0, sck=machine.Pin(14), mosi=machine.Pin(13), miso=machine.Pin(15))
RST = machine.Pin(4)
CE = machine.Pin(5)
DC = machine.Pin(12)
BL = machine.Pin(16)

lcd = upcd8544.PCD8544(spi, RST, CE, DC, BL)

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

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

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

framebuf.text("Hello,", 0, 0, 1)
framebuf.text("World!", 0, 9, 1)
lcd.data(buffer)

Connections:

WeMos D1 Mini   Nokia 5110
(ESP8266)       PCD8544 LCD

D2 (GPIO4) ---- 0 RST
D1 (GPIO5) ---- 1 CE
D6 (GPIO12) --- 2 DC
D7 (GPIO13) --- 3 Din
D5 (GPIO14) --- 4 Clk
3V3 ----------- 5 Vcc
D0 (GPIO16) --- 6 BL
G ------------- 7 Gnd

img_7320b

mcauser commented 8 years ago

Thanks for the library! Am using it here: