Displaying Text

What you will do:
Create a program to display a simple four letter word on the Alphanumeric Character Display segments.

What you will learn:
How to use strings and how to display them on the segments.

Think of a word

The display on the Rainbow HAT has four blocks, and each block can display a character. If you look closely there are 14 little segments and a decimal point on each block.

For this first task, you need to think of a four letter word that you can display in public!

We chose AHOY in this picture but most people choose "Test" when asked for a word to test it out with.

We have darkened this picture of the display showing "AHOY" because it's hard to see when it's so close up!

Open a code editor

We can use Thonny Python IDE or Mu from the programming menu on the Raspberry Pi.

Whichever one you choose, open a new project.
Type in these lines of code:

import rainbowhat


The first line tells the code to use the rainbowhat library we installed earlier.

After that, we talk to the rainbowhat, to the display specifically, and ask it to print the string "Test", which puts the word "Test" into a buffer ready to use.

We have to tell it to show the contents of that buffer, which is what the last line does.

Run your code

Once you have typed in your code, run it (in Thonny and Mu, press Run). You should see the word "Test" appear on the display.

In these screenshots you will see we have also made comments (the grey text with a # before it) to explain what each part does. You do not need to add comments but it helps people reading your code to understand what each part does.

The displaying text program on Mu
The displaying text program on Thonny

Next steps

  1. We displayed the word "Test" and the word "AHOY". One was all in capitals, the other wasn't. Try the same word in upper case (capitals) and lower case.
  2. What happens when you try a 3 letter word?
  3. What happens when you try a word longer than 4 letters?
  4. Code two different words to show one after the other (hint - you will need to use import time and then time.sleep(1) in the right place).
  5. Add rainbowhat.display.clear() in the right place to clear the buffer, but remember to show the changes!

Done? Try taking a temperature reading.