A look at the Raspberry Pi sense hat

0
818

The Sense HAT is a sensor board which has a 8×8 RGB LED matrix, a joystick and also includes a gyroscope, accelerometer, magnetometer and temperature, barometric pressure and humidity sensors.


The Raspberry Pi Sense HAT is attached on top of the Raspberry Pi via the 40 GPIO pins (which provide the data and power interface). The Sense HAT has several integrated circuit based sensors can be used for many different types of experiments, applications, and even games.

Technical Specification:

Gyroscope – angular rate sensor: +/-245/500/2000dps
Accelerometer – Linear acceleration sensor: +/-2/4/8/16 g
Magnetometer – Magnetic Sensor: +/- 4/8/12/16 gauss
Barometer: 260 – 1260 hPa absolute range (accuracy depends on the temperature and pressure, +/- 0.1 hPa under normal conditions)
Temperature sensor (Temperature accurate to +/- 2 degC in the 0-65 degC range)
Relative Humidity sensor (accurate to +/- 4.5% in the 20-80%rH range, accurate to +/- 0.5 degC in 15-40 degC range)
8×8 LED matrix display
Small 5 button

Parts List

Name Link
Raspberry Pi 3 Model B+ 2018 new original Raspberry Pi 3 Model B+
Sense HAT Sense HAT for Raspberry Pi

Installation

Once the board is fitted to your Raspberry Pi you need to update and upgrade your system

sudo apt-get update
sudo apt-get upgrade

Then install the Sense HAT software package:

sudo apt-get install sense-hat
sudo pip3 install pillow

Reboot the Pi to complete the installation:

sudo reboot

 

Examples

from sense_hat import SenseHat
 
sense = SenseHat()
sense.set_rotation(180)
red = (255, 0, 0)
sense.show_message("Scrolly test", text_colour=red)

These are a few examples for the Sense Hat using the environmental sensors to get temperature, pressure and humidity

from sense_hat import SenseHat
sense = SenseHat()
 
while True:
    temp = sense.get_temperature()
    pres = sense.get_pressure()
    humi = sense.get_humidity()
 
    temp = round(temp, 1)
    pres = round(pres, 1)
    humi = round(humi, 1)
 
    msg = "Temperature = {0}, Pressure = {1}, Humidity = {2}".format(temp,pres,humi)
 
    sense.show_message(msg, scroll_speed=0.05)

This example will display a differing background colour on the led matrix depending on whether the temperature is higher or lower than a certain value

from sense_hat import SenseHat
sense = SenseHat()
 
while True:
    temp = sense.get_temperature()
    temp = round(temp, 1)
 
    if temp < 35:
        bg = (0, 100, 0)  # green
    else:
        bg = (100, 0, 0)  # red
 
    msg = "Temperature = {0}".format(temp)
    sense.show_message(msg, scroll_speed=0.05, back_colour=bg)

These were just some text examples for the Sense hat

from sense_hat import SenseHat
from time import sleep
 
sense = SenseHat()
green = [0, 255, 0]
sense.show_message("Hello!", text_colour=green)
from sense_hat import SenseHat
 
sense = SenseHat()
 
yellow = (255, 255, 0)
blue = (0, 0, 255)
 
message = "Hello"
 
speed = 0.05
 
sense.show_message(message, speed, text_colour=yellow, back_colour=blue)
from sense_hat import SenseHat
 
sense = SenseHat()
 
yellow = (255, 255, 0)
blue = (0, 0, 255)
 
sense.show_message("Hello!", text_colour=green)
 
speed = 0.05
 
while True:
    sense.show_message(message, speed, text_colour=yellow, back_colour=blue)

You can create simple images by setting individual pixels on the 8×8 led matrix to different colors. In these examples we create some basic flags

Swedish flag

from sense_hat import SenseHat
 
sense = SenseHat()
 
r = (255, 0, 0)
o = (255, 127, 0)
y = (255, 255, 0)
g = (0, 255, 0)
b = (0, 0, 255)
i = (75, 0, 130)
v = (159, 0, 255)
e = (0, 0, 0)
 
image = [
b,b,y,y,b,b,b,b,
b,b,y,y,b,b,b,b,
b,b,y,y,b,b,b,b,
y,y,y,y,y,y,y,y,
y,y,y,y,y,y,y,y,
b,b,y,y,b,b,b,b,
b,b,y,y,b,b,b,b,
b,b,y,y,b,b,b,b
]
 
sense.set_pixels(image)

French flag

from sense_hat import SenseHat
 
sense = SenseHat()
 
r = (255, 0, 0)
o = (255, 127, 0)
y = (255, 255, 0)
g = (0, 255, 0)
b = (0, 0, 255)
i = (75, 0, 130)
v = (159, 0, 255)
e = (0, 0, 0)
w = (255, 255, 255)
 
image = [
b,b,b,w,w,r,r,r,
b,b,b,w,w,r,r,r,
b,b,b,w,w,r,r,r,
b,b,b,w,w,r,r,r,
b,b,b,w,w,r,r,r,
b,b,b,w,w,r,r,r,
b,b,b,w,w,r,r,r,
b,b,b,w,w,r,r,r
]
 
sense.set_pixels(image)

Scottish flag

from sense_hat import SenseHat
 
sense = SenseHat()
 
r = (255, 0, 0)
o = (255, 127, 0)
y = (255, 255, 0)
g = (0, 255, 0)
b = (0, 0, 255)
i = (75, 0, 130)
v = (159, 0, 255)
e = (0, 0, 0)
w = (255, 255, 255)
 
image = [
w,b,b,b,b,b,b,w,
b,w,b,b,b,b,w,b,
b,b,w,b,b,w,b,b,
b,b,b,w,w,b,b,b,
b,b,b,w,w,b,b,b,
b,b,w,b,b,w,b,b,
b,w,b,b,b,b,w,b,
w,b,b,b,b,b,b,w
]
 
sense.set_pixels(image)
Up to 39% on Arduino &amp; DIY Modules

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.