Python Forum
python script for gfx hat (LCD for raspberry)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python script for gfx hat (LCD for raspberry)
#1
Hy,
i have bought a LCD for my beautifull Pi :)

My LCD is the GFX hat : https://shop.pimoroni.com/products/gfx-hat

There is an Example for script python but i don't understand, i am a very very very rookie in Python Scripts.

what i am looking for with my lcd :

Below the screen : display text like "Hello", "name", etc...

Top the screen : display Pictogram wich are in this folder "/diagbox/pictures"

for example :
When the Pi starts, switch on the LCD and display "Hello, boot in progress"
After, when the wlan0 and eth0 are up, display a pictogramm for the eth0 and for the wlan0

And leave the screen on, as long as the pi is on.


Thank by Advance

Thereafter the script give with the Equipment :

#!/usr/bin/env python

import time
import signal

from gfxhat import touch, lcd, backlight, fonts
from PIL import Image, ImageFont, ImageDraw

print("""hello-world.py

This basic example prints the text "Hello World" in the middle of the LCD

Press any button to see its corresponding LED toggle on/off.

Press Ctrl+C to exit.

""")

led_states = [False for _ in range(6)]

width, height = lcd.dimensions()

image = Image.new('P', (width, height))

draw = ImageDraw.Draw(image)

font = ImageFont.truetype(fonts.AmaticSCBold, 38)

text = "Hola gringo"

w, h = font.getsize(text)

x = (width - w) // 2
y = (height - h) // 2

draw.text((x, y), text, 1, font)

def handler(ch, event):
    if event == 'press':
        led_states[ch] = not led_states[ch]
        touch.set_led(ch, led_states[ch])
        if led_states[ch]:
            backlight.set_pixel(ch, 0, 255, 255)
        else:
            backlight.set_pixel(ch, 0, 255, 0)
        backlight.show()

for x in range(6):
    touch.set_led(x, 1)
    time.sleep(0.1)
    touch.set_led(x, 0)

for x in range(6):
    backlight.set_pixel(x, 0, 255, 0)
    touch.on(x, handler)

backlight.show()

for x in range(128):
    for y in range(64):
        pixel = image.getpixel((x, y))
        lcd.set_pixel(x, y, pixel)


lcd.show()

try:
    signal.pause()
except KeyboardInterrupt:
    for x in range(6):
        backlight.set_pixel(x, 0, 0, 0)
        touch.set_led(x, 0)
    backlight.show()
    lcd.clear()
    lcd.show()
Reply


Messages In This Thread
python script for gfx hat (LCD for raspberry) - by domoticity - Jun-30-2019, 08:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Re-write BASH script to Python script popi75 5 2,605 Apr-30-2021, 03:52 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020