This guide explains how to set up the Pi AI Camera streaming on your Raspberry Pi 5.
- Raspberry Pi 5
- Pi AI Camera module
- Python 3.9 or later
- Network connection
- Install required packages on the Pi:
# Update system
sudo apt update && sudo apt upgrade -y
# Install picamera2 and dependencies
sudo apt install -y python3-picamera2 python3-websockets python3-pil
# Or use pip if needed
pip3 install picamera2 websockets pillow- Copy the streaming script to your Pi:
# Transfer the file to your Pi
scp pi_camera_stream.py pi@mro.local:~/- Make the script executable:
chmod +x ~/pi_camera_stream.py# Start the camera stream
python3 ~/pi_camera_stream.pyThe stream will be available at ws://mro.local:8890 (or your Pi's IP address).
Create a systemd service to auto-start the camera stream:
# Create service file
sudo nano /etc/systemd/system/pi-camera-stream.serviceAdd the following content:
[Unit]
Description=Pi AI Camera WebSocket Stream
After=network.target
[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi
ExecStart=/usr/bin/python3 /home/pi/pi_camera_stream.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetEnable and start the service:
# Reload systemd
sudo systemctl daemon-reload
# Enable service to start on boot
sudo systemctl enable pi-camera-stream.service
# Start the service now
sudo systemctl start pi-camera-stream.service
# Check status
sudo systemctl status pi-camera-stream.service- Open the web interface in your browser
- Click on "MarsPI (Real Rover)" radio button
- A modal will appear asking for connection details
- Enter your Pi's hostname (default:
mro.local) and port (default:8890) - Click "Connect"
- The Pi AI camera stream should now be visible
# Check if camera is detected
libcamera-hello --list-camerasIf port 8890 is already in use, edit pi_camera_stream.py and change the port number on line 118.
- Make sure the Pi is on the same network
- Check that the camera stream service is running:
sudo systemctl status pi-camera-stream.service - Verify firewall rules allow port 8890
# View service logs
sudo journalctl -u pi-camera-stream.service -f- The default resolution is 640x480 at 15 FPS for best network performance
- For higher quality, edit
pi_camera_stream.pyand increase the resolution in the camera configuration - For lower latency on slow networks, reduce the JPEG quality on line 88
Edit pi_camera_stream.py to customize:
- Resolution: Line 79 - Change
"size": (640, 480) - Frame rate: Line 80 - Change
"FrameRate": 15 - JPEG quality: Line 88 - Change
quality=70(1-100, higher = better quality but larger files) - Port: Line 118 - Change
port = 8890