Lesson 4: Camera & RGB

The Astro Pi is equipped with a camera for Earth observation and an LED matrix for status updates. In this lesson, we will learn how to control both.

Session Goals
  • Initialize the Camera and Sense HAT.
  • Control the LED Matrix (clear, set pixels, show text).
  • Capture Images using the camera library.

The Mission Task

We need to create a visual countdown sequence before capturing an image. This alerts the crew (or indicates status) before an operation begins.

Key Concepts

RGB Color Model
Colors are defined by mixing Red, Green, and Blue values (0-255).
Red=(255,0,0), Green=(0,255,0), Blue=(0,0,255).
Pixel Coordinates
The LED matrix is an 8x8 grid. Coordinates (x, y) start at (0, 0) in the top-left and go to (7, 7) in the bottom-right.
Camera Preview vs Capture
Taking a photo saves a file to disk. In our simulation, you will see a log message confirming the capture.

Sense HAT (LEDs & Sensors)

Controls the LED matrix and reads environmental sensors.

from sense_hat import SenseHat
UsageDescription
sense = SenseHat()Initialize the Sense HAT.
sense.clear(r, g, b)Sets the entire LED matrix to a specific color (0-255).
sense.set_pixel(x, y, r, g, b)Sets a single pixel at (x, y) to a color.
sense.show_letter(string)Scrolls a single character on the matrix.

Camera (picamzero)

Controls the Raspberry Pi Camera Module.

from picamzero import Camera
UsageDescription
cam = Camera()Initialize the camera.
cam.take_photo(filename)Captures an image and saves it to the specified file.

Time

Standard Python library for time-related functions.

import time
UsageDescription
time.sleep(seconds)Pauses execution for the specified number of seconds.

Mission Control Interface

Output Terminal
Ready to execute...