A Raspberry Pi 4 camera streaming application with servo motor control and brightest pixel detection.
- Live Video Streaming: MJPEG stream accessible at
/admin/streamor/admin/stream.mjpeg - Brightest Pixel Detection: Real-time tracking of the brightest point in the camera feed
- Servo Control: Web-based dashboard for controlling two SM-S4303R continuous rotation servos
- Authentication: Admin pages protected with basic HTTP authentication
- Public API: Unauthenticated endpoint for brightest pixel coordinates
- Raspberry Pi 4
- OV5647 Camera Module (connected via MIPI interface)
- 2x SM-S4303R Continuous Rotation Servos
- Servo 1: GPIO 17
- Servo 2: GPIO 27
- Power supply for servos
- Raspberry Pi OS (Debian Trixie)
- Python 3.9+
- pigpiod daemon (for servo control)
# Update system
sudo apt update && sudo apt upgrade -y
# Install pigpio daemon
sudo apt install pigpio python3-pigpio -y
# Enable and start pigpiod
sudo systemctl enable pigpiod
sudo systemctl start pigpiod# Navigate to project directory
cd /path/to/smcs-pi-in-the-sky
# Create virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate
# Install Python dependencies
pip install -r requirements.txtThe .env file contains the login credentials in the format:
ADMIN_USERNAME=username
ADMIN_PASSWORD=password
*These are not the actual admin credentials.
You can modify these in the .env file if needed.
# Make sure pigpiod is running
sudo systemctl status pigpiod
# Activate virtual environment
source venv/bin/activate
# Run the application
python3 app.pyThe server will start on http://0.0.0.0:5000
- Open a web browser
- Navigate to
http://<raspberry-pi-ip>:5000/admin/dashboard - Enter credentials when prompted
- GET
/api/coordinate- Returns the (x, y) coordinates of the brightest pixel
- Example response:
{"x": 320, "y": 240}
-
GET
/admin/dashboard- Web dashboard with video stream and servo controls
-
GET
/admin/streamor/admin/stream.mjpeg- MJPEG video stream from camera
-
POST
/admin/servo/control- Control servo motors
- Request body:
{ "servo": "servo1", // or "servo2" "pulse_width": 1500 // 500-2500 microseconds }
-
POST
/admin/servo/stop- Stop a servo motor
- Request body:
{ "servo": "servo1" // or "servo2" }
The SM-S4303R servos are continuous rotation servos:
- 1500 μs: Stop/Rest position
- < 1500 μs: Clockwise rotation (speed increases as value decreases)
- > 1500 μs: Counter-clockwise rotation (speed increases as value increases)
- Range: 500-2500 microseconds
Experimentally, the best settings for the servos are 1030μs (Servo 1), and 1520μs (Servo 2).
smcs-pi-in-the-sky/
├── app.py # Main Flask application
├── camera.py # Camera management and image processing
├── servo_control.py # Servo motor control using pigpiod
├── templates/
│ └── dashboard.html # Admin dashboard interface
├── .env # Authentication credentials (not in git)
├── requirements.txt # Python dependencies
└── README.md # This file
# Check if camera is detected
rpicam-vid --list-cameras
# Check camera interface is enabled
sudo raspi-config
# Navigate to Interface Options > Camera and enable it# Check if pigpiod is running
sudo systemctl status pigpiod
# Restart pigpiod if needed
sudo systemctl restart pigpiod
# Check GPIO permissions
sudo usermod -a -G gpio $USER# Add user to video group for camera access
sudo usermod -a -G video $USER
# Log out and back in for changes to take effectTo run in development mode with debug enabled, modify app.py:
app.run(host='0.0.0.0', port=5000, debug=True, threaded=True)- Authentication credentials are stored in plain text in
.env - The API endpoint
/api/coordinateis intentionally public - For production use, consider implementing HTTPS and more robust authentication
- Never commit
.envto version control
This project is created for educational purposes under the MIT license. Made by Eli Ferrara, SMCS class of 2026.