Introduction
Last week I have shared a tutorial on how to create a simple GUI using Raspberry Pi. Now we try to extend the application of GUI by displaying text on dot matrix. Before that, please go through a few tutorials related to dot matrix and Raspberry Pi first.
- Displaying on MAX7219 Dot Matrix Using Raspberry Pi
- Displaying Text Message on Dot Matrix Using Blynk App and Raspberry Pi
Video
This video will show you how to display text on dot matrix using the GUI that we developed at Raspberry Pi.
Hardware Preparation
This is the list of items used in the video.
Sample Program
This is the sample code to control servo and display sensor’s reading using GUI on Raspberry Pi.
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 | |
else: | |
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) | |
else: | |
counter = 3 | |
else: | |
if counter == 10: | |
counter = 0 | |
with canvas(virtual) as draw: | |
text(draw, (0, 1), datetime.now().strftime('%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) | |
device.contrast(5) | |
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') | |
app.display() |
Thank You
References:
- Raspberry Pi: Getting started with GUIs
- GUI library package – guizero
- Create a Simple GUI to Control LEDs
- Displaying on MAX7219 Dot Matrix Using Raspberry Pi
- Displaying Text Message on Dot Matrix Using Blynk App and Raspberry Pi
Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.