0
0
Iot-protocolsHow-ToBeginner · 4 min read

How to Use USB Webcam with Raspberry Pi: Simple Setup Guide

To use a USB webcam with a Raspberry Pi, first connect the webcam to the Pi's USB port and verify it is detected with lsusb. Then install software like fswebcam or VLC to capture images or stream video from the webcam.
📐

Syntax

Here are common commands to check and use a USB webcam on Raspberry Pi:

  • lsusb: Lists USB devices connected to the Pi.
  • v4l2-ctl --list-devices: Shows video devices detected.
  • fswebcam [options] filename.jpg: Captures a photo from the webcam.
  • vlc v4l2:///dev/video0: Streams video from the webcam using VLC.

Each command helps you detect, capture, or stream from the USB webcam.

bash
lsusb
v4l2-ctl --list-devices
fswebcam image.jpg
vlc v4l2:///dev/video0
💻

Example

This example shows how to capture a photo from a USB webcam connected to Raspberry Pi using fswebcam.

bash
sudo apt update
sudo apt install fswebcam -y
fswebcam test_image.jpg
ls -l test_image.jpg
Output
-rw-r--r-- 1 pi pi 12345 Apr 27 12:00 test_image.jpg
⚠️

Common Pitfalls

Common mistakes when using a USB webcam on Raspberry Pi include:

  • Not checking if the webcam is detected with lsusb or v4l2-ctl.
  • Trying to use the wrong video device (usually /dev/video0).
  • Not installing required software like fswebcam or v4l-utils.
  • Permissions issues accessing the video device.

Always verify the device and install necessary tools before capturing or streaming.

bash
Wrong:
fswebcam /dev/video1

Right:
fswebcam /dev/video0
📊

Quick Reference

CommandPurpose
lsusbList USB devices connected
v4l2-ctl --list-devicesShow video devices detected
fswebcam filename.jpgCapture photo from webcam
vlc v4l2:///dev/video0Stream webcam video with VLC

Key Takeaways

Connect the USB webcam and verify detection with lsusb.
Use fswebcam or VLC to capture images or stream video.
Check the correct video device, usually /dev/video0.
Install necessary software like fswebcam and v4l-utils.
Verify permissions if you cannot access the webcam device.