Introduction: RPi Compact AI Camera Feat. Coral USB Accelerator
This is a compact AI camera that runs on a Raspberry Pi Zero 2. It performs MobileNet model inference on a Coral USB Accelerator TPU and features a colorful viewfinder screen.
Disclaimer
I worked on this project back in September 2023. Since then, a lot of exciting developments have happened in the AI and CV world:
- Raspberry Pi AI Kit was released, offering 13 TOPS of performance.
- Raspberry Pi AI HAT+ was released, offering 26 TOPS of performance.
- The Raspberry Pi AI Camera was released. It offers 4 TOPS of performance—the same as the Coral USB Accelerator used in this project—but it effectively eliminates a component and provides a more compact profile.
- The Nvidia Jetson Orin Nano received a software performance boost. It now offers 67 TOPS of performance, making it powerful enough to run LLMs at an acceptable speed. It also natively supports two CSI cameras.
Given that this project was developed some time ago, I will preserve the original environment, including library versions and OS configurations, to ensure continued compatibility and avoid unexpected issues. However, I will not be able to discuss any problems caused by version compatibility. To simplify the setup, I will also not use a Python virtual environment.
If you’re interested in learning how this project works, you’re more than welcome to continue reading!
Supplies
Here is a list of major supplies—don't buy from scalpers!
- Raspberry Pi Zero 2 W - $15
- 2x20-pin GPIO Header - $1
- Raspberry Pi Camera Module 3 - $25
- Pimoroni Display HAT Mini - $21
- Waveshare UPS HAT For Raspberry Pi Zero - $24
- Coral USB Accelerator - $60
- 0.2M USB Type A Male to USB Type C Male FFC Cable - $10
- 0.2M USB Type A Male to Micro USB Male FFC Cable - $7
Total: Around $170
And I assume you already have the following supplies at home as a DIYer :)
- Fasteners to stack them together! Some may come with the kit:
- M2.5 Standoffs Kit - 12 standoffs, 4 screws
- M2 Countersunk Screws Kit - 4 screws
- M2.5 Countersunk Screws Kit - 4 screws, 4 nuts
- Equipment for preparing the Raspberry Pi OS, for example:
- A PC with Raspberry Pi Imager installed
- A micro SD card reader
- A fast micro SD card with at least 4 GB of capacity
- Generic DIY tools, for example
- Screwdrivers
- Soldering tools
- A 3D printer to print the mount of the camera module
Step 1: Flash OS to the Micro SD Card
- Download Raspberry Pi Imager from the official site and install
- Insert the micro SD card to the card reader, and then plug the card reader to the PC's USB port
- Launch the Imager, choose RASPBERRY PI ZERO 2 W as the device
- Choose the legacy 64-bit Bullseye as the Raspberry Pi OS
- Configure the hostname, user account, and network settings in the next step to make sure you can SSH to the system after the first boot
- Proceed to the next steps while waiting for the flash to finish
Step 2: Print the Camera Mount
Download and print the camera module mount from MakerWorld.
Step 3: Put the Components Together
- Start by soldering the GPIO header to the Raspberry Pi.
- Attach the Display HAT Mini to the Pi.
- Secure the display and Pi using the standoffs for the UPS.
- Insert the CSI cable into the Pi, ensuring the gold fingers face the Pi board. Caution: The CSI connector is the most fragile component of the board—handle it with care!
- Prepare the USB FFC cables: Connect the Micro USB connector and the USB Type-C to form a Micro USB Male to USB Type-C Male cable.
- Plug the cable into the Micro USB OTG port on the Pi board.
- Rearrange the CSI cable and USB FFC cables as shown in the picture, then attach the UPS HAT.
- Ensure the POGO pins make proper contact, then secure the assembly with standoffs.
- Fold the USB cable as shown in the picture and connect the Coral TPU.
- Fold the CSI cable and cover it with the TPU.
- Mount the Pi Camera Module 3 to the front plate using the M2 screws and nuts.
- Insert the CSI cable into the Camera Module.
- Finally, fasten the camera front plate, TPU, and the rest of the body together using four M2.5 screws.
Step 4: Prepare the Libraries
Insert the microSD card into the Pi and wait for it to finish booting. Then, SSH into the Raspberry Pi Zero.
First things first, upgrade the OS packages to get the latest security updates:
Then, follow the instructions to install the display driver. Essentially, run the following commands:
After that, follow the instructions to install the Coral TPU Runtime and the pycoral library for the USB Accelerator. Use the following commands:
Finally, downgrade the NumPy library to a version below 2.0.0 to resolve the binary incompatibility issue:
Step 5: Setup the AI Camera Program
Install git:
Clone the repo:
Run the install script. This downloads the MobileNet v2 model from coral repo and put a @reboot entry in CRONtab:
Reboot the device and it is done!