Xinyuan-LilyGO / T-Display-S3

MIT License
818 stars 202 forks source link

Need a working example of using lilygo S3 T display with circuit python. #285

Open hartmutbohmer opened 2 weeks ago

hartmutbohmer commented 2 weeks ago

Code below reviewed as fine by AI. Also tried downloading latest build bin and driver.

Need a working example i can expand on. I used AI to get display ST7735R going. The newer parallelbus seems to confuse AI a bit even after feeding it with AI android examples using ST7789 with parallelbus. So below find the output of a using my free AI credits over a 24 hour period. Any hint how to move forward will be appreciated. Even if you say i need to wait 6 months for AI to catch up thats also fine.

import board import displayio import paralleldisplaybus from adafruit_st7789 import ST7789 import terminalio from adafruit_display_text import label import digitalio import time

Release any resources currently in use for the displays

displayio.release_displays()

Define pins using board LCD definitions

data_pins = [ board.LCD_D0, board.LCD_D1, board.LCD_D2, board.LCD_D3, board.LCD_D4, board.LCD_D5, board.LCD_D6, board.LCD_D7, ]

Initialize control pins

command = board.LCD_DC chip_select = board.LCD_CS write = board.LCD_WR read = board.LCD_RD reset = board.LCD_RST # Use Pin directly instead of DigitalInOut

Initialize power and backlight with proper sequencing

power = digitalio.DigitalInOut(board.LCD_POWER_ON) power.direction = digitalio.Direction.OUTPUT bl = digitalio.DigitalInOut(board.LCD_BCKL) bl.direction = digitalio.Direction.OUTPUT

Full power-down sequence

power.value = False bl.value = False time.sleep(0.5) # Longer delay to ensure full discharge

Power-up sequence

power.value = True time.sleep(0.1)

Turn on backlight

bl.value = True time.sleep(0.2)

Create ParallelBus object

display_bus = paralleldisplaybus.ParallelBus( data_pins=data_pins, command=command, chip_select=chip_select, write=write, read=read, reset=reset, frequency=30000000 )

Initialize display

display = ST7789( display_bus, width=320, height=170, rowstart=35, colstart=0, rotation=0 )

Create main display group

main_group = displayio.Group()

Create a full-screen colored rectangle

color_bitmap = displayio.Bitmap(display.width, display.height, 1) color_palette = displayio.Palette(1) color_palette[0] = 0xFF0000 # Start with red color_rect = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) main_group.append(color_rect)

Create text label

text_label = label.Label( terminalio.FONT, text="Hello T-Display-S3!", color=0xFFFFFF, # White text scale=3, # Make text larger anchor_point=(0.5, 0.5), anchored_position=(display.width // 2, display.height // 2) ) main_group.append(text_label)

Show the main group initially

display.root_group = main_group

Color animation loop

colors = [0xFF0000, 0x00FF00, 0x0000FF] # Red, Green, Blue

while True: for color in colors:

Update the entire palette with new color

    color_palette[0] = color

    # Update the display with the new color
    display.root_group = main_group  # Ensures the display updates with the root group

    # Delay to create the animation effect
    time.sleep(2)