Raspberry Pi + Phidgets

STEM Workshop Reference Guide

Tuscarora Intermediate Unit 11

Jigar Patel - Director of Innovation & Special Projects

jpatel@tiu11.org | stem.tiu11.org

Getting Started with Raspberry Pi Desktop

First Time Setup

  • 1. Connect keyboard, mouse, monitor
  • 2. Insert SD card with Raspberry Pi OS
  • 3. Connect power cable (do this last)
  • 4. Follow setup wizard for WiFi and passwords

Desktop Basics

  • Menu: Click raspberry icon (top-left)
  • Terminal: Menu → Accessories → Terminal
  • Text Editor: Menu → Programming → Thonny
  • File Manager: Menu → Accessories → File Manager

Essential Terminal Commands

File Operations

ls

List files in current directory

cd folder_name

Change to a directory

cd ..

Go up one directory

pwd

Show current directory path

Python & Projects

python3 myfile.py

Run a Python file

nano myfile.py

Create/edit a text file

pip3 install package_name

Install Python libraries

Ctrl+C

Stop a running program

GPIO Pin Reference

Tip: Always connect Ground (GND) first, then power, then signal pins!
GPIO Pin Diagram
Common Pins
  • 6 GND (Ground)
  • 1 3.3V Power
  • 2 5V Power
  • 11 GPIO17
LED Connections
  • Long leg → GPIO pin (through resistor)
  • Short leg → Ground (GND)
  • Always use 220Ω resistor
Sensor Connections
  • VCC → 3.3V or 5V
  • GND → Ground
  • Signal → GPIO pin
  • Check sensor documentation!

Your Components Guide

LEDs
LED

Wiring: Long leg (+) to GPIO, Short leg (-) to GND

Remember: Always use 220Ω resistor

Buttons
Button

Wiring: One pin to GPIO, opposite pin to GND

Code: button.wait_for_press()

Sensors
Sensor

DS18B20: Brown-GND, Blue-3.3V, Yellow-GPIO

Add: 4.7kΩ resistor between Blue and Yellow

Camera
Camera

Connect: Blue side faces away from SD card

Enable: sudo raspi-config → Interface → Camera

Solar Panel
Sunnytech 0.5w 5v 100ma Mini Solar Panel

Model: B016

Specs: 0.5W, 5V max, 100mA max

Voltage Divider Calculation:

R1 = 10kΩ, R2 = 1kΩ

Vout = Vin × (R2 / (R1 + R2))

Vout = 5V × (1k / 11k) = 0.45V per Volt

Final: 5V input → 0.45V output

Wiring: Red(+) to voltage divider, Black(-) to GND

Activity: Solar Energy Monitoring (Activity 6)

Phidget LCD
Phidget LCD

Connect: USB connection

Install: pip3 install Phidget22

Common Errors:

"No device found": Check USB connection

"Permission denied": Run with sudo

"Device timeout": Check serial number

Activity: Environmental Monitoring (Activity 4)

Quick Code Examples

Blink an LED

from gpiozero import LED
from time import sleep

led = LED(17)

while True:
    led.on()
    sleep(1)
    led.off()
    sleep(1)

Button Control

from gpiozero import LED, Button

led = LED(17)
button = Button(2)

button.wait_for_press()
led.on()
sleep(3)
led.off()

Phidget LCD Display

from Phidget22.Phidget import *
from Phidget22.Devices.LCD import *

lcd = LCD()
lcd.setDeviceSerialNumber(123456)
lcd.setChannel(0)
lcd.openWaitForAttachment(5000)

# Display text
lcd.writeText(LCDFont.FONT_5X8, 0, 0, "Hello World!")
lcd.setBacklight(0) # Green backlight

# Clean up
lcd.close()

Solar Panel Monitoring

import spidev
from gpiozero import LED

power_led = LED(17)
spi = spidev.SpiDev()
spi.open(0, 0)

def read_adc0834(channel):
    cmd = 128 + channel << 4
    reply = spi.xfer2([cmd, 0, 0])
    value = reply[2]
    return value

# Convert ADC to real voltage
adc_val = read_adc0834(0)
voltage = adc_val * 3.3 / 255.0 * 11.0
if voltage > 0.5:
    power_led.on()

Read Temperature

from w1thermsensor import W1ThermSensor

sensor = W1ThermSensor()
temp_c = sensor.get_temperature()
temp_f = temp_c * 9/5 + 32

print(f"Temperature: {temp_f}°F")

Take a Photo

from picamera2 import Picamera2

picam2 = Picamera2()
picam2.start()
picam2.capture_file("photo.jpg")
picam2.stop()

Common Problems & Solutions

LED Not Working?

  1. Check LED orientation (long leg to resistor)
  2. Verify resistor is 220Ω (red-red-brown)
  3. Confirm GPIO pin number in code
  4. Test with different LED

Code Not Running?

  1. Check file extension (.py)
  2. Run with: python3 filename.py
  3. Look for red error messages
  4. Check indentation (use spaces, not tabs)

Phidget LCD Errors

"No Phidget found":
→ Check USB connection
→ Try: lsusb to see devices

"Permission denied":
→ Run: sudo python3 myfile.py

"Device timeout":
→ Check serial number in code
→ Try increasing timeout value

"Import error":
→ Run: pip3 install Phidget22

Solar Panel Issues

No voltage reading:
→ Check ADC0834 connections
→ Verify voltage divider

Wrong values:
→ Check calculation: V = ADC × 3.3/255 × 11
→ Test with known voltage source

SPI errors:
→ Enable SPI: sudo raspi-config
→ Install: pip3 install spidev

Workshop Activities Quick Reference

Main Activities
  • Activity 1: Sustainable Lighting System
  • Activity 2: Smart Traffic System
  • Activity 3: Light-Responsive Energy
  • Activity 4: Environmental Monitoring
  • Activity 5: Motion-Activated Conservation
Advanced Activities
  • Activity 6: Solar Energy Monitoring
  • Activity 7: Camera Surveillance
  • Activity 8: GUI Dashboard
  • Activity 9: Voice-Controlled LED
Key Components Used
  • Phidget Graphic LCD
  • SunFounder Raphael Kit
  • Solar Panel (0.5W 5V)
  • Raspberry Pi Camera
  • Motion Sensors

Helpful Resources & Videos

Getting Started
QR Code

Raspberry Pi Setup

Watch Video
Physical Computing with Python
QR Code

Physical Computing with Python

View Project
Python Basics
QR Code

Learn Python

Watch Video

Essential Libraries

  • gpiozero - Hardware control made simple
  • flask - Create web servers
  • picamera2 - Camera control
  • guizero - Easy GUI creation
  • Phidget22 - Phidget LCD control
  • spidev - SPI devices (solar monitor)

Quick Install Commands

# Basic libraries pip3 install gpiozero flask picamera2 # GUI and sensors pip3 install guizero w1thermsensor # Phidget and SPI pip3 install Phidget22 spidev # Complete install pip3 install gpiozero flask picamera2 guizero w1thermsensor Phidget22 spidev
Pro Tip: Run updates first!
sudo apt update && sudo apt upgrade