Buy the Sense HAT – as seen in space*!

*Not actually in space yet. Wait till December.

Today we have a new product launch: the Sense HAT is now available from the Swag Store, and through our partners RS Components and Premier Farnell/CPC. Here’s a video from Matt Timmons-Brown, freshly released from GCSE exam hell, to show you around.

The Sense HAT was originally developed around James Adams’ idea to make a cool toy-style board that showed off just how much you could do with your average modern MEMS gyroscope, 64 RGB LEDs and some Atmel microcontroller hackery.

Somewhere between prototype and production, it seems to have attracted extra features like a pressure sensor, a humidity/temperature sensor and a teeny joystick. It also seems to have been comandeered and made an integral part of the Astro Pi mission, which will see two Raspberry Pis, two Sense HATs and a lot of code written by UK schoolkids hosted on the International Space Station – I guess I’m to blame for that.

Astro Pi sense HAT LED

The board forms the basis for many of the experiment sequences that will be run on the ISS – many of the schools competition winners’ entries made good use of the HAT’s sensors to gather their experimental data. The LED matrix also provides a feedback mechanism and interactivity for British ESA Astronaut Tim Peake when he’s tasked with deploying the Astro-Pi board on the ISS (he’ll be setting it up on-orbit to run the experiment sequences). One of the winning entries – Reaction Games – programmed a whole suite of joypad-operated games played via the LED matrix. Snake is hilarious on an 8×8 screen.

The board itself has a suite of sensors, a “D-pad” style 5-button joystick and an 8×8 RGB LED matrix driven by a combination of an LED driver chip and an Atmel AVR microcontroller – an ATTiny88.

For the terminally curious, here are the schematics of the board.

The Sense HAT and its Pi tucked snugly in the Astro Pi flight case

The Sense HAT and its Pi tucked snugly into the Astro Pi flight case

Here’s the hardware run-down:

Sensing elements:

Pressure / Temperature
ST Micro LPS25H
– 24-bit pressure measurement resolution (260hPa to 1260hPa)
– 16-bit temperature measurement resolution (0-125°C)
Datasheet

Humidity / Temperature
ST Micro HTS221
– 16-bit humidity measurement resolution (0-100% relative humidity)
– 16-bit temperature measurement resolution (0-60°C)
Datasheet

Acceleration/Gyroscope/Magnetic field
ST Micro LSM9DS1
– 9 degrees of freedom (X, Y, Z independent axes for all sensors)
– ±16 g acceleration measurement range
– ±16 gauss magnetometer measurement range
– ±2000 dps (degrees per second) gyroscope measurement range
Each of these measurement channels has 16 bits of resolution.
Datasheet

All of these sensors have features for periodic sampling of sensor values – complete with internal FIFO storage. The LPS25H and HTS221 have maximum sample rates of 25 per second, the LSM9DS1 has a maximum sample rate of 952Hz – we are already imagining the birth of a million Pi-controlled stunt quadcopters.

LED Matrix
The LED matrix is driven by a combination of a constant-current LED driver and an Atmel ATTiny88 running a custom firmware that delivers an 8×8 display with 15-bit resolution RGB colour. If you want to get into the gory details, the AVR firmware is available on Github.

Joystick
The Atmel is responsible for sampling the joystick. We didn’t have enough pins left on the Atmel to dedicate the five that we needed to sample the joystick axes independently, so they’ve been spliced into the LED matrix row selects. The joystick gets updated at approximately 80Hz, which is the scan rate of the LED matrix.

All of the sensors (and the base firmware for the Atmel) are accessible from the Pi over I2C. As a fun bonus mode, the SPI peripheral on the Atmel has been hooked up to the Pi’s SPI interface – you can reprogram your HAT in the field! We use this method to get the firmware into the Atmel during production test – and we leave it unprotected so you can substitute the stock firmware to get it to do whatever you want. Seriously. First person to turn this sensor HAT into a quadcopter controller HAT wins a cookie from me.

Software
If you’re not assembly-language inclined, you can always use the HAT’s sensors from our shipped Python library – standard function calls return sensor values, give you joystick key events and allow you to display things on the LED matrix. The Sense API is available through the Raspbian APT repositories.

To access the magic, simply enter:

sudo apt-get update
sudo apt-get install sense-hat
sudo pip-3.2 install pillow

into a terminal window. Note you will have to reboot for the Sense HAT to be recognised.

The API is well-documented (and tested extensively by schoolchildren as part of Astro-Pi) – get reading here.

The LED matrix appears as a Linux framebuffer device – for fun you can compare the results of

cat /dev/urandom > /dev/fb0

and

cat /dev/urandom > /dev/fb1

to fill either your attached monitor or the LED matrix with random noise. The joypad appears as a standard input device – the “keys” map to Up/Down/Left/Right and Enter.

The baseline price (excluding spacers and screws, and local taxes) is $30. You’ll be able to buy from all the usual suspects – the Swag Store (which is bundling spacers and screws for free), RS Components/Allied, Premier Farnell/Newark and all their subsidiaries have stock today. Secondary suppliers may take a couple of days to get their hands on stock.

So, what are you waiting for? Get sensor hacking!