def __init__(self, spi=0, cs=5, dc=4, rst=8, bl=28): self.spi = SPI(spi) self.spi.init(baudrate=2000000, polarity=0, phase=0) self.cs = Pin(cs) self.dc = Pin(dc) self.rst = Pin(rst) self.bl = Pin(bl, Pin.OUT, value=1) self.lcd = pcd8544_fb.PCD8544_FB(self.spi, self.cs, self.dc, self.rst) self.buffer = bytearray((pcd8544_fb.HEIGHT // 8) * pcd8544_fb.WIDTH) self.framebuf = framebuf.FrameBuffer(self.buffer, pcd8544_fb.WIDTH, pcd8544_fb.HEIGHT, framebuf.MONO_VLSB) self.HEIGHT = pcd8544_fb.HEIGHT self.WIDTH = pcd8544_fb.WIDTH self.clear()
# Get network time from ntp. ntptime.settime() # This sets the RTC to UTC. # Get MicroPython UTC epoch time in seconds. utc_time = utime.time() # Offset UTC by timezone using 3600 seconds per hour. local_time = utc_time + 3600 * timezone # Get local time's datetime tuple. yy, mo, dd, hh, mm, ss, wkd, yrd = [d for d in utime.localtime(local_time)] # Set the RTC to local time. (I don't think the uP docs are exactly right about this.) RTC().datetime((yy, mo, dd, 0, hh, mm, ss, 0)) # Create a framebuf instance of display using SPI driver. ssd = pcd8544_fb.PCD8544_FB(spi, cs, dc, rst) # Create two Writer instances for two fonts. wri_bcf = Writer(ssd, clock, verbose=False) # Big Clock font. wri_bcf.set_clip(True, True, False) # Clip is on wri_s = Writer(ssd, small, verbose=False) # Small font line 2. wri_s.set_clip(True, True, False) # Clip is on # Create blank strings to erase display lines to eol. bcf_blank_wd = wri_bcf._charlen(' ') # Width of a big font blank px_to_eol = bcf_blank_wd # Create big blanks to clear to eol 1. bcf_clr_eol = ' ' while px_to_eol < scr_wd: bcf_clr_eol += ' ' px_to_eol += bcf_blank_wd
#Andi Dinata #01 May 2022 #Nokia 5110 display initiation part import pcd8544_fb from machine import Pin, SPI spi = SPI(1) spi.init(baudrate=8000000, polarity=0, phase=0) cs = Pin(2) dc = Pin(15) rst = Pin(0) bl = Pin(16, Pin.OUT, value=0) # backlight on display = pcd8544_fb.PCD8544_FB(spi, cs, dc, rst) #the form library part from form import * f1 = Form(display, "Volume", 0, 0, 20, 10, invert=False, fill=True) f2 = Form(display, "Total ", 0, 11, 20, 10, invert=True, fill=True) f3 = Form(display, "/liter", 0, 22, 20, 10, invert=False, fill=True) t1 = Textbox(display, "Pertamax", 0, 34) display.show()