Connecting LOLIN/WEMOS D32Pro V2.0 and 2.13 Inch e-paper

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
jamonda
Posts: 36
Joined: Thu May 21, 2020 3:48 pm

Re: Connecting LOLIN/WEMOS D32Pro V2.0 and 2.13 Inch e-paper

Post by jamonda » Mon Nov 30, 2020 7:22 pm

Hi, friends!
I would ask for a real life example/how to but I've just found it on GitHub: https://github.com/T-Wilko/MicroPython- ... /epaper.py
I look forward to see the driver for landscape orientation.
Thank you , T-Wilko!

snurre
Posts: 2
Joined: Tue Dec 22, 2020 8:37 pm

Re: Connecting LOLIN/WEMOS D32Pro V2.0 and 2.13 Inch e-paper

Post by snurre » Tue Dec 22, 2020 9:19 pm

Hi!

I've created a landscape hack using a new framebuffer.

My work is also based on T-Wilko's IL3897-driver:
https://github.com/T-Wilko/MicroPython-IL3897-driver

Based on the example there:

Code: Select all

import epaper
import framebuf

width = 256     # 250x122 pixels/bits, but need whole bytes for easy copy to the screen
height = 128

e = epaper.EPD()
e.init()
e.clearBuffer()

widebuf = bytearray(width*height // 8)
wf = framebuf.FrameBuffer(widebuf, width, height, framebuf.MONO_HLSB)

black = 0
white = 1

wf.fill(white)
wf.text("Hello wide WORLD!", 50, 100, black)

wf.line(0, 0, 249, 0, black)
wf.line(0, 0, 0, 121, black)
wf.line(0, 121, 249, 121, black)
wf.line(249, 121, 249, 0, black)

def displayRotatedBuffer():
    global height, width, wf, e
    TERMINATE_FRAME_READ_WRITE = const(0xFF) # not in datasheet, aka NOOP
    BYTES_PER_LINE = 16

    rotatebuf = bytearray(width*height // 8)
    rf = framebuf.FrameBuffer(rotatebuf, height, width, framebuf.MONO_HLSB)

    # Rotate the wide buffer 90 deg
    for x in range(0, 122):
        for y in range(0, 250):
            rf.pixel(x, y, wf.pixel(250 - y, x))

    e._command(b'\x24')
    for y in range(0, 250):
        for x in range(0, BYTES_PER_LINE):
            e._data(bytearray([rotatebuf[y * BYTES_PER_LINE + x]]))
    e._command(b'\x22')
    e._command(b'\xC7')
    e._command(b'\x20')
    e._command(bytearray([TERMINATE_FRAME_READ_WRITE]))
    e.wait_until_idle()


displayRotatedBuffer()

Again, this is a hack, we spimply create a new framebuffer and just rotate and copy all pixels to this before displaying it. The code is not optimized for speed or memory usage, rotating and displaying takes maybe three seconds.

I have the LILYGO TTGO T5 V2.3 board btw, https://www.aliexpress.com/item/32869729970.html, and had to do some small changes to the epaper.py file to map the correct pins. If anyone else use this board, I've included the changes here.

Code: Select all

class EPD:
    def __init__(self):
        self.spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
        self.spi.init()

        dc = Pin(17)
        cs = Pin(5)
        rst = Pin(16)

snurre
Posts: 2
Joined: Tue Dec 22, 2020 8:37 pm

Re: Connecting LOLIN/WEMOS D32Pro V2.0 and 2.13 Inch e-paper

Post by snurre » Sun Dec 27, 2020 10:03 pm

Shorter and rotation both ways.

Code: Select all

width = 250
height = 122

j_width = (width + 7) & 0xfff8      # Rounded up to next whole byte
j_height = (height + 7) & 0xfff8

widebuf = bytearray(j_width * height // 8)
wf = framebuf.FrameBuffer(widebuf, j_width, height, framebuf.MONO_HLSB)

def displayRotatedBuffer90():
    global height, width, j_width, j_height, wf, e
    rotatebuf = bytearray(j_height * width // 8)
    rf = framebuf.FrameBuffer(rotatebuf, j_height, width, framebuf.MONO_HLSB)
    # Rotate the wide buffer 90 deg
    for x in range(0, height):
        for y in range(0, width):
            rf.pixel(x, y, wf.pixel(width - y, x))
    e.displayBuffer(rotatebuf)

def displayRotatedBuffer270():
    global height, width, j_width, j_height, wf, e
    rotatebuf = bytearray(j_height * width // 8)
    rf = framebuf.FrameBuffer(rotatebuf, j_height, width, framebuf.MONO_HLSB)
    # Rotate the wide buffer 270 deg
    for x in range(0, height):
        for y in range(0, width):
            rf.pixel(height - x, y, wf.pixel(y, x))
    e.displayBuffer(rotatebuf)

Post Reply