Getting Started with The Sense HAT – Raspberry Pi

The Raspberry Pi Sense HAT is a useful and somewhat confusingly named interface board for the RPi. It includes sensors, we can
measure Temperature, Relative humidity and Pressure. Accelerometer, Gyroscope and magnetometer are available. It also has a full-color 8*8
LED matrix display. Sense HAT requires a RPi with 40 Pin GPIO header and some softwares to be installed before you can use it.

What you will need

Hardware

  • Raspberry Pi
  • Sense HAT

Software

You will need the latest version of Raspbian which already includes the following software packages:

  • Python 3
  • Sense HAT for Python 3

If for any reason you need to install a package manually, follow these instructions:

Install the Sense HAT Python library

Install the Sense HAT Python library by using the command

 sudo apt-get install sense-hat 

This installer will actually enable I2C automatically, So you do not need to follow the usual I2C setup. Sense HAT’s Display uses a graphics library called Python Image Library (PIL), which must be installed by using the command:

sudo pip-3.2 install pillow

Installation will take a while, after which you should reboot if I2C was not already enabled.

So Now we can check that everything is working or not, by opening Python console using:

sudo python

Now enter these commands

>>> from sense_hat import SenseHat

>>> hat = SenseHat()

>>> hat.show_message('RPi Tutorials by IoTbyHVM')

Now LED matrix should then display the text of the message above, scrolling it across the screen.


You may like also: How To Use Raspberry pi in a truely headless mode


Measuring temperature, Humidity, and Pressure with a Sense HAT

Now we are going to measure temp, humd and pressure with SenseHat. Open any text editor or IDLE and Paste given below code.

and save with sense_thp.py.



# Program for measuring temperature and humidity and pressure with Sense Hat
# Visit https://iotbyhvm.ooo IoTbyHVM.ooo Explore TechBytes

from sense_hat import SenseHat
import time

hat = SenseHat()

while true:
    t = hat.get_temperature()
    h = hat.get_humidity()
    p = hat.get_preesure()
    print ('Temp C:{:.2f} Humd:{:.0f} Pres:{:.0f}' .format(t, h, p ) )
    time.sleep(1)
    

Output will like this:


sudo pyhton sense_thp.py
Temp: C:27.12 Humd:45 Pres:1232
Temp: C:27.45 Humd:44 Pres:1231

Here temp is in degree C, Humdity is in the percentage and Atmospheric Pressure is in milibars.

Sensing a Magnet with Sense HAT

Yes, you can sense magnet with Sense hat because SenseHAT  has magnetometer. Follow code given below:


# Sense magnet with SenseHAT
from sense_hat import SenseHat
import time

hat = SenseHat()
fill = (255,0,0)

while true:
    reading = int(hat.get_compass_raw()['z'])
    if reading > 200:
        hat.clear(fill)
        time.sleep(0.2)
    else:
        hat.clear()

now run this program, when the magnet gets close to SenseHAT, the LEDs will all turn red for 1/5 of a second.

Finding magnetic North with Sense HAT | How To make Compass


from sense_hat import SenseHat
import time

hat = SenseHat()

while true:
    bearing = sense.get_compass()
    print ('bearing: {:.0f} to north' .format(bearing))

Output:


sudo python sense_compass.py
Bearing : 138 to north
Bearing : 138 to north

Controlling LED with Raspberry Pi

Control LED with GPIO connector. Visit these articles given below.


You may like also:


Buy now : Raspberry PI 3 Model B+ Motherboard

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. I am a tech blogger and an IoT Enthusiast. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. Thank you for reading my blog! Happy learning! Follow and send tweets me on @harshvardhanrvm

8 thoughts on “Getting Started with The Sense HAT – Raspberry Pi

Leave a Reply

%d bloggers like this: