← Back to Mission Control

🎮 Raspberry Pi Sense HAT Explorer

Interactive guide for CICF - Learn by exploring!

💡 LED Matrix (8x8)

Try it: Click the buttons to see different LED patterns!
🐍 Python Code
from sense_hat import SenseHat
import time

sense = SenseHat()

# Light up a single pixel (red)
sense.set_pixel(3, 3, 255, 0, 0)
time.sleep(1)

# Show a message
sense.show_message("Hello CICF!", scroll_speed=0.05)

# Clear the display
sense.clear()
from sense_hat import SenseHat

sense = SenseHat()

# Define heart pattern (0 = off, 1 = on)
heart = [
    0,1,1,0,0,1,1,0,
    1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,
    0,1,1,1,1,1,1,0,
    0,0,1,1,1,1,0,0,
    0,0,0,1,1,0,0,0,
    0,0,0,0,0,0,0,0
]

# Draw the heart (pink color)
for i in range(64):
    if heart[i] == 1:
        x = i % 8
        y = i // 8
        sense.set_pixel(x, y, 255, 0, 100)
from sense_hat import SenseHat
import time

sense = SenseHat()

# Rainbow colors (one per row)
colors = [
    [255, 0, 0],      # Red
    [255, 127, 0],    # Orange
    [255, 255, 0],    # Yellow
    [0, 255, 0],      # Green
    [0, 0, 255],      # Blue
    [75, 0, 130],     # Indigo
    [148, 0, 211],    # Violet
    [255, 255, 255]   # White
]

# Draw rainbow row by row
for y in range(8):
    for x in range(8):
        r, g, b = colors[y]
        sense.set_pixel(x, y, r, g, b)
    time.sleep(0.2)  # Animate the drawing
from sense_hat import SenseHat

sense = SenseHat()

# Draw your custom design here
# Click "Draw Mode" and draw on the matrix
# Then click "Generate Code" to see your code here!

sense.clear()

🌡️ Environmental Sensors

Note: Temperature readings are affected by Raspberry Pi heat. Add 3-5°C to get real room temperature!
Temperature
--°C
Humidity
--%
Pressure
-- mb
🐍 Python Code
from sense_hat import SenseHat

sense = SenseHat()

# Read temperature
temp = sense.get_temperature()
print(f"Temperature: {temp:.1f}°C")

# Read humidity
humidity = sense.get_humidity()
print(f"Humidity: {humidity:.1f}%")

# Read pressure
pressure = sense.get_pressure()
print(f"Pressure: {pressure:.1f} mbar")

🎯 Motion & Orientation

Try it: Move the sliders to see how the Sense HAT detects tilt and rotation!
🐍 Python Code
from sense_hat import SenseHat

sense = SenseHat()

# Get orientation (pitch, roll, yaw)
orientation = sense.get_orientation_degrees()
print(f"Pitch: {orientation['pitch']:.1f}°")
print(f"Roll: {orientation['roll']:.1f}°")
print(f"Yaw: {orientation['yaw']:.1f}°")

# Get raw accelerometer data
accel = sense.get_accelerometer_raw()
print(f"x: {accel['x']:.2f}g")
print(f"y: {accel['y']:.2f}g")
print(f"z: {accel['z']:.2f}g")

🕹️ 5-Direction Joystick

Try it: Click the arrows and center button to see how the joystick works!
🐍 Python Code
from sense_hat import SenseHat
from signal import pause

sense = SenseHat()

# Handle joystick up
def pushed_up(event):
    if event.action == 'pressed':
        sense.show_letter("U", text_colour=[0, 255, 0])

# Handle joystick down
def pushed_down(event):
    if event.action == 'pressed':
        sense.show_letter("D", text_colour=[0, 255, 0])

# Handle joystick middle (press)
def pushed_middle(event):
    if event.action == 'pressed':
        sense.show_letter("M", text_colour=[255, 0, 0])

# Assign functions to joystick directions
sense.stick.direction_up = pushed_up
sense.stick.direction_down = pushed_down
sense.stick.direction_middle = pushed_middle

pause()  # Keep running

🚀 Complete Sense HAT Test

All-in-One: Copy this code to test everything at once on your Raspberry Pi!
🐍 Complete Test Script
from sense_hat import SenseHat
import time

sense = SenseHat()

print("=" * 50)
print("  SENSE HAT COMPLETE TEST - CICF")
print("=" * 50)

# 1. LED Test
print("\n1. Testing LED Matrix...")
for y in range(8):
    sense.clear()
    for x in range(8):
        sense.set_pixel(x, y, 255, 0, 0)
    print(f"   Row {y} lit")
    time.sleep(0.3)

sense.show_message("OK!", scroll_speed=0.05, text_colour=[0, 255, 0])
sense.clear()

# 2. Environmental Sensors
print("\n2. Testing Environmental Sensors...")
temp = sense.get_temperature()
humidity = sense.get_humidity()
pressure = sense.get_pressure()

print(f"   Temperature: {temp:.1f}°C")
print(f"   Humidity: {humidity:.1f}%")
print(f"   Pressure: {pressure:.1f} mbar")

# 3. Motion Sensors
print("\n3. Testing Motion Sensors...")
orientation = sense.get_orientation_degrees()
accel = sense.get_accelerometer_raw()

print(f"   Pitch: {orientation['pitch']:.1f}°")
print(f"   Roll: {orientation['roll']:.1f}°")
print(f"   Yaw: {orientation['yaw']:.1f}°")
print(f"   Acceleration: x={accel['x']:.2f}g y={accel['y']:.2f}g z={accel['z']:.2f}g")

# 4. Compass
print("\n4. Testing Compass...")
north = sense.get_compass()
print(f"   North direction: {north:.1f}°")

# 5. Joystick
print("\n5. Testing Joystick...")
print("   Press any direction on the joystick!")
print("   (Test will wait 5 seconds)")

event_detected = False
def any_direction(event):
    global event_detected
    if event.action == 'pressed':
        event_detected = True
        print(f"   ✓ {event.direction} detected!")
        sense.show_letter("✓", text_colour=[0, 255, 0])

sense.stick.direction_any = any_direction
time.sleep(5)

if not event_detected:
    print("   ⚠ No joystick input detected")

sense.clear()
print("\n" + "=" * 50)
print("  TEST COMPLETE!")
print("=" * 50)

Centro de Inovação Carlos Fiolhais

Made for teaching Raspberry Pi Sense HAT to young innovators 🚀

This is a simulator - run the Python code on your actual Raspberry Pi with Sense HAT!