0% found this document useful (0 votes)
249 views

Raspberry Pi Sense HAT

How to use the Sense HAT.

Uploaded by

Steve Attwood
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
249 views

Raspberry Pi Sense HAT

How to use the Sense HAT.

Uploaded by

Steve Attwood
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Foundation

Raspberry Pi
Documentation

Computers

Accessories

Microcontrollers

Services

Pico C SDK

Sense HAT

Introducing the Sense HAT


Edit this on GitHub

The Raspberry Pi Sense HAT is an add-on board that


gives your Raspberry Pi an array of sensing capabilities.
The on-board sensors allow you to monitor pressure,
humidity, temperature, colour, orientation, and movement.
The bright 8×8 RGB LED matrix allows you to visualise
data from the sensors, and the Uve-button joystick lets
users interact with your projects.

The Sense HAT was originally developed for use on the


International Space Station, as part of the educational
Astro Pi programme run by the Raspberry Pi Foundation
in partnership with the European Space Agency. It is well
suited to many projects that require position, motion,
orientation, or environmental sensing. The Sense HAT is
powered by the Raspberry Pi computer to which it is
connected.

An oYcially supported Python library provides access to


all of the on-board sensors, the LED matrix, and the
joystick. The Sense HAT is compatible with any Raspberry
Pi computer with a 40-pin GPIO header.

Installation
Edit this on GitHub

In order to work correctly, the Sense HAT requires an up-


to-date kernel, I2C to be enabled, and a few libraries to get
started.

Ensure your APT package list is up-to-date:

sudo apt update

Next, install the sense-hat package, which will ensure the


kernel is up to date, enable I2C, and install the necessary
libraries and programs:

sudo apt install sense-hat

Finally, a reboot may be required if I2C was disabled or


the kernel was not up-to-date prior to the install:

sudo reboot

Getting started

After installation, example code can be found under


/usr/src/sense-hat/examples.

You can Und more information on how to use the Sense


HAT in the Raspberry Pi Press book Experiment with the
Sense HAT. Written by The Raspberry Pi Foundation’s
Education Team, it is part of the MagPi Essentials series
published by Raspberry Pi Press. The book covers the
background of the Astro Pi project, and walks you through
how to make use of all the Sense HAT features using the
Python library.

You can download this book as a PDF Ule for free, it has
been released under a Creative Commons Attribution-
NonCommercial-ShareAlike 3.0 Unported (CC BY NC-SA)
licence.

Using the Sense HAT with Python


sense-hat is the oYcially supported library for the Sense
HAT; it provides access to all of the on-board sensors and
the LED matrix.

Complete documentation for the library can be found at


pythonhosted.org/sense-hat.

Using the Sense HAT with C++


RTIMULib is a C++ and Python library that makes it easy
to use 9-dof and 10-dof IMUs with embedded Linux
systems. A pre-calibrated settings Ule is provided in
/etc/RTIMULib.ini, which is also copied and used by
sense-hat. The included examples look for
RTIMULib.ini in the current working directory, so you
may wish to copy the Ule there to get more accurate data.

The RTIMULibDrive11 example comes pre-compiled to


help ensure everything works as intended. It can be
launched by running RTIMULibDrive11 and closed by
pressing Ctrl C.

NOTE

The C/C++ examples can be compiled by running


make in the appropriate directory.

Sense HAT hardware


Edit this on GitHub

The Sense HAT has an 8×8 RGB LED matrix and a Uve-
button joystick, and includes the following sensors:

Gyroscope

Accelerometer

Magnetometer

Temperature

Barometric pressure

Humidity

Colour and brightness

Schematics and mechanical drawings for the Sense HAT


are available for download.

Sense HAT schematics.

Sense HAT mechanical drawings.

LED matrix
The LED matrix is an RGB565 framebuffer with the id
"RPi-Sense FB". The appropriate device node can be
written to as a standard Ule or mmap-ed. The included
'snake' example shows how to access the framebuffer.

Joystick
The joystick comes up as an input event device named
"Raspberry Pi Sense HAT Joystick", mapped to the arrow
keys and Enter. It should be supported by any library
which is capable of handling inputs, or directly through
the evdev interface. Suitable libraries include SDL,
pygame and python-evdev. The included 'snake' example
shows how to access the joystick directly.

Hardware calibration
Install the necessary software and run the calibration
program as follows:

$ sudo apt update


