add sample code for using a waveshare 1.54in WBR epaper display
This commit is contained in:
parent
ef0dbdd1f9
commit
0011948163
77
main.py
77
main.py
|
@ -1,20 +1,75 @@
|
||||||
import uPyConfig
|
import uPyConfig
|
||||||
|
|
||||||
hw = uPyConfig.esp32(variant='wemos-lolin32')
|
hw = uPyConfig.esp32()
|
||||||
#print family, variant and IP address (using oled, if available on-board)
|
|
||||||
import webrepl
|
import webrepl
|
||||||
webrepl.start()
|
webrepl.start()
|
||||||
|
#print family, variant and IP address (using oled, if available on-board)
|
||||||
import init_sample
|
import init_sample
|
||||||
init_sample.PrintHWInfo(hw)
|
init_sample.PrintHWInfo(hw)
|
||||||
|
|
||||||
# Main app
|
# Main app
|
||||||
import uJIRA
|
from machine import Pin, TouchPad, SPI
|
||||||
from machine import Pin, TouchPad
|
import framebuf
|
||||||
jcloud = uJIRA.client('tradeprint.atlassian.net')
|
from epaper1in54b import EPD
|
||||||
auth = {
|
|
||||||
'method': 'basic-auth', #Only basic-auth is supported for now, oauth is a headache
|
|
||||||
'username': '',
|
|
||||||
'password': '',
|
|
||||||
}
|
|
||||||
|
|
||||||
jcloud.login(auth)
|
#confusingly, a 1 (interpreted in the display as 0xff) is the "off" state for the pixel
|
||||||
|
#whereas a 0 is the "on" state
|
||||||
|
c_blank=1
|
||||||
|
c_filled=0
|
||||||
|
#our display is a 200x200 display
|
||||||
|
d_w=200
|
||||||
|
d_h=200
|
||||||
|
|
||||||
|
#set up framebuffers and backing buffers
|
||||||
|
#because we have a display with three colours (red, white, black), this is presented logically
|
||||||
|
#as two separate monochrome "frames" of equal size
|
||||||
|
#so when rendering, the display_frame function will take as many frames as there are non-white colours
|
||||||
|
#this could be used for easy inversion by just swapping the order of arguments to display_frame(buf,buf)
|
||||||
|
#some documentation suggests that framebuffer should be initialised directly
|
||||||
|
#using FrameBuffer(bytearray(size..))
|
||||||
|
#however this causes problems when trying to use the fb as a buffer
|
||||||
|
#because it is not "subscriptable"
|
||||||
|
#thus the underlying buffer MUST be separated, as it cannot be directly read from inside the fb
|
||||||
|
fb_buffer_black=bytearray(d_w*d_h//8)
|
||||||
|
fb_buffer_red=bytearray(d_w*d_h//8)
|
||||||
|
fb_black=framebuf.FrameBuffer(fb_buffer_black,d_w,d_h,framebuf.MONO_HLSB)
|
||||||
|
fb_red=framebuf.FrameBuffer(fb_buffer_red,d_w,d_h,framebuf.MONO_HLSB)
|
||||||
|
fb_black.fill(c_blank)
|
||||||
|
fb_red.fill(c_blank)
|
||||||
|
|
||||||
|
#SPI is one of the more poorly documented parts of the micropython esp32 port
|
||||||
|
#i wish i could make this prettier
|
||||||
|
spi_mosi=Pin(23)
|
||||||
|
spi_miso=Pin(19)
|
||||||
|
spi_sck=Pin(18)
|
||||||
|
spi_cs=Pin(2)
|
||||||
|
spi_dc=Pin(4)
|
||||||
|
spi_rst=Pin(0)
|
||||||
|
spi_busy=Pin(15)
|
||||||
|
|
||||||
|
#set up SPI, then set up the ePaper display
|
||||||
|
#i'm using a WaveShare ePaper SPI 1.54in. display model (B) with a third colour (red)
|
||||||
|
#this example code will work identically for the model (C) with yellow as its third colour
|
||||||
|
#but is easily adaptable for other waveshare displays
|
||||||
|
spi=SPI(2,baudrate=200000,polarity=0,phase=0,mosi=spi_mosi,miso=spi_miso,sck=spi_sck)
|
||||||
|
epd=EPD(spi,cs=spi_cs,dc=spi_dc,rst=spi_rst,busy=spi_busy)
|
||||||
|
|
||||||
|
#only needs to be run once upon startup, unless the display is placed into low-power mode
|
||||||
|
#using epd.sleep(), then you need to run either epd.init() or epd.reset()
|
||||||
|
epd.init()
|
||||||
|
|
||||||
|
#helper function
|
||||||
|
def updatedisplay():
|
||||||
|
epd.display_frame(fb_buffer_black,fb_buffer_red)
|
||||||
|
|
||||||
|
updatedisplay()
|
||||||
|
from time import sleep_ms
|
||||||
|
sleep_ms(1000)
|
||||||
|
ln=0
|
||||||
|
while ln<200:
|
||||||
|
fb_black.text("what's up i'm sleepy",5,ln,c_filled)
|
||||||
|
ln+=10
|
||||||
|
fb_red.text("what's up i'm sleepy",5,ln,c_filled)
|
||||||
|
ln+=10
|
||||||
|
|
||||||
|
updatedisplay()
|
||||||
|
|
Loading…
Reference in New Issue