What is the Sense HAT?
The Sense HAT is an add-on electronic board (or HAT) for the Raspberry Pi computer. It has sensors, a mini joystick, and a grid of multi-coloured LED lights.
The Sense HAT was first developed for the Astro Pi project and launched into space in December 2015, before becoming available for purchase. With the Sense HAT, you can create physical computing projects that use sensors and joystick inputs, and show outputs on the LED matrix.
The Code Club Sense HAT projects are written for the Trinket Sense HAT emulator, so you don’t need a physical Sense HAT for them. But you can also complete the projects using a physical Sense HAT and a Raspberry Pi. If you only have Raspberry Pis, you could use the Sense HAT emulator that’s included on its operating system (you’ll find it in the Programming section of the menu). It works in the same way as the Trinket emulator.
Using the Sense HAT emulator on Trinket
You don’t need a physical Sense HAT to complete the Code Club Sense HAT projects. Instead, you can use the Sense HAT emulator, which lets you code and test Sense HAT projects in a web browser.
In the emulator, you write Python code in the editor on the left, and the emulator runs on the right.
You can use the sliders in the emulator to adjust the ‘measurements’ of the temperature, pressure, and humidity sensors. To use the emulated joystick, press the arrow keys on your keyboard for directions, and the Enter key for the middle button on the joystick.
Text output from print statements in your code is shown below the emulator.
Note that Trinket uses Python 2 by default, so you need to include the line #!/bin/python3 at the very top of your code to tell Trinket to use Python 3.
Using a physical Sense HAT and Raspberry Pi
To use a physical Sense HAT, you will also need a Raspberry Pi computer set up in the usual way for Raspberry Pi projects. Even if you have a physical Sense HAT, you may still find it useful to use the Trinket emulator to test for different environmental conditions, such as high temperatures.
The Sense HAT slots on to the Raspberry Pi expansion header, and attaches using standoffs and screws. It’s important that you use the standoffs to secure the Sense HAT so that it’s stable.
Follow the beginning of this Getting started with the Sense HAT project to get your Raspberry Pi ready to work with the Sense HAT.
Safety: When using a physical Sense HAT it is important to read the safety instructions that are included with the device, and to explain them to young people.
Moving programs from Trinket to a physical Sense HAT
You can download a Trinket Sense HAT project and run it on a physical Raspberry Pi with a Sense HAT. This works well if you only have a small number of physical Sense HATs but want a larger group to work through the projects.
Make sure your Sense HAT is attached to your Raspberry Pi.
If your Raspberry Pi is connected to the internet, you can download a project directly from Trinket. Otherwise, you can download the project on another computer, and transfer the file to the Pi using a USB drive.
In Trinket, choose Download from the menu. This will download a .zip file containing the project to your Downloads directory.
Copy the .zip file to a suitable folder on the Raspberry Pi and double-click it to unzip it. You should find a file called main.py, as well as any other files used by your project.
Start up Python 3 IDLE and use it to run main.py, either with the menu command or by pressing F5 on the keyboard.