Hi Everyone, I’m new here so please bear with me.
I purchased a Waveshare PICO-LCD-2 (embedded ST7789VW driver, 65K colors, 320 x 240 Pixels. SPI interface) and was looking at using the picographics library to display information on the screen.
I have used the SPIBus by using from pimoroni_bus import SPIBus in my code and changing the SPI pin numbers for CS, DC, SCK, MOSI and BL and calling the spibus in the display variable for the program. I am using the default DISPLAY_PICO_DISPLAY_2 in the code as it is the same dimensions etc as the screen I have.
The code wasn’t written by me and I have just added these things into it to try and get it working with this display. But to no avail. Has anyone else had this display working with the picographics library at all?
The code I’m trying to run can be found and downloaded from here GitHub - kevinmcaleer/ghostbox (Yes I know it’s not real but it’s a bit of fun and nice to try to get it to run).
The code does run on the pico as I can see in Thonny that it is selecting the words from the file and showing them but not on the screen. The screen stays blank. The wiki page for the screen can be found here: https://www.waveshare.com/wiki/Pico-LCD-2 (Just as an aside. The demos on this wiki page do work and the screen does display them when running).
# GhostBox.py
# Kevin McAleer
# October 2022
# Note this project uses the batteries included MicroPython firmware from Pimoroni,
# which can be found here:
# www.github.com/pimoroni/pimoroni-pico
from random import choice, randrange
from time import sleep
import binascii
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_RGB565
import jpegdec
from time import sleep
from pimoroni import Button
from pimoroni_bus import SPIBus
import gc
#from gui import Listbox, hsv_to_rgb
import math
import machine
spibus = SPIBus(cs=9, dc=8, sck=10, mosi=11, bl=13)
gc.collect()
display = PicoGraphics(DISPLAY_PICO_DISPLAY_2, bus=spibus, rotate=0, pen_type=PEN_RGB565)
display.set_backlight(0.8)
WIDTH, HEIGHT = display.get_bounds()
SCALE = 1
SPACING = 1
WORD_WRAP = WIDTH -2
button_a = Button(15)
button_b = Button(17)
button_x = Button(2)
button_y = Button(3)
#led = RGBLED(6, 7, 8)
#led.set_rgb(0, 0, 0)
print(f'Width {WIDTH}, Height {HEIGHT}')
white = {'red': 255, 'green': 255, 'blue': 255}
black = {'red': 0, 'green': 0, 'blue': 0}
def draw_jpg(display, filename):
j = jpegdec.JPEG(display)
# Open the JPEG file
j.open_file(filename)
WIDTH, HEIGHT = display.get_bounds()
display.set_clip(0, 0, WIDTH, HEIGHT)
# Decode the JPEG
j.decode(0, 0, jpegdec.JPEG_SCALE_FULL)
display.remove_clip()
display.update()
GHOST_WORDS = "ghostwords.txt"
BACKGROUND = "ghostbox.jpg"
MIN_WAIT = 1
MAX_WAIT = 10
def load_ghost_words():
with open(GHOST_WORDS, "r") as f:
return f.read().splitlines()
# load the ghost words
words = load_ghost_words()
white_pen = display.create_pen(white['red'],white['green'],white['blue'])
black_pen = display.create_pen(black['red'],black['green'],black['blue'])
display.set_font('gothic')
while True:
# wait a random amount of time
wait = randrange(MIN_WAIT, MAX_WAIT)
#print(f'waiting for {wait} seconds')
sleep(wait)
display.set_pen(black_pen)
display.clear()
draw_jpg(display,BACKGROUND)
display.update()
# pick a random word
word = choice(words)
print(word)
display.set_pen(white_pen)
length = display.measure_text(word,SCALE,SPACING)
mid_point = WIDTH //2
x = mid_point - ( length // 2)
print(f'length: {length}, mid_point: {mid_point}, x: {x}')
y = 100
display.text(word, x,y,WORD_WRAP,SCALE)
display.update()
If anyone can help me I would be grateful.
Kindest Regards,
Brett