Raspberry Pi & Phidgets Workshop

Glossary, Challenges & Resources

Raspberry Pi & Electronics Glossary

A comprehensive guide to terminology used throughout the workshop.

A

ADC (Analog-to-Digital Converter)
A device that converts continuous analog signals (like voltage) into discrete digital values that can be processed by a computer. The ADC0834 is an 8-bit ADC used in the workshop to read solar panel voltage.
Anode
The positive terminal of an electronic component. In an LED, the anode is the longer leg which connects to the positive side of the circuit (usually through a resistor).

B

Breadboard
A reusable solderless device for prototyping electronic circuits. It has holes connected by metal strips underneath, allowing components to be inserted and interconnected without soldering.
Button
A simple tactile switch that completes a circuit when pressed. In GPIO Zero, buttons are represented by the Button class, which can detect when the button is pressed or released.
Buzzer
An audio signaling device that produces a buzzing sound. In GPIO Zero, buzzers are represented by the Buzzer class, which can produce continuous tones or beeping patterns.

C

Cathode
The negative terminal of an electronic component. In an LED, the cathode is the shorter leg which connects to the negative side of the circuit (usually ground).
CSI (Camera Serial Interface)
A specialized port on the Raspberry Pi for connecting the Raspberry Pi Camera Module. The ribbon cable connects to this port, with the blue tab facing away from the Ethernet port.
CSV (Comma-Separated Values)
A simple file format used to store tabular data, with each line representing a row and commas separating the values in each row. Python's csv module is used to read and write CSV files.

G

GND (Ground)
The reference point in an electrical circuit from which voltages are measured, usually defined as 0 volts. In Raspberry Pi circuits, GND pins provide the ground connection.
GPIO (General Purpose Input/Output)
Pins on the Raspberry Pi that can be programmed to act as inputs or outputs for digital signals. They can be used to connect sensors, LEDs, buttons, and other components.
GPIO Zero
A Python library for controlling GPIO devices connected to the Raspberry Pi. It provides simple interfaces for common components like LEDs, buttons, and sensors.

I

I2C (Inter-Integrated Circuit)
A communication protocol that allows multiple devices to connect to the Raspberry Pi using just two pins (SDA and SCL). The Sense HAT uses I2C to communicate with the Raspberry Pi.

J

Jumper Wire
A wire with connectors at both ends used to establish electrical connections between components on a breadboard or between a breadboard and a Raspberry Pi.

L

LED (Light Emitting Diode)
A semiconductor device that emits light when current flows through it. LEDs have two legs: the longer one (anode) connects to the positive side of the circuit, and the shorter one (cathode) connects to the negative side.

P

Phidget
A brand of USB sensors and controllers. In the workshop, we use Phidget LCD displays to show sensor readings and status information.
Picamera2
A Python library for controlling the Raspberry Pi Camera Module. It replaces the older picamera library and provides more features and better performance.
PIR (Passive Infrared) Sensor
A motion detection sensor that detects changes in infrared radiation (heat) emitted by moving objects. PIR sensors are commonly used for motion-activated lights and security systems.
Photoresistor
A light-sensitive resistor whose resistance decreases when exposed to light. Also known as an LDR (Light Dependent Resistor). Used to detect ambient light levels.

R

Resistor
An electronic component that limits the flow of current in a circuit. Resistors are color-coded to indicate their resistance value in ohms (Ω). In LED circuits, resistors prevent excessive current that could damage the LED or the Raspberry Pi.

S

SPI (Serial Peripheral Interface)
A communication protocol used for short-distance communication between devices. The ADC0834 chip uses SPI to communicate with the Raspberry Pi.
Sense HAT
An add-on board for the Raspberry Pi that includes an 8×8 RGB LED matrix, a joystick, and several sensors (temperature, humidity, pressure, acceleration, gyroscope, and compass).

T

Thermistor
A temperature-sensitive resistor whose resistance changes with temperature. Used to measure temperature in electronic circuits.

V

Voltage Divider
A circuit consisting of two resistors in series that reduces a higher voltage to a lower one. In the solar energy monitoring activity, a voltage divider is used to reduce the solar panel voltage to a level that can be safely measured by the ADC.

Challenge Activities

Put your skills to the test with these progressive challenges, organized by difficulty level.

Multi-Pattern LED Sequencer

Beginner

Create a program that cycles through multiple LED blinking patterns. Each pattern should run for a few seconds before switching to the next pattern.

Materials Needed:

  • Raspberry Pi
  • 3 LEDs (different colors)
  • 3 x 220Ω resistors
  • Jumper wires
  • Breadboard

Objectives:

  1. Connect 3 LEDs to different GPIO pins
  2. Create at least 3 different blinking patterns (e.g., sequential, alternate, all-blink)
  3. Switch between patterns every 5 seconds
  4. Run continuously until the program is stopped

Need a hint?

Define each pattern as a separate function. Here's a simple example to get started:

from gpiozero import LED
from time import sleep

red = LED(17)
yellow = LED(27)
green = LED(22)

def pattern_sequential():
    for _ in range(3):  # Repeat 3 times
        red.on()
        sleep(0.5)
        red.off()
        yellow.on()
        sleep(0.5)
        yellow.off()
        green.on()
        sleep(0.5)
        green.off()

def pattern_alternate():
    for _ in range(5):  # Repeat 5 times
        red.on()
        green.on()
        yellow.off()
        sleep(0.3)
        red.off()
        green.off()
        yellow.on()
        sleep(0.3)
    
    yellow.off()

# Main loop that switches patterns
while True:
    pattern_sequential()
    sleep(1)  # Pause between patterns
    pattern_alternate()
    sleep(1)  # Pause between patterns

Try adding a third pattern and use a list to cycle through them!

Smart Environment Monitor

Intermediate

Create a system that monitors both temperature and light levels, logs the data to a CSV file, and provides visual feedback through LEDs. The system should also track daily highs and lows.

Materials Needed:

  • Raspberry Pi
  • Temperature sensor (DS18B20)
  • Photoresistor module
  • 2 LEDs (red for temperature alerts, blue for light level)
  • 2 x 220Ω resistors
  • 4.7kΩ resistor (for DS18B20)
  • Jumper wires
  • Breadboard

Objectives:

  1. Read temperature and light level every 30 seconds
  2. Log data to a CSV file with timestamps
  3. Track daily high and low temperature
  4. Control LEDs based on readings:
    • Red LED: On when temperature exceeds threshold
    • Blue LED: Brightness reflects light level (use PWM)
  5. Display summary statistics in the terminal

Need a hint?

Use the PWMLED class for the blue LED to control brightness based on light level. Here's a structure to get started:

from gpiozero import LED, PWMLED, DigitalInputDevice
from w1thermsensor import W1ThermSensor
import time
import csv
from datetime import datetime

# Setup components
temp_sensor = W1ThermSensor()
light_sensor = DigitalInputDevice(4)
temp_led = LED(17)  # Red LED for temperature alerts
light_led = PWMLED(18)  # Blue LED with variable brightness

# Thresholds
TEMP_THRESHOLD = 75  # Fahrenheit

# Track daily highs and lows
today = datetime.now().date()
daily_high = -float('inf')
daily_low = float('inf')

