Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Displaying text on dot matrix through Raspberry Pi GUI.
from gpiozero import Buzzer
from guizero import App, Box, Text, TextBox, PushButton, warn
from time import strftime
from datetime import datetime
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
from luma.core.virtual import viewport
from luma.led_matrix.device import max7219
from luma.core.legacy import text, show_message
from luma.core.legacy.font import proportional, CP437_FONT, LCD_FONT
buzzer = Buzzer(26)
def DisplayText():
global counter
global dotMatrixText
if len(GUIText.value) > 0:
buzzer.beep(0.1, 0.1, 1)
dotMatrixText = GUIText.value
print('GUI Text: {}'.format(dotMatrixText))
counter = 1
buzzer.beep(0.2, 0.2, 3)
warn("Text error", "Please insert text!")
def my_user_task():
global counter
global dotMatrixText
print('Counter = {}'.format(counter))
if counter == 0:
buzzer.beep(0.1, 0.1, 2)
show_message(device, 'GUI Ready!', fill="white", font=proportional(LCD_FONT), scroll_delay=0.05)
counter = 3
elif counter < 4:
if len(dotMatrixText) > 0:
show_message(device, dotMatrixText, fill="white", font=proportional(LCD_FONT), scroll_delay=0.08)
counter = 3
if counter == 10:
counter = 0
with canvas(virtual) as draw:
text(draw, (0, 1),'%I:%M'), fill="white", font=proportional(CP437_FONT))
counter = counter + 1
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, width=32, height=8, block_orientation=90)
virtual = viewport(device, width=32, height=8)
counter = 0
dotMatrixText = ''
app = App(title="LED Matrix GUI", width=350, height=150, layout="auto")
instruction_text = Text(app, text="Put your text below and click Display Text.")
instruction_text.repeat(3000, my_user_task)
designby_text = Text(app, text="Idris - Cytron Technologies", align='bottom')
display_text = PushButton(app, command=DisplayText, text="Display Text", align='bottom')
GUIText = TextBox(app, width='fill', align='bottom')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment