Introduction

Previously, you might have tried your hands with programming the Sense HAT emulator

In this guide, you will get started with using an actual Sense HAT with the Raspberry Pi 3 Model B+. 

 After completing this guide, you will have gathered real-world data using the Sense HAT.
    • Attach the Sense HAT to the Raspberry Pi by aligning and inserting the 40-pin header as shown.

    • Insert the NOOBS microSD card into the Raspberry Pi, and then power it up with the official power supply. 

    • First, to make sure the package lists are up to date: sudo apt-get update

    • Install the Sense HAT software with the following commands: sudo apt-get install sense-hat

    • Reboot the Raspberry Pi: sudo reboot

  1. sudo idle3 &
    
    • We will control the Sense HAT by first programming it in Python on the Raspberry Pi. 
      To do so, we need administrative privileges to execute scripts. So open up a terminal window and run IDLE with the following command:

    • Click on the Raspberry Pi icon on the top left hand corner to access the main menu. 

    • Click on Programming > Python 3 (IDLE). 

    • Now, create a new file by clicking File > New File. 

    • Next, save the file by clicking File > Save, and naming it sense.py

  2. from sense_hat import SenseHat
    
    sense = SenseHat()
    • First, we will import the relevant Python modules. 
      Then we will place it in a variable, called "sense".

  3. from sense_hat import SenseHat
    
    sense = SenseHat()
    
    temp = sense.get_temperature()
    pres = sense.get_pressure()
    hum = sense.get_humidity()
    • Using two of the Sense HAT's sensors, let's measure:
      Temperature in degree celsius

    • Pressure in millibars

    • Humidity as a percentage

    • We will place them in variables. 

  4. from sense_hat import SenseHat
    
    sense = SenseHat()
    
    temp = sense.get_temperature()
    pres = sense.get_pressure()
    hum = sense.get_humidity()
    
    print(temp)
    print(pres)
    print(hum)
    • Add the following lines to your code to print out the temperature, pressure and humidity readings from the Sense HAT.

    • Now click on Run > Run Module or press F5 on your keyboard to run the program.

      You should see three measurements being printed.