# Setup CSV logging
filename = f"environment_log_{today.strftime('%Y%m%d')}.csv"
with open(filename, 'a', newline='') as csvfile:
    writer = csv.writer(csvfile)
    # Write header if file is new (empty)
    if csvfile.tell() == 0:
        writer.writerow(['Timestamp', 'Temperature_F', 'Light_Level', 'Daily_High', 'Daily_Low'])
    
    try:
        while True:
            # Get current time
            now = datetime.now()
            timestamp = now.strftime('%Y-%m-%d %H:%M:%S')
            
            # Check if it's a new day
            current_date = now.date()
            if current_date != today:
                today = current_date
                daily_high = -float('inf')
                daily_low = float('inf')
                # Create new log file for new day
                filename = f"environment_log_{today.strftime('%Y%m%d')}.csv"
                with open(filename, 'w', newline='') as new_csvfile:
                    new_writer = csv.writer(new_csvfile)
                    new_writer.writerow(['Timestamp', 'Temperature_F', 'Light_Level', 'Daily_High', 'Daily_Low'])
            
            # Read sensors
            temp_c = temp_sensor.get_temperature()
            temp_f = temp_c * 9/5 + 32
            light_level = 0 if light_sensor.value else 1  # Invert because sensor is HIGH in darkness
            
            # Update daily high/low
            if temp_f > daily_high:
                daily_high = temp_f
            if temp_f < daily_low:
                daily_low = temp_f
            
            # Control LEDs
            if temp_f > TEMP_THRESHOLD:
                temp_led.on()
            else:
                temp_led.off()
                
            light_led.value = light_level  # 0.0 to 1.0 brightness
            
            # Log data
            writer.writerow([timestamp, f"{temp_f:.2f}", light_level, f"{daily_high:.2f}", f"{daily_low:.2f}"])
            csvfile.flush()
            
            # Display in terminal
            print(f"{timestamp} | Temp: {temp_f:.2f}°F | Light: {light_level*100:.0f}% | " +
                  f"High: {daily_high:.2f}°F | Low: {daily_low:.2f}°F")
            
            # Wait for next reading
            time.sleep(30)
            
    except KeyboardInterrupt:
        print("\nMonitoring stopped")

This is just a starting point. Consider adding more features like time-based triggers or alerts when conditions change rapidly.

Intelligent Home Monitoring System

Advanced

Create a comprehensive home monitoring system that integrates multiple sensors, provides a web interface for remote monitoring, and implements adaptive behavior based on environmental conditions and time of day.

Materials Needed:

  • Raspberry Pi
  • Temperature sensor (DS18B20)
  • Photoresistor module
  • PIR motion sensor
  • Multiple LEDs (at least 3 different colors)
  • Buzzer for alerts
  • Resistors (various values)
  • Jumper wires
  • Breadboard
  • Optional: Camera module

Objectives:

  1. Implement all sensors with proper calibration
  2. Create different operating modes:
    • "Home" - Normal monitoring with minimal alerts
    • "Away" - Security focus with motion detection and alerts
    • "Night" - Reduced light sensitivity and quiet operation
  3. Implement a Flask web server to:
    • Display real-time sensor readings
    • Show historical data with simple graphs
    • Allow remote mode switching
    • Configure alert thresholds
  4. Create an alert system:
    • Visual indicators (LEDs)
    • Audio alerts (buzzer)
    • Optional: Email/SMS notifications
  5. Implement adaptive behavior:
    • Automatic mode switching based on time
    • Learning from patterns (e.g., typical temperature ranges)
    • Motion sensitivity adjustment based on light levels
  6. If using camera: Take photos when motion is detected in Away mode

Need a hint?

This is a complex project. Start by developing each component separately:

  1. First, get all sensors working individually
  2. Create a basic Flask web server that can display sensor data
  3. Implement the different modes without the adaptive behavior
  4. Finally, add the adaptive components

Here's a sample structure for the Flask application to get you started:

from flask import Flask, render_template, request, jsonify
import threading
import time
import json
from gpiozero import LED, PWMLED, MotionSensor, Buzzer, DigitalInputDevice
from w1thermsensor import W1ThermSensor

app = Flask(__name__)

# Global variables for sensor data and system state
sensor_data = {
    'temperature': 0,
    'light_level': 0,
    'motion_detected': False,
    'last_updated': '',
}

system_state = {
    'mode': 'Home',  # 'Home', 'Away', 'Night'
    'alerts_enabled': True,
    'temp_threshold_high': 78,
    'temp_threshold_low': 65,
}

