Lesson 1 (Displaying Messages)

From our Raspberry Pi Monitor we may connect to the Raspberry Pi with the Sense HAT.

We open the terminal

We should know the IP Address of the Raspberry Pi we will work with. In this occasion it is 192.168.1.14, so we type

ssh 192.168.1.14

We enter the password.

We get into python environment, by typing

python

We are ready to write our code in order to control the Sense HAT.

We type

from sense_hat import SenseHat

sense_hat is the library that helps us use Sense HAT, just like gpiozero helped us with the LED and the button.

We name our Sense HAT.

sense = SenseHat()

We are ready to display our first message.

sense.show_message(“hi”)

We will see it rolling on the HAT LED array.

If we want to make it rolling faster, we can type

sense.show_message(“hi”, scroll_speed=0.05)

To modify the speed, we modify the number beside scroll_speed

If we want to type only one letter, we type

sense.show_letter(“a”)

To clear it we type

sense.clear()

If we want to change the color of the text, eg red, we type

sense.show_message(“hi”, text_colour=(255, 0, 0))

Numbers (255, 0, 0) are a way to choose color in python, besides other languages as well. It is called RGB, namely Red Green Blue, because every number is mapped to a different color. You can try various numbers and see what colors are displayed.

If we want our text and our background to have colors (for example red and blue), we type

sense.show_message(“hi”, text_colour=(255, 0, 0), back_colour=(0, 0, 255))

Notes

In order to test our code we may get a Sense HAT.

These lessons are based on this link

https://astro-pi.org/resources/

As opposed to the previous lessons, where each student had his/her own Raspberry Pi, in this lesson we will all connect to the same one.

This is because Sense HAT costs around 40 euro, so for Coyote Project, but most probably for other Labs as well, there could be just one HAT available. Besides, this could be an opportunity for the students to learn how to connect to other nodes.