Skip to content

Sense HAT

Jason Charney edited this page Mar 26, 2016 · 1 revision

:under_construction: UNDER CONSTRUCTION! This is a new page, and as such it is under construction.

For about $30 at MicroCenter (or maybe $40 at Amazon) you can pick up the Sense HAT for Raspberry Pi B+, 2, and 3. The downside with shields is that many of them will cover up all the GPIO pins, leaving no room for using other GPIO devices such as the 7 Inch [Touch Screen](Touch Screen) or a chip that would provide Real-Time Clock functionality. You can get away with using USB for the 7 inch Touch Screen, but I found using GPIO more effective because of power. I'll bring that up again in the Touch Screen page. There is no official Real-Time Clock chip. There are several of them on the market on Amazon and Ebay, but you may want to check the reviews to make sure that they weren't manufactured to short out your Pi for a quick buck. Personally, I would like to see someone make a Real-Time Clock chip that you can plug into USB.

The Raspberry Pi Foundation keeps claiming they don't include a Real-Time Clock to keep the cost down, but considering you can buy some cheap quartz timepiece for like $20 at Wal-Mart, which less than 10% of that cost actually goes towards that clock circuit, I think the foundation should consider putting a clock circuit on the device when and if the Pi 4 comes out, or consider making USB dongle that does timekeeping. But this is going beyond the scope of this page.

Installation

Installation should be easy.

For the hardware part, just place the sense hat on top of all the GPIO pins. Do not miss any of them and be careful not to break off any of the pins. The sense hat must cover all rows and all columns. If the pins are not all covered, this can damage the hardware. There are no standoff screws, but if you have one of those stackable layer style enclosurers, you should be in good shape. I'll post a link to what I'm talking about eventually in this article.

The official documentation says you should have an up-to-date kernel, I2C enabled, and a few libraries installed. Just to be sure, let's do that second thing as we can take care of making sure our kernel and software are updated shortly.

sudo raspi-config

Go to Advanced Options then I2C. When asked "Would you like the ARM I2C interface to be enabled?" select Yes then press Enter. Press Enter again to confirm that I2C will be enabled after reboot. When asked "Would you like the I2C kernel module to be loaded by default?" select Yes then press Enter. Press Enter again. Scroll right to select Finish and Press Enter. When asked "Would you like to reboot now?", select No then press Enter.

$ sudo apt-get update && sudo apt-get upgrade    # Let's make sure our software is up to date.
$ sudo apt-get install python-sense-hat python3-sense-hat sense-hat libjpeg-dev     # Install the Sense HAT software, alsothe JPEG development library
$ sudo pip install numpy pillow sense-hat        # Python imaging library. Install sensehat from pip anyway just to be sure.
$ sudo reboot                                    # Reboot your computer so the raspi-config changes go in effect.

Usage

All the example code should be located in /usr/src/sense-hat/examples. We can play around with them by putting them into a sandbox directory.

$ mkdir -p ~/Sandbox/sense-hat
$ cp -a /usr/src/sense-hat/examples ~/Sandbox/sense-hat
$ cd ~/Sandbox/sense-hat/examples/

Sense HAT code can be written in Python or [C or C++](C and C plus plus). The C/C++ examples can be compiled by running make since there is a MakeFile in the directory. This is probably a good idea to follow especially if you are new to C/C++.

If you are programming in Python, please use Python 3 style so that we can finally phase out Python 2 code.

Python Sense-HAT and RTIMULibDrive11

Programs launched by running RTIMULibDrive11 can be executed using Ctrl+C.

RTIMULib controls the sensors on the Sense Hat, like the 9DoF LSM9DS1 (Gyroscope, accelerometer, and magetometer) and the HTS211 (Relative Humidity, Presure, and Temperature).

The Python Sense-HAT program is generally used for manipulating RTIMULib as well as Kernel space stuff like the input device and framebuffer on the sense hat using AVR which takes in input from the Joystick and outputs data through the LED Matrix. For my interest, I only got the Sense Hat for the LED Matrix and the sensors.

Which brings us to the most important part of this page.

Hello World.

$ cd ~/Sandbox/sense-hat/
$ vim hello.py

Then write in hello.py

#!/usr/bin/python

from sense_hat import SenseHat

sense = SenseHat()

sense.show_message("Hello world!")

Then run python hello.py

The LED display should display a message.

See Also

  • [Touch Screen](Touch Screen)
  • [Atrix Lapdock](Atrix Lapdock)
  • GPIO

Links

Setup

  1. [Assemble the Hardware](Assemble the Hardware)
  2. [Install the Software](Install the Software)
  3. 🆙 [Setup your Raspberry Pi](Setup your Raspberry Pi)
  4. [Download the Missing Parts](Download the Missing Parts)

Typical Utilities

  • [Downloading and extracting with curl and tar](curl and tar)
  • [Browsing with ls and cat](ls and cat)
  • [Searching with grep and find](grep and find)
  • [Filtering with sed and awk](sed and awk)
  • [Piping with less, pv, and tee](less, pv, and tee)
  • Monitor your system with htop
  • Multiplex with tmux

Clone this wiki locally