Select Page

Lesson 2 (measuring temperature)

We connect to the Raspberry Pi with the Sense HAT like in the previous lesson and we enter to python environment.

We prepare Sense HAT like before, as well.

from sense_hat import SenseHat
sense = SenseHat()

To find out what temperature we have at the moment, we type:


If we need to store the temperature value, we type

temp = sense.get_temperature()

We stored the value and we gave it a name: temp

In programming, this is called a variable. The value of the variable is the temperature value we measured.

To see the value again, we type


The number is long, so we can shorten it by rounding it.

temp = round(temp, 2)

We confirm that it is rounded now


Try to display the temperature on Sense HAT array


The command will fail. This is happening because temp variable is a number and HAT displays only letters. So we turn our variable to a word (in programming this is called “alphanumerical”) with this command

temp = str(temp)

And we try again.