In this Getting Started project, we run computer vision AI using the Raspberry Pi AI Camera powered by Sony’s IMX500 on a Raspberry Pi 5. While the Pi 5 is powerful and flexible, you may prefer a more cost-effective, compact, and energy-efficient device for deployment. This setup can comfortably run on battery power.
What You’ll Need
- Raspberry Pi Zero 2 W
- Raspberry Pi AI Camera (IMX500)
- Raspberry Pi Zero case (Optional)
- SD card (32GB+ recommended)
- Internet connection to setup and update IMX500 libraries.
- Keyboard, mouse, monitor (for local setup)
In this project, we will go through how you set up Raspberry Pi Zero 2 W to leverage AI capabilities of IMX500. As mentioned, this project builds on the Getting Started guide and focuses on the key differences and additional steps.
Step-by-Step InstructionsSystem Setup
1️⃣ Connect the Camera to the Raspberry Pi Zero 2 W
Securely connect your Raspberry Pi AI Camera to the CSI port on your Raspberry Pi Zero 2W.
📌 Note: Camera Lid of Raspberry Pi Zero case needs small DIY to make 12mm x 13mm rectangle to fit Raspberry Pi AI Camera.
2️⃣ Set Up Your Raspberry Pi SD Card
Using Raspberry Pi Imager select Raspberry Pi OS (Other)
Then Select Raspberry Pi OS Lite (64bit).
Please make sure to configure WiFi settings in Raspberry Pi Imager before you write to SD Card.
📌 Note: Raspberry Pi OS with Desktop is overwhelming for the Raspberry Pi Zero 2 W. While the Zero 2 W is more powerful and capable than the original Raspberry Pi Zero, running the full desktop OS often leads to resource constraints and noticeable latency during basic operations. For our purposes, desktop features are typically unnecessary, so we used Raspberry Pi OS Lite instead.
3️⃣ Update to the Latest Raspberry Pi OS
Once you booted into Raspberry Pi OS lite, you'll need to install additional libraries using the following commands :
sudo apt update && sudo apt full-upgrade -y
sudo apt install -y python3-libcamera python3-kms++ libcap-dev
sudo apt install -y imx500-all
📌 Note: With Raspberry Pi 2 W the above process can take 10 to 15 minutes.
4️⃣ Create a working folder
Create a folder to save sample app and navigate to it.
mkdir camera-app
cd camera-app
5️⃣ Download and Save the Sample App Source Code
Download and unzip source files to your working folder. Download using the following command:
wget https://hacksterio.s3.amazonaws.com/uploads/attachments/1866874/source.zip
6️⃣ Unzip source files
Unzip source files to the project folder using the following command :
unzip source.zip
7️⃣ Install Python Package Manager
Update Python Package Manager (pip) by running :
pip install --upgrade pip==24.0
📌 Note: PIP version 24.1 and above requires packages to follow version specifiers described here. Some of packages are not updated to follow this change so we are using pip version 24.0
8️⃣ Install all Python libraries to the system with:
pip3 install --break-system-pacakges -r ./requirements.txt
9️⃣️ Run the application and access to Web UI
Start the sample app with :
python3 ./main.py
This will launch python application that hosts a web server.
Open browser on your PC and navigate to: http://<IP Address or Raspberry Pi Zero 2 W>:8080. You should now see real-time detection using MobileNet SSDv2 on the IMX500-powered camera!
📌 Note: You can find IP Address of your Raspberry Pi Zero 2 W with :
hostname -I
🔟 Register the app as a service
Since we want to use Raspberry Pi Zero 2 W as a camera, let's register this demo app as a service so you do not have to manually start the app.
📌 Note: Please ensure that the path to the sample app and user name are correct in imx500.service file. If you used a different folder name and user name, update ExecStart, WorkingDirectory, and User settings in imx500.service file.
[Unit]
Description = imx500 sample app
Wants = network-online.target
[Service]
ExecStart=/usr/bin/python3 /home/pi/camera-app/main.py
WorkingDirectory=/home/pi/camera-app
User=pi
StandardOutput=inherit
StandardError=inherit
Restart=always
Type=simple
[Install]
WantedBy=multi-user.target
Copy service definition file and enable it with :
sudo cp service/imx500.service /etc/systemd/system/imx500.service
sudo systemctl enable imx500.service
Enable auto login with :
sudo raspi-config
Select System Option -> Auto Login to enable Auto Login.
Reboot the device, then access your Raspberry Pi Zero 2 W from Browser on your PC.
📌 Note: If Console is difficult to read because of font size, you can change console font size with :
sudo dpkg-reconfigure console-setup
Now that you've successfully run your first demo, you can explore more advanced possibilities:
- Swapping out the model with your own.
- Logging detections or triggering actions.
- Start building your own apps — from people counters to inventory trackers and smart door alerts.
Comments