$ sudo apt install octave -y
$ cd
$ cp /usr/share/librtimulib-utils/RTEllipsoidFit .
$ cd RTEllipsoidFit
$ RTIMULibCal

You will then see this menu:

Options are:

m - calibrate magnetometer with min/max


e - calibrate magnetometer with ellipsoid (do mi
a - calibrate accelerometers
x - exit

Enter option:

Press lowercase m. The following message will then


show. Press any key to start.

Magnetometer min/max calibration


--------------------------------
Waggle the IMU chip around, ensuring that all
(+x, -x, +y, -y and +z, -z) go through their e
When all extrema have been achieved, enter 's'
or 'x' to abort and discard the data.

Press any key to start...

After it starts, you will see something similar to this


scrolling up the screen:

Min x: 51.60 min y: 69.39 min z: 65.91


Max x: 53.15 max y: 70.97 max z: 67.97

Focus on the two lines at the very bottom of the screen,


as these are the most recently posted measurements
from the program.

Now, pick up the Raspberry Pi and Sense HAT and move it


around in every possible way you can think of. It helps if
you unplug all non-essential cables to avoid clutter.

Try and get a complete circle in each of the pitch, roll and
yaw axes. Take care not to accidentally eject the SD card
while doing this. Spend a few minutes moving the Sense
HAT, and stop when you Und that the numbers are not
changing anymore.

Now press lowercase s then lowercase x to exit the


program. If you run the ls command now, you’ll see a
new RTIMULib.ini Ule has been created.

In addition to those steps, you can also do the ellipsoid Ut


by performing the steps above, but pressing e instead of
m.

When you’re done, copy the resulting RTIMULib.ini to


/etc/ and remove the local copy in
~/.config/sense_hat/:

$ rm ~/.config/sense_hat/RTIMULib.ini
$ sudo cp RTIMULib.ini /etc

Reading and writing


EEPROM data
Enable I2C0 and I2C1 by adding the following line to
/boot/config.txt:

dtparam=i2c_vc=on
dtparam=i2c_arm=on

Enter the following command to reboot:

sudo systemctl reboot

Download and build the iash tool:

$ git clone https://github.com/raspberrypi/hats.gi


$ cd hats/eepromutils
$ make

NOTE

These steps may not work on Raspberry Pi 2 Model B


Rev 1.0 and Raspberry Pi 3 Model B boards. The
Urmware will take control of I2C0, causing the ID pins
to be conUgured as inputs.

Reading
EEPROM data can be read with the following command:

$ sudo ./eepflash.sh -f=sense_read.eep -t=24c32 -r

Writing
Download EEPROM settings and build the .eep binary:

$ wget https://github.com/raspberrypi/rpi-sense/ra
./eepmake sense_eeprom.txt sense.eep /boot/overla

Disable write protection:

$ i2cset -y -f 1 0x46 0xf3 1

Write the EEPROM data:

$ sudo ./eepflash.sh -f=sense.eep -t=24c32 -w

Re-enable write protection:

i2cset -y -f 1 0x46 0xf3 0

WARNING

This operation will not damage your Raspberry Pi or


Sense Hat, but if an error occurs, the HAT may no
longer be automatically detected. The steps above are
provided for debugging purposes only.

Raspberry Pi documentation is copyright © 2012-2023 Raspberry Pi


Ltd and is licensed under a Creative Commons Attribution-ShareAlike
4.0 International (CC BY-SA) licence.
Some content originates from the eLinux wiki, and is licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported licence.

Follow us

Sign up to newsletter

Twitter

Mastodon

YouTube

Instagram

LinkedIn

Facebook

About Raspberry Pi

News

Contact us

Trademark

About us

Our Approved Resellers

Jobs

Accessibility

Site use terms and conditions

Acceptable use

Cookies

Licensing

Terms and conditions of sale

Privacy

Security

Verify our bank details

For home

Raspberry Pi for home

Tutorials

For industry

Raspberry Pi for industry

Thin clients

Powered by Raspberry Pi

Design partners

Success stories

Hardware

Computers and microcontrollers

Cameras and displays

Add-on boards

Power supplies and cables

Cases

Peripherals

Software

Raspberry Pi OS

Raspberry Pi Imager

Raspberry Pi Desktop

Documentation

All categories

Product information portal

Datasheets

Community

Forums

Events

Raspberry Pi Store

Cambridge Store

Raspberry Pi Press

About Raspberry Pi Press

The MagPi

HackSpace

You might also like