Skip to content

E-Paper 2.9" with ESP32 D1 R32  #23

Description

@N00BTellaBrot

Hello.

I found working code on this page: https://forum.micropython.org/viewtopic.php?f=18&t=6319&hilit=epaper+rotate#p36068
But it only works with the resolution of 212 x 104 and then only in one corner of the e-paper.
This is how it looks:
20220902_151937

Here is my code:

"""
	Example for 2.13 inch black & white & red Waveshare 2.13B E-ink screen
	Run on ESP32 Waveshare driver board (software SPI)
	Adapted by Guy -- April 2019
    We used the 2.13" E-paper in landscape mode
"""

# import epaper2in9
# import epaper2in9b
import epaper2in13b
from machine import Pin, SoftSPI

# software SPI on ESP32 Waveshare driver board
sck = Pin(18)
mosi = Pin(23)
cs = Pin(5)
busy = Pin(4)
rst = Pin(16)
dc = Pin(17)
miso = Pin(12) # miso is not used but must be declared. Let's take any unused gpio: 12
spi = SoftSPI(baudrate=100000, polarity=0, phase=0, sck=sck, mosi=mosi, miso=miso)

e = epaper2in13b.EPD(spi, cs, dc, rst, busy)
e.init()

h = 296; w = 128 # e-paper 2.9"
# h = 104;  w = 212 # e-paper heigth and width. It will be used in landscape mode

buf_black        = bytearray(w * h // 8) # used by frame buffer (landscape)
buf_red          = bytearray(w * h // 8) # used by frame buffer (landscape)
buf_epaper_black = bytearray(w * h // 8) # used to display on e-paper after bytes have been
buf_epaper_red   = bytearray(w * h // 8) # moved from frame buffer to match e-paper (portrait)

import framebuf
fb_black = framebuf.FrameBuffer(buf_black, w, h, framebuf.MONO_VLSB)
fb_red   = framebuf.FrameBuffer(buf_red,   w, h, framebuf.MONO_VLSB)
black_red = 0 # will be black on buf_black, red on buf_red
white     = 1

#clear red & black screens, write in black on top left and in red bootom right
fb_black.fill(white)
fb_red.fill(white)
fb_black.text('Hello world!', 0, 0,black_red)
fb_red.text('Hello world!', 110, 90,black_red)



# Let's draw rectangles, one black one red
fb_black.fill_rect(10, 40, 75, 10, black_red)
fb_red.fill_rect(10, 60, 75, 10, black_red)

# Move frame buffer bytes to e-paper buffer to match e-paper bytes oranisation.
# That is landscape mode to portrait mode. (for red and black buffers)
x=0; y=-1; n=0; m=0
for i in range(0, 13):
    for j in range(0, 212):
        m = (n-x)+(n-y)*12
        buf_epaper_black[m] = buf_black[n]
        buf_epaper_red[m] = buf_red[n]
        n +=1
    x = n+i+1
    y = n-1

# Now let's write text in portrait mode
fb_portrait_black   = framebuf.FrameBuffer(buf_epaper_black, h, w, framebuf.MONO_HLSB)
fb_portrait_red     = framebuf.FrameBuffer(buf_epaper_red, h, w, framebuf.MONO_HLSB)
fb_portrait_black.text('Micropython', 0, 0,black_red)
fb_portrait_red.text('Micropython', 15, 200,black_red)

# We can use EPD class to draw circle(not available in framebuf class)
# but only after we have moved bytes from framebuffers to e-paper buffers
e.draw_filled_circle(buf_epaper_black, 50, 110, 30, 1)
e.draw_filled_circle(buf_epaper_black, 50, 110, 20, 0)
e.draw_filled_circle(buf_epaper_red, 50, 150, 30, 1)
e.draw_filled_circle(buf_epaper_red, 50, 150, 20, 0)

print('Sending to display')
e.display_frame(buf_epaper_black, buf_epaper_red )
print('Done!.......')
e.sleep()  # recommended by manufacturer to avoid damage to display
print('E-paper sleeping!...')
# also recommended by manufacturer: min. 180s between 2 refresh screen

#print('Test if sleeping: Nothing should be dispayed')
#fb_black.fill(white)
#fb_red.fill(white)
#e.display_frame(buf_black, None)
print('END')

This is the result of my code:
20220902_151721

Does anyone have a solution?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions