Adafruit ST7789 1.54" python code

Hi,

Can anyone please point me in the right direction!

I am trying to develop a Raspberry Pi ZERO W to run 2 screens, at the moment the screens ar just running a static image, but each screen runs a different image off a single Pi. I have managed to do this using 2 x ST7735 1.44" TFT screens, but the quality is no high enough. So I have purchased 2 x Adafruit ST7789 1.54" 240 x 240 TFT screens (https://shop.pimoroni.com/products/adafruit-1-54-240x240-wide-angle-tft-lcd-display-with-microsd-st7789). I can get 1 screen working no problem, but cannot get the other working at all, I think its because the code I am using is using hardware CS & that is coded to use CE0 only, I need to run the second screen off CE1. Can anyone offer any advise on how I can do this in Python?

For info

Screen1 (ST7789) 1.54" Adafruit
Screen Label Pin # GPIO # Cable Colour
G Pin 20 Ground Green
V+ Pin 17 3v3 Yellow
CK Pin 23 BCM 11 SPI0 SCLK Purple
SI Pin 19 BCM 10 SPI0 MOSI Brown
RES Pin 22 BCM 25 Orange
DC Pin 18 BCM 24 Blue
TC Pin 24 BCM 8 SPI0 CE0 Red

Screen2 (ST7789) 1.54" Adafruit
Screen Label Pin # GPIO # Cable Colour
G Pin 39 Ground Green
V+ Pin 01 3v3 Yellow
CK Pin 40 BCM 21 (SPI1 SCLK) Purple
SI Pin 38 BCM 20 (SPI1 MOSI) Brown
RES Pin 37 BCM 26 Orange
DC Pin 31 BCM 6 Blue
TC Pin 26 BCM 7 (SPI0 CE1) Red

Please see the below code for the first screen that is working.

“”""“BEGIN CODE”""""

import digitalio
import board
from PIL import Image, ImageDraw
#import adafruit_rgb_display.ili9341 as ili9341
import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import
#import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import
#import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import
#import adafruit_rgb_display.ssd1351 as ssd1351 # pylint: disable=unused-import
#import adafruit_rgb_display.ssd1331 as ssd1331 # pylint: disable=unused-import

Configuration for CS and DC pins (these are PiTFT defaults):

cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D24)
reset_pin = digitalio.DigitalInOut(board.D25)

Config for display baudrate (default max is 24mhz):

BAUDRATE = 24000000

Setup SPI bus using hardware SPI:

spi = board.SPI()

pylint: disable=line-too-long

Create the display:

disp = st7789.ST7789(spi, rotation=90, # 2.0" ST7789

disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=180, # 1.3", 1.54" ST7789

disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789

disp = hx8357.HX8357(spi, rotation=180, # 3.5" HX8357

disp = st7735.ST7735R(spi, rotation=90, # 1.8" ST7735R

disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3, # 1.44" ST7735R

disp = st7735.ST7735R(spi, rotation=90, bgr=True, # 0.96" MiniTFT ST7735R

disp = ssd1351.SSD1351(spi, rotation=180, # 1.5" SSD1351

disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351

disp = ssd1331.SSD1331(spi, rotation=180, # 0.96" SSD1331

disp = st7789.ST7789(
spi,
height=240,
y_offset=80,
rotation=180, # 1.3", a.54" ST7789
cs=cs_pin,
dc=dc_pin,
rst=reset_pin,
baudrate=BAUDRATE,
)
#disp = ili9341.ILI9341(

spi,

rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341

cs=cs_pin,

dc=dc_pin,

rst=reset_pin,

baudrate=BAUDRATE,

#)

pylint: enable=line-too-long

Create blank image for drawing.

Make sure to create image with mode ‘RGB’ for full color.

if disp.rotation % 180 == 90:
height = disp.width # we swap height/width to rotate it to landscape!
width = disp.height
else:
width = disp.width # we swap height/width to rotate it to landscape!
height = disp.height
image = Image.new(“RGB”, (width, height))

Get drawing object to draw on image.

draw = ImageDraw.Draw(image)

Draw a black filled box to clear the image.

draw.rectangle((0, 0, width, height), outline=0, fill=(0, 0, 0))
disp.image(image)

image = Image.open("/home/pi/IMAGE.jpg")

Scale the image to the smaller screen dimension

image_ratio = image.width / image.height
screen_ratio = width / height
if screen_ratio < image_ratio:
scaled_width = image.width * height // image.height
scaled_height = height
else:
scaled_width = width
scaled_height = image.height * width // image.width
image = image.resize((scaled_width, scaled_height), Image.BICUBIC)

Crop and center the image

x = scaled_width // 2 - width // 2
y = scaled_height // 2 - height // 2
image = image.crop((x, y, x + width, y + height))

Display image.

disp.image(image)>

“”""“END OF CODE”""""

Any info on this would be appreciated. Ian

If you put your code between two ` one at the start > your code > one at the end, it will retain the formatting and be easier on the eyes. ;)