boochow / MicroPython-ST7735

ST7735 TFT LCD driver for MicroPython
202 stars 64 forks source link

Buffer example has wrong orientation #10

Closed DedFishy closed 1 year ago

DedFishy commented 1 year ago

Hello again. There seems to be an issue regarding the FrameBuffer example, where it's rendered in portrait as opposed to landscape, which is how most screens are oriented. Is there a way to get around this problem?

boochow commented 1 year ago

@SuperBoyne use tft.rotation(2) to change the screen orientation.

DedFishy commented 1 year ago

I noticed that method, but when I use that it seemed to just cause the screen to either go completely black or just stay how it was, depending on where I called it in the code.

boochow commented 1 year ago

@SuperBoyne this code works for me.

from machine import SPI,Pin
from ST7735 import TFT
spi = SPI(0, baudrate=20000000, polarity=0, phase=0, sck=Pin(2), mosi=Pin(3), miso=Pin(0))
tft=TFT(spi,4,5,1)
tft.initr()
tft.rgb(True)
tft.rotation(2)
tft.fill(TFT.BLACK)

from framebuf import FrameBuffer, RGB565
buf = bytearray(128*160*2)
fb = FrameBuffer(buf, 128, 160, RGB565)

tft._setwindowloc((0,0),(127,159))

size=20
h_size=10
(xmax, ymax) = (128-size, 160-size)
(x, y) = (size, size)
(vx, vy) = (1, 1)

while True:
    fb.fill(0)
    fb.ellipse(x, y, size, size, 0xffff, True)
    fb.ellipse(x - h_size, y - h_size, h_size, h_size, 0x1f, True)
    fb.ellipse(x + h_size, y - h_size, h_size, h_size, 0xf800, True)
    x += vx
    if x == xmax or x == size:
        vx = -vx
    y += vy
    if y == ymax or y == size:
        vy = -vy
    tft._writedata(buf)
DedFishy commented 1 year ago

I had to set the rotation to 1 and switch around the _setwindowloc and FrameBuffer size value X and Y, but it ended up working! Thank you so much for all the help you've given me!