Waveshare e-paper display how to rotate?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
JumpZero
Posts: 27
Joined: Mon Oct 30, 2017 5:54 am
Location: Arcachon - France

Re: Waveshare e-paper display how to rotate?

Post by JumpZero » Fri Apr 26, 2019 2:08 pm

Hello,

@pythoncoder:
I’d like to have bigger fonts so I’ve check your micropython-font-to-py repo as you suggested here above.
But so far I had no success.
I understand as per your documentation that when using the writer as in:

Code: Select all

wri = Writer(device, font)
the device must inherit from framebuf
But in my code I don’t have such a device. I have tried to pass the framebuffer as a device

Code: Select all

wri = Writer(fb_portrait_black, freesans20)
but receive this error:

Code: Select all

AttributeError: 'FrameBuffer' object has no attribute 'width'
Seems normal: yes the FrameBuffer' object has no attribute 'width'

I tried to pass the EPD object:

Code: Select all

wri = Writer(e, freesans20)
But got this error:

Code: Select all

ValueError: Device must be derived from FrameBuffer.
So I’m a bit lost do I have to create an object from EPD and FrameBuffer? How can I do this?

Thanks in advance if you can help.

PS: my code is the same as posted here above + from writer import Writer + import freesans20, of course

User avatar
pythoncoder
Posts: 3655
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Waveshare e-paper display how to rotate?

Post by pythoncoder » Fri Apr 26, 2019 5:43 pm

I must admit I hadn't considered the case where someone might want to write to a framebuf and then output the result to a separate display instance. I think you'll have to create a dummy display device derived from framebuf and point the Writer at that.

I think the dummy could be along these lines. Note I haven't actually tried this:

Code: Select all

class DummyDisplay(framebuf.FrameBuffer):
    def __init__(self, width, height, mode):
        self.height = height  # your height and width in pixels
        self.width = width
        self.buffer = bytearray(height * width)
        super().__init__(self.buffer, width, height, mode)
Peter Hinch

JumpZero
Posts: 27
Joined: Mon Oct 30, 2017 5:54 am
Location: Arcachon - France

Re: Waveshare e-paper display how to rotate?

Post by JumpZero » Sun Apr 28, 2019 1:14 pm

Hi
@pythoncoder thank you very much for your support. It works! :-)
It took me sometime because I’m not comfortable enough with python class definition (self and super() are still a bit obscure, but I learn!). I had to change some minor things in this DummyDisplay class and this took me time and tries but now I can use bigger fonts.
Here is my code:

Code: Select all

import framebuf
import epaper2in13b
from machine import Pin, SPI
from writer import Writer
import freesans20

sck = Pin(13); mosi = Pin(14); cs = Pin(15); busy = Pin(25); rst = Pin(26); dc = Pin(27); 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()

class DummyDisplay(framebuf.FrameBuffer):
    def __init__(self, buffer, width, height, format):
        self.height = height
        self.width = width
        self.buffer = buffer
        self.format = format
        super().__init__(buffer, width, height, format)

w=104; h=212
buf_black = bytearray(w * h // 8)
buf_red   = bytearray(w * h // 8)
black_red = 0 # will be black on buf_black, red on buf_red
white     = 1

d_b = DummyDisplay(buf_black, w, h, framebuf.MONO_HLSB)
d_r = DummyDisplay(buf_red, w, h, framebuf.MONO_HLSB)
d_b.fill(white)
d_r.fill(white)

wri_b = Writer(d_b, freesans20, False)
Writer.set_textpos(d_b, 0, 0)  # verbose = False to suppress console output
wri_b.printstring('Sunday\n', True)
wri_b.printstring('28/04/2019\n',True)
wri_b.printstring('14:30', True)

wri_r = Writer(d_r, freesans20, False)
Writer.set_textpos(d_r, 100, 0)
wri_r.printstring('uPython\n', True)
wri_r.printstring('    :-)', True)

print('Sending to display')
e.display_frame(buf_black, buf_red)
print('Done!.......')
e.sleep()  # recommended by manufacturer to avoid damage to display
print('E-paper sleeping!...')

print('END')
Next step will be to use your font-to-py to generate some fonts!
Here is a photo of the result
Image
Thanks again I really appreciate
--
Jmp0

User avatar
pythoncoder
Posts: 3655
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Waveshare e-paper display how to rotate?

Post by pythoncoder » Mon Apr 29, 2019 6:20 am

Congratulations on getting it working. :D

I strongly recommend getting proficient with Python's object oriented capabilities, either from a book or by following an online course on a PC.
Peter Hinch

Post Reply