Hardware & Sensors · Lesson 11 of 17
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.
Install Pillow
To display data on our Automation Hat Mini, we will also need the Pillow library.
We can install it via
pip install Pillow
Set up the screen
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.
Create an image
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.
Draw and display the message
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.