Raspberry Pi connected to USB camera

The previous article mentioned the Raspberry Pi. As a card computer, the Raspberry Pi can be connected to many peripherals. Today, let's see how to use the Raspberry Pi to connect a USB camera.


Now the USB cameras on the market are basically free of drive, but it should be noted that we have to confirm that the camera is also free of drive under Linux. Explain the camera you use, pay attention not to advertise XD, the Oni Wolf Demon bought by Jingdong during May Day is only 49 yuan, and you can buy it and play it on the Raspberry Pi.


Ready to work

Before starting the following two tasks, the Raspberry Pi should have already set a static IP, or the IP has been bound to the route, otherwise the IP of the Raspberry Pi will change every time, which is inconvenient to operate.


1. Enable SSH

Enabling SSH on the Raspberry Pi is very simple. Just create an empty file named ssh in the /boot directory of the Raspberry Pi. With SSH, we can interact with the Raspberry Pi through the terminal.


2. Enable VNC

To enable VNC on the Raspberry Pi, you need to install tightvncserver on the Raspberry Pi. Execute the following command in the terminal:

$ sudo apt-get update

$ sudo apt-get install tightvncserver


After the installation is complete, enter the command to run the server:

$ vncserver :1


When logging in, the VNC server address is: Raspberry Pi IP address: 1


If you need to start the vnc service automatically when the Raspberry Pi is turned on, you can create the tightvnc.desktop file in the ~/.config/autostart/ directory

$ cd ~/.config/autostart/

$ vim tightvnc.desktop


Then enter the following:

[Desktop Entry]

Type=Application

Name=TightVNC

Exec=vncserver :1

StartupNotify = false


Connect and test the USB camera

It is very simple to connect the Raspberry Pi to the USB camera. After all, the Raspberry Pi is a card computer of the Linux system. Connect the purchased USB camera directly to the USB port of the Raspberry Pi, and then we can see if the camera is recognized. There are two methods:

1. Use the lsusb command

$ lsusb


The SSH terminal will display the list of USB devices currently connected to the Raspberry Pi. We can first unplug the camera, lsusb, and then plug in the camera lsusb to see which device the USB camera corresponds to. The picture below is my camera.



2. View device files

You can also view the device file and enter the command:

$ ls / dev / video *


Strictly, you should also plug and unplug the camera once to see if a new camera device is recognized. My device file is /dev/video0. Actually, this method is more straight forward, we will use the device file later.

Find the camera, we can use the fswebcam command to test the capture:

$ sudo apt-get install fswebcam

$ fswebcam /dev/video0 ~/image.jpg


The simplest usage of fswebcam, the first parameter is the device file path corresponding to the camera, and the second parameter is the path to save the screenshot.


If you are not satisfied with taking pictures, we can also take a look at the effect of the camera. Just log in to VNC, start the terminal on the Raspberry Pi, and use luvcview:

$ sudo apt-get install luvcview

$ luvcview -s 1080x720


1080x720 is the displayed video resolution, but using the VNC interface will be a little stuck, but you can verify that the camera is working properly. The camera is connected, and everyone can play the application they want to play.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325567748&siteId=291194637