Xinyuan-LilyGO / LilyGo-T-Display-S2

47 stars 16 forks source link

Not able to get ST7789 running #7

Open cyberjunkiefr opened 2 years ago

cyberjunkiefr commented 2 years ago

Hello, I've just got a new LilyGo-T-Display-s2. As Firmware I've loaded the micropython firmware found on MicroPython.con ESP32-S2 port (GENERIC_S2-20211212-unstable-v1.17-231-g0892ebe09.bin) Everything is working fine for micropython, no issues there. I took an example program for testing the ST7789 and adapted it for my board and micropython. The program is running without any errors, I can see the backlight coming on, but the display isn't showinf anything, Some where I must have made a mistake in the pins for the display (SoftSPI), but I just can't figure it out. Maybe somebody can help. here's the progam I use:

import random import machine from machine import Pin, SPI, SoftSPI import st7789py as st7789 import time backlight = Pin(33, Pin.OUT) backlight.value(1)

spi = SPI(1, baudrate=40000000, polarity=1, sck=Pin(36), mosi=Pin(35), miso=Pin(37))

spi = SoftSPI(baudrate=500000, sck=Pin(36), mosi=Pin(35), miso=Pin(37)) display = st7789.ST7789( spi, 240, 240, reset=machine.Pin(38, Pin.OUT), dc=machine.Pin(37, 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)

I'm thankfull for any support I can get.

Roel Jaspers

NilsBe commented 2 years ago

Managed to make it work.

"""
lines.py
    Draws lines and rectangles in random colors at random locations on the
    display.
"""
import random
from machine import Pin, SPI, SoftSPI
import st7789py as st7789

def main():
    spi = SoftSPI(
        baudrate=20000000,
        polarity=1,
        phase=0,
        sck=Pin(36),
        mosi=Pin(35),
        miso=Pin(4))

    tft = st7789.ST7789(
        spi,
        135,
        240,
        reset=Pin(38, Pin.OUT),
        cs=Pin(34, Pin.OUT),
        dc=Pin(37, Pin.OUT),
        backlight=Pin(33, Pin.OUT),
        rotation=0)

    tft.fill(st7789.BLUE)

    while True:
        tft.line(
            random.randint(0, tft.width),
            random.randint(0, tft.height),
            random.randint(0, tft.width),
            random.randint(0, tft.height),
            st7789.color565(
                random.getrandbits(8),
                random.getrandbits(8),
                random.getrandbits(8)
                )
            )

        width = random.randint(0, tft.width // 2)
        height = random.randint(0, tft.height // 2)
        col = random.randint(0, tft.width - width)
        row = random.randint(0, tft.height - height)
        tft.fill_rect(
            col,
            row,
            width,
            height,
            st7789.color565(
                random.getrandbits(8),
                random.getrandbits(8),
                random.getrandbits(8)
            )
        )

main()