Raspberry Pi Sense HAT

The Raspberry Pi's Sense HAT (also known as the Astro Pi HAT) is a device that sits on top of the Raspberry Pi device. It has an on-board accelerometer, magnetometer, gyroscope, thermometer, barometer, and humidity sensor, all of which pass data back to the Pi via I2C communication. In addition to these sensors, it has an 8×8 LED array that can be used to display information and a five-way joystick that can be used for input.

Sense HAT on a Raspberry Pi B (courtesy of the Raspberry Pi Foundation).

Opening the Device

    DeviceOpen["SenseHAT"]

    opens an I2C connection to the Sense HAT device.

    DeviceOpen["SenseHAT"] is not required to read data from sensors but must be used to display strings using DeviceWrite[].

Reading Data

    DeviceRead["SenseHat", sensor]

    reads data from the sensor specified by sensor.

    DeviceRead[dev,sensor]

    reads data from the sensor specified by sensor.

  • The Sense HAT has a variety of sensors that can be read from:
  • "Temperature"reads temperature in degrees Celsius
    "Humidity"reads humidity in % RH
    "Pressure"reads atmospheric pressure in millibars
    "Rotation"reads gyroscopic motion in revolutions per second
    "Acceleration"reads acceleration in terms of standard accelerations due to gravity on Earth's surface
    "Orientation"reads orientation relative to magnetic north in degrees
    "Magnetic Field"reads strength and direction of a magnetic field around the sensor in microteslas
  • The gyroscope, accelerometer, and magnetometer sensors return a list of three values that corresponds to {roll,pitch,yaw}, as oriented according to the following image:

Writing Data

    DeviceWrite[dev,"str"]

    displays the string str on the LED matrix.

  • The following options can be given:
  • "ScrollSpeed"the amount of time between frames
    "Color"the color of the text in {r,g,b} with values in the range 0-255.
  • Text written to the LED matrix using DeviceWrite is displayed by scrolling the text across the matrix.
  • DeviceWrite[dev,list]

    displays a list of RGB values, list, writing each RGB triple to one LED on the board.

  • Images written to the LED screen using RGB triples can be passed to DeviceWrite as a list of 64 triples, or a list of 8 rows, each having 8 triples.

Closing and Releasing Resources

    DeviceClose[dev]

    closes the connection to the device.

    DeviceClose[dev] is only necessary if DeviceOpen["SenseHat"] was called before reading data from the sensors or writing strings to the LED matrix.

Examples

open allclose all

Basic Examples  (3)

Read sensor data using DeviceOpen:

Display a string on the LED array:

Display a list of RGB values:

Scope  (1)

Turn the Sense HAT into a stock ticker: