Pi Pico W and ST7789 display problem

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
FeK9
Posts: 33
Joined: Sun Jan 20, 2019 8:19 am

Pi Pico W and ST7789 display problem

Post by FeK9 » Wed Sep 14, 2022 11:25 am

Good Day All

I've been experimenting with a Waveshare 320x240 with ST7789 driver, I've searched high and low for an answer with no success... :(
https://www.waveshare.com/pico-restouch-lcd-2.8.htm

I have used the firmware and example and cfg_helper.py from 'russhughes' github https://github.com/russhughes/st7789_mpy and I repeatedly get the same syntax error shown below...

Code: Select all

>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 10, in <module>
  File "tft_config.py", line 16
SyntaxError: invalid syntax
>>> 
Line 16 in tft_config.py is this line "for rotation 0 use offset(0, 0)" found in tft_config.py which is shown below...

Code: Select all

# Generic st7735 128x128 OR 128X160 display
BAUDRATE = 30000000
COLUMNS = 240
ROWS = 320
SCK_PIN = 10
MOSI_PIN = 11
RESET_PIN = 12
CS_PIN = 9
DC_PIN = 8
BACKLIGHT_PIN = 13

rotation = 0
madctl = 0x00 ()
inversion_mode(True)
color_order = st7789.RGB
for rotation 0 use offset(0, 0)
for rotation 1 use offset(0, 0)
for rotation 2 use offset(0, 0)
for rotation 3 use offset(0, 0)
The main example used is also shown below...

Code: Select all

"""
hello.py

    Writes "Hello!" in random colors at random locations on the display.
"""

import random
import utime
import st7789
import tft_config
import vga1_bold_16x32 as font

tft = tft_config.config(0)

def center(text):
    length = len(text)
    tft.text(
        font,
        text,
        tft.width() // 2 - length // 2 * font.WIDTH,
        tft.height() // 2 - font.HEIGHT,
        st7789.WHITE,
        st7789.RED)

def main():
    tft.init()

    tft.fill(st7789.RED)
    center("Hello!")
    utime.sleep(2)
    tft.fill(st7789.BLACK)

    while True:
        for rotation in range(4):
            tft.rotation(rotation)
            tft.fill(0)
            col_max = tft.width() - font.WIDTH*6
            row_max = tft.height() - font.HEIGHT

            for _ in range(128):
                tft.text(
                    font,
                    "Hello!",
                    random.randint(0, col_max),
                    random.randint(0, row_max),
                    st7789.color565(
                        random.getrandbits(8),
                        random.getrandbits(8),
                        random.getrandbits(8)),
                    st7789.color565(
                        random.getrandbits(8),
                        random.getrandbits(8),
                        random.getrandbits(8)))


main()

What am I not seeing... :?:

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Pi Pico W and ST7789 display problem

Post by Roberthh » Wed Sep 14, 2022 11:31 am

These lines ate not valid Python statements. They look more like comments. So add the comment char.

FeK9
Posts: 33
Joined: Sun Jan 20, 2019 8:19 am

Re: Pi Pico W and ST7789 display problem

Post by FeK9 » Wed Sep 14, 2022 11:39 am

Roberthh wrote:
Wed Sep 14, 2022 11:31 am
These lines ate not valid Python statements. They look more like comments. So add the comment char.
Hi Roberthh

The tft_config.py is also mentioned in the docs on russhughes github page, he even gives an example and the cfg_helper.py of his generates the same tft_config.py..

FeK9
Posts: 33
Joined: Sun Jan 20, 2019 8:19 am

Re: Pi Pico W and ST7789 display problem

Post by FeK9 » Wed Sep 14, 2022 12:14 pm

Roberthh wrote:
Wed Sep 14, 2022 11:31 am
These lines ate not valid Python statements. They look more like comments. So add the comment char.
Solved...

Thank's for the suggestion, I redid the tft_config.py...

I'm a dummy, I took the output of cfg_helper.py as a given, the doc was not to clear...

This tft_config.py works... :D

Code: Select all

from machine import Pin, SPI
import st7789

TFA = 0 # top free area when scrolling
BFA = 0 # bottom free area when scrolling

def config(rotation=0, buffer_size=0, options=0):
    return st7789.ST7789(
        SPI(1, baudrate=30000000, sck=Pin(10), mosi=Pin(11)),
        240,
        320,
        reset=Pin(12, Pin.OUT),
        cs=Pin(9, Pin.OUT),
        dc=Pin(8, Pin.OUT),
        backlight=Pin(13, Pin.OUT),
        rotation=rotation,
        options=options,
        buffer_size=buffer_size)

Post Reply