Sense Hat on Raspberry Pi – The Ultimate Tutorial (Part 1)

I have had my Sense Hat for a few months, and I’m excited to share with you what I have learned about it
But I never managed to write this post because there are so many things to explain. I didn’t know how to organize them to make it a complete tutorial, but not too long
Finally, this tutorial is online, and consists of several parts

What is the Sense Hat?
The Sense Hat is the most popular HAT on Raspberry Pi
It’s an expansion card, created by the Raspberry Pi Foundation, that provides many sensors to play with
There is also a LED display matrix and a joystick on it
Many experiences become possible once installed on your Pi

But before playing with it, there is a few things you need to do and understand, and this is the main goal of this first part
In this post, I will explain you exactly what you can do with it, where to buy it, how to install it and check that everything is ok

Ready? Go 🙂

Sense Hat presentation

“HAT” definition

We often use the term HAT to define a Raspberry Pi extension
It’s not only for the first meaning, but it stands for “Hardware Attached on Top”

In short, it’s an additional card, that you plug on the top of your Raspberry Pi to bring new features
Generally, it uses the GPIO ports to connect the two cards together
If you are interested, you can see a few HATs examples on this page

raspberry pi zero cluster
A cluster of Pi Zero using the Cluster HAT

Don’t panic, the assembly is easy.
It requires no soldering, so you can plug and unplug it when you want
And even better, the installation is most of the time automatic.

The Raspberry Pi will recognize the HAT thanks to an EEPROM module on the board that identifies the HAT model

So don’t be afraid to use HAT with your Raspberry Pi, it’s effortless, and close to an additional PCI cards on your computer
Just plug it, maybe install one thing, and it’s ready to use

Raspberry Pi Bootcamp
Take it to the next level.
I'm here to help you get started on Raspberry Pi.
Learn all the skills you need in the correct order.

The Sense Hat story

Originally, the Sense HAT was created by the Raspberry Pi Foundation as “Astro Pi” (you may have heard this name)
The goal was to send a few Raspberry Pi with many sensors on board the International Space Station (ISS)

Here is an infographic from the ESA (European Space Agency):

Source: ESA

After this successful flight, the Sense HAT was created as a commercial product, available for anyone on Earth 🙂

The Sense Hat features

As said in introduction, the sense HAT provides many new sensors to the Raspberry Pi
Here is the list of what you will get on it:

  • Accelerometer (get the movement speed of the PI)
  • Gyroscope (capture the rotation movement of the Raspberry Pi)
  • Magnetometer (magnetic field measurement)
  • Air pressure sensor
  • Temperature and humidity sensors

And there is also a LED display matrix and a joystick on the top of it

Everything is controllable in Python scripts (we’ll see that in the next part of this tutorial)


If you are not yet excited enough by the Sense Hat features, here is a short video of a person playing with the LED display 🙂

Windows IoT Raspberry Pi Sense HAT Demo

I’m sure you want to keep reading after that ^_^

Sense Hat installation

Where to buy it?

Before going further, the first step is to have a Sense Hat in your hands 🙂
This extension is not so expensive, probably between $30 and $40 depending on where you buy it

You will find it on the same stores as the Raspberry Pi device
The most convenient place to order it is probably on Amazon (check the current price here)

It’s not mandatory, but you can also find specific cases to include the Raspberry Pi and the Sense Hat in the same one
This one for example is perfect for this (also on Amazon)
If you plan to use it for a long time, this is probably something to consider

Master your Raspberry Pi in 30 days
Download the eBook.
Uncover the secrets of the Raspberry Pi in a 30 days challenge.
Learn useful Linux skills and practice multiples projects.


So, once you have received your Sense Hat, there is not many other things to have
If you have your Raspberry Pi (3B+ or 4 is perfect) and your Sense Hat, you are ready to go

You also need to prepare a SD card with Raspbian Desktop (or Full) on it
If needed, you can find my recommendations for an SD card here, and a tutorial on how to install Raspbian Desktop here

