I’ve had my Sense Hat for a few months, and I’m excited to share what I’ve learned with you.
But it’s been difficult to write this post because there are so many things to explain. I didn’t know how to organize everything in order to make it a complete tutorial that wasn’t too long.
This tutorial is finally online, and consists of several parts.
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, a LED matrix and a joystick. Python code can be used to control all of this.
But before playing with it, there are a few things you need to do and understand, which is the main goal of this first part of the article.
In this post, I will explain what exactly you can do with Sense Hat, where to buy it, how to install it and ensure that everything is ok.
If you are looking to quickly progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge, where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.
Sense Hat presentation
If you are lost in all these new words and abbreviations, request my free Raspberry Pi glossary here (PDF format)!
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 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.
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 automatic most of the time.
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 in, you might have to install one thing, and it’s ready to use.
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 onboard the International Space Station (ISS).
Here is an infographic from the ESA (European Space Agency):
After this successful flight, the Sense HAT was created as a commercial product that was available for anyone on Earth :).
What does a Sense Hat do?
The sense HAT provides many new sensors to the Raspberry Pi:
- 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 an LED display matrix and a joystick on the top of it.
Everything is controllable in Python scripts, which we’ll see in the next part of this tutorial.
If you aren’t excited enough by the Sense Hat features just yet, here’s a short video of a person playing with the LED display :);
I’m sure you want to keep reading after that ^_^.
Sense Hat installation
Grab your free PDF file with all the commands you need to know on Raspberry Pi!
Where to buy a Sense HAT?
Before going further, the first step is to have a Sense Hat in your hands :).
This extension is not very expensive, typically between $30 and $40 depending on where you buy it.
You will find it in 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 purchase specific cases to accommodate the Raspberry Pi and the Sense Hat together.
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.
So, once you have your Sense Hat, you don’t need much else.
If you have your Raspberry Pi (3B+ or 4 is perfect) and your Sense Hat, you are ready to go.
For now, don’t plug in the Sense Hat, we will get to this 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.
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 in.
- 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 your Raspberry Pi again.
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 screw them in if you want, but it isn’t mandatory.
If you got the rainbow display on boot, you can be almost certain that everything is ok.
But in this last part, we will verify that Raspbian can control the Raspberry Pi.
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 this might not be the case for all versions.
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.
Even if this post is not a Python lesson on how to program with the Sense Hat, I will give you 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()
I will come back to this in the next part, but 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:
However 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.
Support us: Join the community on Patreon to show your support, get behind-the-scenes content and other awesome perks!
That’s it for this first part, the goal for now was to discover what Sense Hat is, install it and ensure everything is working correctly.
It also gives you the time to buy one if you haven’t 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 questions or suggestions, feel free to leave a comment below.