A collection of codes designed for Raspberry Pi Sense HAT can be found on my GitHub site.

# Update the package list, update all packages and remove any packages that are no longer required on your Raspberry Pi
sudo apt-get update -y && sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y

Using GitHub with your Sense HAT

For the following steps, you have to ssh into your Respberry Pi:

ssh pi@raspberrypi

The default password for user pi is raspberry. You can change this following the procedure described at the Raspberry Pi page.

  • First create a new repository:

echo "# sensehat" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:tarikgit/sensehat.git
git push -u origin master
  • Tell GitHub who you are:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
  • Generate a new SSH key

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Press Enter to set a default file location. When asked to Enter passphrase …​, provide a safe password.

  • Add new SSH key to your GitHub account

    • Copy the SSH key to your clipboard

Open id_rsa.pub:

cat ../.ssh/id_rsa.pub
# assuming that the current folder is /home/pi/sensehat

Copy the key and paste it into GitHub

  • Push your first commit

git commit -m "initial commit"
git push origin master
  • Putting all the commands into a sequence:

git add *
git commit  -m "description of commit"
git push

Sources:

Using the Raspberry Pi Sense HAT and Scratch 2 (not tested)

Check your system, if you have a more recent version, Scratch 3 may be available.

Update your Raspberry Pi

sudo aptitude update
sudo aptitude safe-upgrade

Install Scratch on your Raspberry Pi:

sudo aptitude install scratch2

In order to use the interface of Scratch, you can use Remote Desktop Server on your Raspberry Pi. This will allow you to connect to your Raspberry Pi from another device. This is particularly useful if you don’t have a screen, keyboard and mouse connected to your Raspberry Pi.

One approach to set up a Remote Desktop Server, is to install VNC (Virtual Network Computing) on your Raspberry Pi:

sudo apt-get install vnc4server

On your Raspberry, retrieve the local IP address:

hostname -I

You can then install on your laptop, tablet or desktop a VNC viewer.

Temperature and Humidity Sensor

Use your SenseHat to get the temperature and humidity using the joystick of the device.

from sense_hat import SenseHat
from time import sleep

sense = SenseHat()

#sense.set_rotation(270)
sense.clear()

red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)



def temperature():
    temp = sense.get_temperature()
    print(temp)
    if temp > 34:
        sense.clear(red)
    elif temp < 34 and temp > 24:
        sense.clear(green)
    elif temp < 24 and temp > 0:
        sense.clear(blue)
    sleep(1)

    sense.show_message(str(round(temp,2)))



def humidity():
    humidity = sense.get_humidity()
    print(humidity)
    if humidity > 40:
        sense.clear(blue)
    elif humidity < 40 and humidity > 30:
        sense.clear(green)
    elif humidity < 30 and humidity > 0:
        sense.clear(red)
    sleep(1)

    sense.show_message(str(round(humidity,2)))


try:
    while True:
        for event in sense.stick.get_events():
            if event.action == "pressed":
                if event.direction =="up":
                    temperature()
                elif event.direction == "down":
                    humidity()
                sleep(0.5)


except KeyboardInterrupt:
    sense.show_message("Bye!")

Sources: