Displaying data on Automation Hat Mini LCD
In this example, we will cover how to write something on an LCD screen using Python. We're using something called an ST7735 display, and we are going to write 'Hello World' on it.
To display data on our Automation Hat Mini, we will also need the Pillow library.
We can install it via
pip install Pillow
So, the first thing we do is set up the ST7735 screen.
We do this by giving it various settings, like which port to use, how to control the backlight, and how fast it should talk to the Raspberry Pi. Once we've done that, we tell the screen to turn on.
After the screen's on, we need something to display. We're going to use a handy Python tool called Pillow. With Pillow, we make a pretend 'screen' in the program that we can draw on. This pretend screen is called an `Image`. So, we create this Image and make it all black - think of it as like the blank screen on an old television.
Next, we need to prepare the image for our content. We do this using a utility from the Pillow library named `draw`. With this, we set the initial state of our image to be entirely black, effectively ensuring that the screen is clear. After clearing the screen, we use `draw.text()` to write 'Hello World' on our prepped image in white color.
At this point, we have a black Image with 'Hello World' written in white, but it's still just in our program. The final step is to show this Image on the actual ST7735 screen. We do this with `disp.display(img)` which takes the Image from our program and puts it on the ST7735 display for everyone to see.
Full Code Example
Funded by the European Union. Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Education and Culture Executive Agency (EACEA). Neither the European Union nor EACEA can be held responsible for them.
Project Number: 2023-3-CY02-KA210-YOU-000173087