Introduction
Hey there, I figured I would write this short guide for people looking to get a nice webcam but either can’t find one in stock or can’t afford a high quality webcam due to inflated pricing. I originally wanted to buy a Logitech Streamcam but they’re currently very expensive and alternatives are completely out of stock as of writing.
Recently, Raspberry announced the HQ Camera accessory and the official lenses. So I decided that I could probably build a better webcam than the current offerings with the RPI and the HQ Cam.
Preface: I have tested this on Linux only. Most of this guide should work on other platforms and I have done my best to comment on where things are likely to go wrong. If anyone runs into any issues I’ll correct things ASAP.
Guide
What you’ll need
Hardware:
- Raspberry Pi 4 (~$35 USD) or Raspberry Pi Zero* (~$10 USD)
- Raspberry Pi High Quality Camera (~$50 USD)
- Raspberry Pi HQ Camera Lens - Wide Angle (~$25 USD)
- Class 4 Micro SD Card Minimum 8GB (>$10 USD usually) - I had a 32 GB one laying around so I used that.
- 3.0A USB-C Power Supply - I got mine from CanaKit for ~$10 USD
*I have not tested with a Raspberry Pi Zero but it should work. You might have more trouble doing the headless setup but everything else should be fine.
All together that comes to $130 USD which is significantly cheaper than many of the HQ Webcams I’ve seen, plus being a RPI it has much more utility.
Installation
First, you should make sure that you have a way to SSH into your Pi since this tutorial will be covering how to set up your Pi in a headless configuration (no display).
- Download the Raspberry Pi OS (32-bit) Lite image from here.
- Write the image to your micro SD card using a image writer utility like Etcher.
- Before removing the micro SD card from your computer, we’re going to set up the micro SD card so when you turn on your RPI, it will automatically connect to your network. To begin, navigate to the
boot
directory on your micro SD card and create a file calledwpa_supplicant.conf
and paste the following content:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<Insert 2 letter ISO 3166-1 country code here>
network={
ssid="<Name of your wireless LAN>"
psk="<Password for your wireless LAN>"
}
You can find your country’s ISO letters here but for the USA you can just use US
. Then create a blank file called ssh
.
Once you’ve saved the file you can go ahead and eject the micro SD card.
- Insert your micro SD card into the RPI’s micro SD card slot and connect the USB-C power supply to your RPI to boot it up.
From here you can SSH into your RPI using the following command if your on Linux or Mac:
ssh [email protected]
and the default password is raspberry
When you ssh into your RPI you’ll be greeted with the following prompt:
pi@raspberrypi:~ $
Congrats! You now have a functional Raspberry Pi. Now we’ll move on to setting up our camera.
Camera Setup
Attach your lens to the camera following the directions here for how to attach your lens. Then attach the ribbon cable to the PI’s ribbon slot. Make sure that the blue part is facing the audio jack on the RPI 4!
We’ll begin by enabling the camera and changing the default password.
- Use
sudo raspi-config
where you’ll see this prompt:
-
Select option 1 to change your password.
-
After changing the default password, go to option 5 “Interfacing Options” and enable the camera.
-
Once you’ve enabled the camera restart your RPI by disconnecting and reconnecting the power cable.
-
SSH back into your RPI using your new password.
Now we can install python by running sudo apt install python3 python3-pip
once those packages finish installing run the following command to install our needed python package:
pip3 install picamera
Download this file and run it using
python3 pi_camera.py
You can see if the camera works by going to http://raspberrypi.local:8000/.
Next we’ll focus on setting up the client side.
Client Setup
On the computer you want to use your webcam…
If you’re on Linux or Mac you can go ahead and set up v4l2loopback using the install section and start v4l2loopback using:
modprobe v4l2loopback
then run the following command to pipe your webcam to your dummy video device
ffmpeg -f mjpeg -i "http://raspberrypi.local:8000/stream.mjpg" -vf format=yuv420p -f v4l2 /dev/video0
if you’re on Windows you can use the tool IP Camera Adapter to grab the stream from the above url
You should then be able to add your webcam to any software that taps into your video devices!
Conclusion
Hopefully this saves you some money. Let me know if there are any errors in this post and I will correct them ASAP.
Here’s a picture of my setup. I use it mainly to play Magic the Gathering over the internet: