Today, I’m going to show you how to use raspberry PI and a USB camera to build a simple monitor, with which you can view the moving images captured by the camera on your computer.

1. Camera detection

The Raspberry PI supports many common USB cameras, like the one Used by Yoshi:

This type of camera can be directly powered by USB and data communication via USB cable. It’s also easy to connect to the PI by plugging it directly into the PI’S USB port.

How do you know if the raspberry PI knows when you plug it in? There are two ways to determine this:

Method 1: Check whether the video0 file exists in the /dev/directory

pi@raspberrypi:~ $ ls /dev/video*
/dev/video0
Copy the code

Method 2: Check whether the USB device is new

pi@raspberrypi:~ $ lsusb Bus 001 Device 004: ID 0458:706D KYE Systems Corp. (Mouse Systems) Genius iSlim 2000AF V2 # Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub Bus 001 Device 001: ID 1D6b :0002 Linux Foundation 2.0 Root HubCopy the code

2. Install the Motion program

Take Raspbian, the official system, for example. To install Motion, simply enter the following command:

sudo apt-get install motion
Copy the code

If the installation fails, you may need to run the following two commands:

sudo apt-get update
sudo apt-get upgrade
Copy the code

3. Configure the Motion daemon

Use vim to modify /etc/default/motion. If the system does not have Vim installed, install it in advance, or use the Nano editor.

sudo vim /etc/default/motion
Copy the code

We changed no to yes to keep the daemon running in the background:

# set to 'yes' to enable the motion daemon
start_motion_daemon=yes
Copy the code

4. Modify the Motion configuration file

First, open the Motion configuration file with Vim or Nano:

sudo vim /etc/motion/motion.conf
Copy the code

The configuration file is a bit long, but there are a few options that must be changed, and the rest is the default.

We need to change daemon off to daemon on and stream_localhost on to stream_localhost off. These two are not in the same location, so we need to search for them.

# Start in daemon (background) mode and release terminal (default: off)
daemon on

# Restrict stream connections to localhost only (default: on)
stream_localhost off
Copy the code

Of course, we can also change the screen size:

# Image width (pixels). Valid range: Camera dependent, default: 352
width 800

# Image height (pixels). Valid range: Camera dependent, default: 288
height 600
Copy the code

Run the :wq command to save the changes and exit.

5. Start the configuration

First, start the Motion service:

sudo service motion start
Copy the code

Then, start Motion again:

pi@raspberrypi:~ $ sudo motion [0:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf [0:motion] [NTC] [ALL] motion_startup: Motion 4.0 Started [0: Motion] [NTC] [ALL] motion_startup: Logging to a file (/ var/log/Motion/Motion. The log)Copy the code

6. Check the effect

After completing the above steps, you can view the effect in your browser. However, when I use The 360 browser, I can’t see the effect, and when I use Google Chrome, everything works fine. The Internet said Firefox would work, but never tried.

Open Google Browser and enter http://raspberry PI IP:8081 to view the image captured by the camera. The IP address of the raspberry PI can be seen in the background management of the router or searched by the IP scanner, which is not described here.

> < p style = “max-width: 100%; clear: both
#### read all is true love, a praise to walk again? Your “sanlian” is the biggest motivation for liang Xu’s continuous creation!
1\. Follow the ** original ** * public account “** Liangxu Linux**”, the first time to get the latest Linux dry goods!
2. Public account background reply [information] [interview] [resume] to get selected first-line big factory interview, self-improvement, resume and other information.
3\. Follow my blog: [lxlinux.net]([http://www.lxlinux.net]](http://www.lxlinux.net%29/)