Don’t plug the Sense Hat for now, we will do this on the next step, as soon as the operating system is ready
Once on Raspbian Desktop, I recommend to:

  • Check that the Internet connection is working (this step is mainly for Wi-Fi connections)
  • Update your system
    sudo apt update && sudo apt upgrade
  • Enable SSH
    It’s not mandatory for now, but you’ll need it in a following part of this tutorial

Once ready, you can stop your Raspberry Pi and move to the Sense Hat installation

Hardware installation

The Sense Hat installation on the Raspberry Pi is straightforward
The Sense HAT has a GPIO connector that slot into all the pins, so you don’t have to think on where to plug it

  • Start with the Raspberry Pi off (unplug the power cable)
  • Then, put the Sense Hat on the GPIO pins and push it gently to connect it
  • Finally, start again your Raspberry Pi

If the Sense Hat is plugged correctly, all the LEDs on the top will light up to draw a rainbow for a few seconds

The Sense Hat is provided with a few screws to attach it to the Raspberry Pi
You can fix them if you want, but it’s not mandatory

Installation check

If you got the rainbow display on boot, it’s almost sure that everything is ok
But in this last part, we will verify that Raspbian can control the Raspberry Pi

Raspbian configuration

Depending on the Raspbian version you have, you may need to install the Sense Hat library
It’s installed by default on my Raspbian Full, but maybe not on any version

Here is the command to install it:
sudo apt install sense-hat
You can also use the Raspbian Add/Remove Software tool if you prefer

Hello world

Even if this post is not a Python lesson on how to program with the Sense Hat, I will give you here a basic script to test that everything is working fine

  • Create a new Python script with your favorite editor
    – On Raspbian Desktop, you can use Thonny (main menu > Programming > Thonny Python IDE)
    – On Raspbian Lite or in a terminal, nano will be enough for this
  • Paste the following lines:
    from sense_hat import SenseHat
    sense = SenseHat()
    sense.show_message("Hello world")

    I will come back to this in the next part, for now there is no need to understand everything
  • If you are in Thonny, click on the green “Run” button to run the script
    On nano, save and exit (CTRL+O, CTRL+X) and run it with:

Whatever how you run this script, you should see the Sense Hat displaying “Hello world” in big white letters on the LED Matrix

Note: If you are new to Python scripts, a good idea is probably to start with this Python tutorial before going further


That’s it for this first part, the goal for now was only to discover what is a Sense Hat, install it and check that everything is working correctly
It also gives you the time to buy it if you don’t have it yet 🙂
(As a reminder, the direct link to Amazon here)

If you want to learn more about what you can do with a Sense Hat, you can jump to the second part of this tutorial
We’ll move to the practice part, and see how to control it completely with Python scripts

In any case, if you have any question or suggestion, feel free to leave a comment below

This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Patrick Fromaget

I'm the lead author and owner of My goal is to help you with your Raspberry Pi problems using detailed guides and tutorials. In real life, I'm a Linux system administrator with a web developer experience.

2 thoughts on “Sense Hat on Raspberry Pi – The Ultimate Tutorial (Part 1)

  1. Dear Patrick
    I bought a few days ago a Raspberry 4 and a SenseHat. First I was succesfull in running the Raspberry Pi with the GPIO (led’s etc). Then I mounted the SenseHat. After connecting to the power the LED on top started the rainbow but didn’t switched off after a few second.
    It seems that the SenseHat module was not recognized by the main board. I got an error message after the command sense = SenseHat() saying that the device was not recognized. I found the corresponding line in the program:
    raceback (most recent call last):
    File “/home/pi/”, line 6, in
    sense = SenseHat()
    File “/usr/lib/python3/dist-packages/sense_hat/”, line 39, in __init__
    raise OSError(‘Cannot detect %s device’ % self.SENSE_HAT_FB_NAME)
    OSError: Cannot detect RPi-Sense FB device.
    Any idea what I amdoing wrong or it is a hardware failure. Note that I am using a headless approach.
    I do appreciate any help.
    Kind regards
    Albrecht Neftel, Switzerland

    1. Hi,

      Make sure you didn’t miss any step in the prerequisites (python library installed for example).
      You can also check that I2C is enabled in raspi-config and reboot your Raspberry Pi.


Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts

Master your Raspberry Pi - 10% off