after 3 days struggling with that I come here to ask for help, if possible.
I have a Waveshare ESP32 driver board + 2.13inch e-paper display (B model: 3 colors)
I have successfully flashed Micropython : MicroPython v1.10-54-g43a894fb4 on 2019-02-07; ESP32 module with ESP32
I use mcauser Micropython display driver and have successfully modified the SPI pins declaration in the exemple code to match that board.
It works. So far so good! I can print text, rectangles, lines, manage the colors
Here is the code
Code: Select all
"""
Example for 2.13 inch black & white & red Waveshare 2.13B E-ink screen
Run on ESP32 Waveshare driver board (software SPI)
Adapted by me -- April 2019
"""
import epaper2in13b
from machine import Pin, SPI
# software SPI on ESP32 Waveshare driver board
sck = Pin(13)
mosi = Pin(14)
cs = Pin(15)
busy = Pin(25)
rst = Pin(26)
dc = Pin(27)
# miso is not used but must be declared. Let's take any unused gpio: 12
miso = Pin(12)
spi = SPI(baudrate=100000, polarity=0, phase=0, sck=sck, mosi=mosi, miso=miso)
e = epaper2in13b.EPD(spi, cs, dc, rst, busy)
e.init()
w = 104
h = 212
x = 0
y = 0
# --------------------
# use a frame buffer
# 212 * 104 / 8 = 2756 - that's some pixels
import framebuf
buf = bytearray(w * h // 8)
fb = framebuf.FrameBuffer(buf, w, h, framebuf.MONO_HLSB)
black = 0
white = 1
fb.fill(white)
# --------------------
# write hello world with black bg and white text
# from toto import hello_world_dark
from image_dark import hello_world_dark
from image_light import hello_world_light
print('Image dark')
bufImage = hello_world_dark
fbImage = framebuf.FrameBuffer(bufImage, 128, 296, framebuf.MONO_HLSB)
fb.blit(fbImage, 20, 2)
bufImage = hello_world_light
fbImage = framebuf.FrameBuffer(bufImage, 128, 296, framebuf.MONO_HLSB)
fb.blit(fbImage, 168, 2)
# e.display_frame(buf)
e.display_frame(buf, buf)
# --------------------
# write hello world with white bg and black text
print('Image light')
#e.display_frame(hello_world_light)
# --------------------
print('Frame buffer things')
fb.fill(white)
fb.text('Hello World',30,0,black)
fb.pixel(30, 10, black)
fb.hline(30, 30, 10, black)
fb.vline(30, 50, 10, black)
fb.line(30, 70, 40, 80, black)
fb.rect(30, 90, 10, 10, black)
fb.fill_rect(30, 110, 10, 10, black)
for row in range(0,36):
fb.text(str(row),0,row*8,black)
fb.text('Line 36',0,288,black)
#e.display_frame(buf)
e.display_frame(buf, buf)
# --------------------
# wrap text inside a box
black = 0
white = 1
# clear
fb.fill(white)
# display as much as this as fits in the box
str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vel neque in elit tristique vulputate at et dui. Maecenas nec felis lectus. Pellentesque sit amet facilisis dui. Maecenas ac arcu euismod, tempor massa quis, ultricies est.'
# this could be useful as a new method in FrameBuffer
def text_wrap(str,x,y,color,w,h,border=None):
# optional box border
if border is not None:
fb.rect(x, y, w, h, border)
cols = w // 8
# for each row
j = 0
for i in range(0, len(str), cols):
# draw as many chars fit on the line
fb.text(str[i:i+cols], x, y + j, color)
j += 8
# dont overflow text outside the box
if j >= h:
break
# clear
fb.fill(white)
# draw text box 1
# box position and dimensions
print('Box 1')
bx = 8
by = 8
bw = 112 # = 14 cols
bh = 112 # = 14 rows (196 chars in total)
text_wrap(str,bx,by,black,bw,bh,black)
#e.display_frame(buf)
e.display_frame(buf, buf)
# draw text box 2
print('Box 2 & 3')
bx = 0
by = 128
bw = w # 128 = 16 cols
bh = 6 * 8 # 48 = 6 rows (96 chars in total)
text_wrap(str,bx,by,black,bw,bh,black)
# draw text box 3
bx = 0
by = 184
bw = w//2 # 64 = 8 cols
bh = 8 * 8 # 64 = 8 rows (64 chars in total)
text_wrap(str,bx,by,black,bw,bh,None)
#e.display_frame(buf)
e.display_frame(buf, buf)
# --------------------
I have tried to define the frame buffer 212x104 and use the text method of frame buffer but it’s displaying garbage.
There is a rotate function in mcauser’s driver but calling it: e.set_rotate(1)
has no effect as well, display is the same as without calling it.
A combination of declaring the framebuffer 212x104 and calling the rotate function doesn’t work either.
My understanding is that this function works on the frame buffer only (not modifying the way e.display_frame(buf, buf) will display) same for other functions circle, line, rectangle, etc..
The e-paper display (as I understand) display bytes from top corner left (104x212 WxH) with bit 0 being the leftmost. So rotating the framebuffer itself should work, but unfortunately there is no such method in the framebuffer class.
Does anybody have an idea? another library? a function to rotate the framebuffer? Or anything else?
Thanks