Page 1 of 1

Display on TTGO T-Display

Posted: Mon Dec 30, 2019 10:54 pm
by crowndip
Hello,

did someone manage to make work the display on the TTGo T-Display board?

It seems it is a ST7789V with 135 x 240 resolution. I tried example from https://github.com/devbis/st7789py_mpy changing the resolution and pins but i get no response whatsoever. Can please someone point me in the right direction?

Thanks

Code: Select all

import random

import machine
import st7789py as st7789
import time


def main():
    spi = machine.SPI(1, baudrate=40000000, polarity=1)
    display = st7789.ST7789(
        spi, 135, 240,
        reset=machine.Pin(23, machine.Pin.OUT),
        dc=machine.Pin(16, machine.Pin.OUT),
    )
    display.init()

    while True:
        display.fill(
            st7789.color565(
                random.getrandbits(8),
                random.getrandbits(8),
                random.getrandbits(8),
            ),
        )
        # Pause 2 seconds.
        time.sleep(2)

Re: Display on TTGO T-Display

Posted: Wed Jan 01, 2020 9:55 pm
by russ_h
I used the c version https://github.com/devbis/st7789py_mpy and it works. There was an update about 5 days ago for the 135x240 TTGO display that worked for me. I'll see if I can test the python version.

Re: Display on TTGO T-Display

Posted: Wed Jan 01, 2020 10:10 pm
by russ_h
This works for me on my TTGO board using the python driver.

Code: Select all

import time
import random
import machine
import st7789py

# turn on backlight
bl = machine.Pin(4, machine.Pin.OUT)
bl.value(1)

spi = machine.SPI(
    2,
    baudrate=20000000,
    polarity=1,
    phase=1,
    sck=machine.Pin(18),
    mosi=machine.Pin(19))

display = st7789py.ST7789(
    spi, 135, 240,
    reset=machine.Pin(23, machine.Pin.OUT),
    cs=machine.Pin(5, machine.Pin.OUT),
    dc=machine.Pin(16, machine.Pin.OUT))

display.init()

while True:
    display.fill(
        st7789py.color565(
            random.getrandbits(8),
            random.getrandbits(8),
            random.getrandbits(8),
        ),
    )
    time.sleep(2)

Re: Display on TTGO T-Display

Posted: Thu Jan 02, 2020 10:09 pm
by crowndip
... and it works for me as well. Thanks, you saved my day !!!

I looked at the library and the best it allows are lines. Is there a way to send text to the display using some other library?

Re: Display on TTGO T-Display

Posted: Sat Jan 04, 2020 6:25 am
by russ_h
This driver is not framebuf based so there is more work involved. One possibility is to use Peter Hinch's https://github.com/peterhinch/micropython-font-to-py program to create fonts and use his writer routine to write text to a buffer using the font. From there you could use blit_buffer to write the buffer to the screen. I haven't tried it but it looks like it would work.

Re: Display on TTGO T-Display

Posted: Sun Jan 05, 2020 11:02 am
by pythoncoder
See my response to this query.

tl;dr It should work with minor adaptation.

Re: Display on TTGO T-Display

Posted: Tue Jan 07, 2020 6:04 am
by russ_h

Re: Display on TTGO T-Display

Posted: Tue Jan 07, 2020 8:14 am
by pythoncoder
Interesting. That uses a random access file for storing fonts. I used that approach on e-paper displays. E-paper displays are slow to update so this works fine, but I found it to be too slow for other display technologies. The other benefit of my approach is that there is a conversion route from any ttf or otf font - I'm not sure if there is a utility to create Hershey fonts from these.

The principal drawback of my approach is that to get the benefit of minimal RAM usage you have to build the Python font files as frozen bytecode, whereas the random access file approach does not require this.

Re: Display on TTGO T-Display

Posted: Tue Jan 07, 2020 8:46 pm
by russ_h
Frozen bytecode of a raster font would be a better solution for most displays. My original use is in a slow moving robot plotter where ease of use was more important then speed. It's not really a practical solution for displays, still it's cute enough to show off and maybe it will be of use to someone.

There is a program on github that will convert other types of fonts to Hershey fonts that I plan to play around with when I get time.

Re: Display on TTGO T-Display

Posted: Sat Jan 11, 2020 7:09 pm
by russ_h
I took Peter's suggestion and used his bytearray method and it's definitely faster. I haven't tried feezing the bytecode yet. Both methods are now in my GitHub repo. Here is a side by side video showing both methods.