I used the library https://github.com/mcauser/micropython-pcd8544 and created a main.py file with the clock code. My boot.py file automatically starts Wi-fi and gets the time via NTP.
This is my first effort. I consulted extensively on the forum and documentation provided by Loboris. Thank you!
I hope this helps.
==
Code: Select all
#Nokia 5110 in Wemos ESP 32
# Pinout
# 3V3 or any Pin => VCC 3.3V logic voltage (0=off, 1=on)
# MOSI (23) => DIN data flow (Master out, Slave in)
# SCK (18) => CLK SPI clock
# Pin (0) => RST Reset pin (0=reset, 1=normal)
# Pin (2) => CE Chip Enable (0=listen for input, 1=ignore input)
# Pin (15) => DC Data/Command (0=commands, 1=data)
# Pin (12) => LIGHT Light (0=on, 1=off)
# GND => GND
# References: https://github.com/mcauser/micropython-pcd8544
# http://docs.micropython.org/en/latest/pyboard/library/machine.SPI.html
# http://pedrominatel.com.br/pt/esp8266/utilizando-o-lcd-nokia-5110-no-esp8266/
import pcd8544
import framebuf
import utime
import machine
import _thread
from machine import Pin, SPI
from time import strftime
spi = SPI(1, baudrate=328125, bits=8, polarity=0, phase=1, sck=18, mosi=23, miso=19)
spi.init()
cs = Pin(2)
dc = Pin(15)
rst = Pin(0)
led = Pin(16)
# backlight on
bl = Pin(12, Pin.OUT, value=0)
lcd = pcd8544.PCD8544(spi, cs, dc, rst)
lcd.contrast(0x3c, pcd8544.BIAS_1_40, pcd8544.TEMP_COEFF_0)
lcd.reset()
lcd.init()
lcd.clear()
buffer = bytearray((lcd.height // 8) * lcd.width)
framebuf = framebuf.FrameBuffer1(buffer, lcd.width, lcd.height)
rtc = machine.RTC()
rtc.ntp_sync ('a.ntp.br')
rtc.init (rtc.now())
def watch():
data = strftime('%d/%m/%y')
relogio = strftime('%H:%M:%S')
lcd.position(0, 0)
while True:
framebuf.text(data, 10, 12, 1)
framebuf.text(relogio,10,24,1)
lcd.data(buffer)
agora = strftime('%H:%M:%S')
if relogio != agora:
relogio = agora
framebuf.fill(0) # clear framebuffer
utime.sleep(1)
lcd.data(buffer)
_thread.start_new_thread ("clock",watch, ())