# Setup hardware
temp_sensor = W1ThermSensor()
light_sensor = DigitalInputDevice(4)
motion_sensor = MotionSensor(27)
red_led = LED(17)
yellow_led = LED(22)
green_led = LED(23)
buzzer = Buzzer(24)

# Routes for web interface
@app.route('/')
def index():
    return render_template('index.html', 
                          sensor_data=sensor_data, 
                          system_state=system_state)

@app.route('/api/data')
def get_data():
    return jsonify(sensor_data)

@app.route('/api/set_mode', methods=['POST'])
def set_mode():
    data = request.get_json()
    system_state['mode'] = data['mode']
    return jsonify({'status': 'success'})

# Function to update sensor data in background
def update_sensors():
    global sensor_data, system_state
    
    while True:
        # Read temperature
        temp_c = temp_sensor.get_temperature()
        temp_f = temp_c * 9/5 + 32
        
        # Read light level (invert because sensor is HIGH in darkness)
        light_level = 0 if light_sensor.value else 1
        
        # Update global data
        sensor_data['temperature'] = temp_f
        sensor_data['light_level'] = light_level
        sensor_data['motion_detected'] = motion_sensor.value
        sensor_data['last_updated'] = time.strftime('%Y-%m-%d %H:%M:%S')
        
        # Apply logic based on mode
        if system_state['mode'] == 'Home':
            home_mode_logic()
        elif system_state['mode'] == 'Away':
            away_mode_logic()
        elif system_state['mode'] == 'Night':
            night_mode_logic()
        
        # Log data to file
        log_data()
        
        # Sleep until next update
        time.sleep(5)

# Mode-specific logic functions
def home_mode_logic():
    # Implement home mode behavior
    pass

def away_mode_logic():
    # Implement away mode behavior
    pass

def night_mode_logic():
    # Implement night mode behavior
    pass

def log_data():
    # Implement data logging
    pass

# Start the background thread for sensor updates
sensor_thread = threading.Thread(target=update_sensors, daemon=True)
sensor_thread.start()

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=False)

You'll also need to create HTML templates for the web interface. Consider using Chart.js for simple graphs of sensor data.

Helpful Resources

Explore these resources to deepen your understanding and expand your Raspberry Pi skills.

Official Documentation

Raspberry Pi Documentation

Comprehensive official documentation for Raspberry Pi hardware, operating system, and peripherals.

Hardware GPIO Software Configuration
Visit Resource

GPIO Zero Documentation

Reference documentation for the GPIO Zero library, with examples and API details for all supported components.

Python GPIO Components API
Visit Resource

Picamera2 Documentation

Detailed guide for using the Picamera2 library with the Raspberry Pi Camera Module.

Camera Python Imaging
Visit Resource

Tutorials & Projects

Raspberry Pi Projects

A collection of beginner to advanced projects created by the Raspberry Pi Foundation, with step-by-step instructions.

Projects Tutorials All Levels
Visit Resource

Adafruit Learning System

Extensive collection of Raspberry Pi projects, tutorials, and guides from Adafruit, focusing on electronics and making.

Electronics Projects Sensors Displays
Visit Resource

Flask Web Development with Raspberry Pi

Learn how to create web applications on the Raspberry Pi using Flask, with examples for sensor data visualization and remote control.

Web Flask Python IoT
Visit Resource

Tools & Libraries

Thonny Python IDE

A beginner-friendly Python IDE pre-installed on Raspberry Pi OS, with features specifically designed for learning programming.

IDE Python Development
Visit Resource

Guizero

A simple Python library for creating graphical user interfaces (GUIs) on the Raspberry Pi, with an easy-to-learn API.

GUI Python Desktop
Visit Resource

Matplotlib

A Python library for creating static, animated, and interactive visualizations, perfect for graphing sensor data.

Visualization Graphs Data Python
Visit Resource