Display on TTGO T-Display

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
crowndip
Posts: 2
Joined: Mon Dec 30, 2019 10:50 pm

Display on TTGO T-Display

Post by crowndip » Mon Dec 30, 2019 10:54 pm

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)

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: Display on TTGO T-Display

Post by russ_h » Wed Jan 01, 2020 9:55 pm

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.

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: Display on TTGO T-Display

Post by russ_h » Wed Jan 01, 2020 10:10 pm

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)

crowndip
Posts: 2
Joined: Mon Dec 30, 2019 10:50 pm

Re: Display on TTGO T-Display

Post by crowndip » Thu Jan 02, 2020 10:09 pm

... 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?

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: Display on TTGO T-Display

Post by russ_h » Sat Jan 04, 2020 6:25 am

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.

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

Re: Display on TTGO T-Display

Post by pythoncoder » Sun Jan 05, 2020 11:02 am

See my response to this query.

tl;dr It should work with minor adaptation.
Peter Hinch
Index to my micropython libraries.

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: Display on TTGO T-Display

Post by russ_h » Tue Jan 07, 2020 6:04 am


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

Re: Display on TTGO T-Display

Post by pythoncoder » Tue Jan 07, 2020 8:14 am

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.
Peter Hinch
Index to my micropython libraries.

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: Display on TTGO T-Display

Post by russ_h » Tue Jan 07, 2020 8:46 pm

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.

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: Display on TTGO T-Display

Post by russ_h » Sat Jan 11, 2020 7:09 pm

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.

Post Reply