Homepage Wiki Forum Buy

Webcam

From GNUBLIN

severity (level) requirement Gnublin family
Gnublin logo easy.png Kernel compile, Toolchain Alle

Contents


If have a project which requires some snapshots of an object or a live-stream you can use a webcam on the Gnublin-board. This article explains how u can use a webcam, and what to do, to get some pictures. We used a Logitech Webcam Pro 9000.

Logitech.jpg


Quickstart with Gnublin Distribution

If you use the Gnublin distribution and a Logitech C170 Webcam (for example from our shop) ) you can use this quickstart. Everything is prepared to work with this webcam.

At first you should plug in the Webcam to the Gnublin board (USB Jumper1 -> Host and USB Jumper2 -> H)

After this you can load the driver with the following command:

modprobe uvcvideo

Snapshot or stream with gnublin-cam

You can use the program gnublin-cam to easily interact with your webcam.

It is important that you first load the module uvcvideo before you use this program, else you will get an error message.


Snapshot

If you want to make a snapshotyou can do this with the following command:

gnublin-cam -i example.jpg

If the snapshot has bad quality you can try to set another higher resolution with the following command:

gnublin-cam -i example.jpg -r 800x600


Start a webstream

If you want to start a webstream, you can do this with the following command:

gnublin-cam -s

Please note that you need a working WLAN/LAN/USB-Gadget connection to see the webstream. Another important thing is that the program blocks the input when its active. You can also start the stream in the background with the following command, so you can work in a normal way while the stream is active:

gnublin-cam -b

Further options for this program are -r and -p. With the parameter "-r" you can specify the resolution of the stream and with "-p" the port on which the stream runs.

Here is an example call with resolution=640x480 and Port=5555 and the stream in the background:

gnublin-cam -b -r 640x480 -p 5555

For advanced

Identify the driver

It's recommended to plugin the device into a PC/Laptop running Linux, if u want to identify the drivers.

After u plugged in the webcam you should get an output like the following output if u type lsusb into a shell:

Bus 002 Device 009: ID 046d:0809 Logitech, Inc. Webcam Pro 9000

If you type the command dmesg you should also get the module which was loaded:

[  149.506737] usb 2-1.5: new high-speed USB device number 3 using ehci_hcd
[  149.817836] uvcvideo: Found UVC 1.00 device <unnamed> (046d:0809)

Here you can see that the module uvcvideo was loaded for the webcam. If you don't get an output like this by the command dmesg, you can use the command lsmod to identify the matching driver module (plugout the webcam, type lsmod and look at the output, -> plugin the webcam and type lsmod again, the driver which is new in the list should be the webcam driver)

Attention: If you got a Laptop with a buildin webcam it could be that there are two different modules loaded for webcams (except the chipset of the webcams is identical)


Searching and preparing the Kernel modules

You can find the kernel modules for webcams in the menuconfig at Device Drivers--> Multimedia Support --> Video for Linux --> Video capture adapters --> V4L USB devices

Kernel module:

 │ │   Device Drivers   --->                                                     │ │   
 │ │       	<M> Multimedia support  --->                                     │ │   
 │ │       	   <M>   Video For Linux                                         │ │   
 │ │       		[*]   Video capture adapters (NEW)  --->                 │ │   
 │ │       		   [*]   V4L USB devices (NEW)  --->                     │ │   
 │ │       			    <M>   USB Video Class (UVC)                  │ │   


How to compile the kernel and the modules is described in the article Kernel compile + Module installation.


Loading the kernel module + creating device file

After you have compiled the kernel and the modules you should copy the files to the SD-card and bottup the Gnublin. Now you can load the module with the following command.

 root@gnublin-debian:~# modprobe uvcvideo

The command gives us the following output for our webcam:

Linux video capture interface: v2.00
uvcvideo: Found UVC 1.00 device <unnamed> (046d:0809)
input: UVC Camera (046d:0809) as /devices/platform/lpc-ehci.0/usb1/1-1/1-1:1.0/input/input0
usbcore: registered new interface driver uvcvideo
USB Video Class driver (v0.1.0)


If you have udev running on your Gnublin, you can skip the following command, else if you don't have udev running on your Gnublin (nearly everybody) you must create a device-file, to communicate with the webcam.

Therefor you must use the following command:

root@gnublin-debian:~# mknod /dev/video0 c 81 0


Prepare to take snapshots

Now we have to install some debian packages before we are able to take some snapshots.

Gnublin with Debian

If you're running Debian on your Gnublin, you can install the packages and the dependencies with apt-get:

root@gnublin-debian:~# apt-get install fswebcam uvccapture

You must have a working internet connection of course. If you don't have a working connection to the internet on your Gnublin just download the packages from the first step of the guide "how to install the .deb packages on Gnublin systems without Debian" and copy the *.deb files into your home-directory on your SD-card and execute the following command for each *.deb file:

root@gnublin-debian:~# dpkg -i package.deb

Gnublin without Debian

If you don't have Debian running on your Gnublin, you must install the packages manually. This is how we do it:

Downloading the relevant packages

First we have to download the packages on a PC/Laptop running Linux:

fswebcam	Program to take Snapshots				from	http://packages.debian.org/squeeze/fswebcam
libgd2-noxpm	GD-graphi-lib(dependencie from fswebcam)		from	http://packages.debian.org/squeeze/libgd2-noxpm
libjpeg62	Shared Librarys to handle JPG files			from	http://packages.debian.org/squeeze/libjpeg62
libv4l-0	Librarys to handle Video4Linux Devices			from	http://packages.debian.org/squeeze/libv4l-0
libfreetype6	Librarys for the FreeType 2 font engine			from	http://packages.debian.org/squeeze/libfreetype6
libpng12-0	Library to handle PNG- Dateien				from	http://packages.debian.org/squeeze/libpng12-0
zlib1g_1.2.3	Library for compression( zlibONEg_1.2.3)		from	http://packages.debian.org/squeeze/zlib1g
uvccapture	Alternative to fswebcam					from	http://packages.debian.org/squeeze/uvccapture

ATTENTION: You must download these packages for the ARM architecture (if you click on one of the links you can download the package on the bottom of the site. There you must choose armel )

Converting the packages

If you're finished with downloading the packages you must install a small programm on your PC/Laptop to convert the *.deb files to *.tar.gz files. The program is called Alien and you can get it by typing apt-get install alien into a shell.

After the installation of alien you can convert the packages with the following command (Please NOTE: You must type the alien -t command for every package you will convert. You must also be in the right directory on the shell):

alien -t package.deb

Installing the packages

After you have finished converting the packages you should have 8 new files with .tar.gz at the end of the filename. Now you can copy these files to the root-directory on the SD-card. Boot up the Gnublin-board and type the following to install the packages:

root@gnublin:~# cd /
root@gnublin:/# tar -xzvf package

Note: You have to extract every package with the command above.

If you have done this you can go on and take the first snapshot.


Taking pictures

Now after everything is installed you can take some snapshots. Therefor you just change in the directory you want to store the pictures on the Gnublin and execute the following command:

root@gnublin:~/Photo# fswebcam -v -S 1 -r 640x480 -d /dev/video0 -i 0  out.jpeg

The options of the command are explained very easily

-v  	means verbose mode, and gives us additional output
-S 1	the program deletes the first picture taken and saves the second picture(the first picture has bad quality most of the time)  
-r  	setting the resolution in our example 640x480
-d  	tells the program which device to use in our case /dev/video0
-i  	tells the program which interface it should use in our case interface 0
  	the last line ist just the name of the picture which is saved

Note: If you dont specify the resolution by -r the program uses thwe standard resolution for the webcam (not the best resolution) Our Webcam has got the standard resolution of 352 × 288 Pixels. But you will get a much better picture if you set the resolution to 800 x 600 Pixels or something like that. Just test the best resolution for your webcam.

This is an output example of the command above:

root@gnublin-debian:~# fswebcam -v -S 1 -d /dev/video0 -i 0 out2.jpeg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
src_v4l2_get_capability,86: /dev/video0 information:
src_v4l2_get_capability,87: cap.driver: "uvcvideo"
src_v4l2_get_capability,88: cap.card: "UVC Camera (046d:0809)"
src_v4l2_get_capability,89: cap.bus_info: "usb-lpc-ehci.0-1"
src_v4l2_get_capability,90: cap.capabilities=0x04000001
src_v4l2_get_capability,91: - VIDEO_CAPTURE
src_v4l2_get_capability,102: - STREAMING
src_v4l2_set_input,180: /dev/video0: Input 0 information:
src_v4l2_set_input,181: name = "Camera 1"
src_v4l2_set_input,182: type = 00000002
src_v4l2_set_input,184: - CAMERA
src_v4l2_set_input,185: audioset = 00000000
src_v4l2_set_input,186: tuner = 00000000
src_v4l2_set_input,187: status = 00000000
src_v4l2_set_pix_format,540: Device offers the following V4L2 pixel formats:
src_v4l2_set_pix_format,553: 0: [0x56595559] 'YUYV' (YUV 4:2:2 (YUYV))
src_v4l2_set_pix_format,553: 1: [0x47504A4D] 'MJPG' (MJPEG)
Using palette MJPEG
Adjusting resolution from 384x288 to 352x288.
src_v4l2_set_mmap,692: mmap information:
src_v4l2_set_mmap,693: frames=4
src_v4l2_set_mmap,740: 0 length=102400
src_v4l2_set_mmap,740: 1 length=102400
src_v4l2_set_mmap,740: 2 length=102400
src_v4l2_set_mmap,740: 3 length=102400
--- Capturing frame...
Skipping frame...
Capturing 1 frames...
verify_jpeg_dht,94: Inserting DHT segment into JPEG frame.
Captured 2 frames in 0.03 seconds.


If you want to take a picture with uvccapture the command looks like:

root@gnublin-debian:~# uvccapture -v  -x 960 -y 720 -d /dev/video0 

The options are also easy to explain. - for verbose mode, -x/-y for the x- and y-resolution and -d for the device


Here you can see a picture taken with the webcam on the Gnublin-Board (standard resolution):

Webcambeispiel.jpg

Error handling fswebcam

With another webcam model (gspca_pac7311 driver) we got an error message if we executed fswebcam.

Because of some weird bugs in gspca you must preload the librarys for fswebcam. You can do this with the following command:

root@gnublin:~# LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so; export LD_PRELOAD

There is no output for the command.

Without preloading the library we get an error message which says No Pallette Information available and the different picture modes of the camera were not recognized correctly.


Other people had similar error messages which can be fixed, by preloading another library:


root@gnublin:~# LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so PROGRAMM_WHICH_NEEDS_A_PRELOAD_LIBRARY

In the case of using fswebcam the command above should look like this : LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so fswebcam


MJPG-Streamer

With the small program mjpg-streamer you can create your own local webstream. You can watch this webstream in every browser.

What do we need?

  1. A webcam which was tested with fswebcam (explained in the guide above how it works)
  2. You must install the package 'libjpeg-dev'! (if u type apt-get install libjpeg-dev in the shell, it recommends the package libjpeg62-dev. this si the right one.)
  3. You need a working network- or internetconnection to watch the stream on a PC or Laptop
  4. An USB-Hub with a external power supply, because the power supply of the GNUBLIN is too low to power the LAN-adapter and the webcam at once. (strange errors happen if you try to power both devices over a normal USB-hub, e.g a USB-device is registering itself and a second later it is is deregistering again)


Assembling the components:

Webstream.jpeg


There are two different options how to install the program mjpg-streamer. The first option is to download and use the precompiled program and the second option is to compile the program by yourself.

PLEASE NOTE We tested only a webcam which used the module uvcvideo but it should also work to use webcams which use the gspca module. To use the program with a gspca-webcam you must only exchange the word "input_uvc.so" with the word "input_gspcav1.so" in the program execution command below.

Precompiled version

The easiest way to get the program running is to download the precompiled package from this link and read the tutorial below:

Download the precompiled package and copy it to the root-directory (/) on the SD-card of the Gnublin. After you've done this, bootup the board and execute the following commands:

cd /
tar -xzvf mjpeg-streamer.tar.gz

Thats it, now you can run the program with the following command:

mjpg_streamer -i "/lib/input_uvc.so -d /dev/video0  -r 800x600" -o "/lib/output_http.so -p 8080 -w /usr/www -n"

After this you can watch the stream in a browser of your choice. You need the IP-Address of the Gnublin (with the command ifconfig you can list the network-device and the IP-addresses. If you got WLAN you should lookup the IP from wlan0. If u got LAN you should lookup the IP from eth0)

To watch the stream with a browser, you just have to type the following in your addressbar:

IP-ADDRESS:8080/?action=stream 

In our case (Gnublin IP-Address=192.168.0.182) the command looks like this:

192.168.0.182:8080/?action=stream


Compile the Sources

If you want to compile the sources by yourself , you need to insttall the following two packages first. You can do this with apt-get (Debian) or you can read this article.

apt-get install gcc
apt-get install make

Please Note that the package gcc, has a lot of dependencies so the installation by hand is really complicated.

You can find the newest version of mjpg-streamer here

If you have dowloaded the package, you can copy it into a directory of your choice on the SD-card. (Just remember where you copied it)

Afterwards you can boot the Gnublin and change the directory (cd ) in which the tar file of the sourcec is located. (e.g cd ~/mjpg-streamer)

Now we extract the previously copied program source archiv with the command tar -xzvf NAME (please replace NAME with the name of your file)

After you've extracted the file, there should be a new directory. Now change into the directory (cd ). (the directory could be called mjpg-streamer-r63 for example)

If we changed into the directory we have to exevute the following command to compile the program:

make clean all

This could take a while, depending on your Gnublin version (There will be a bunge of warnings in the output, but we don't care about them. It's important that there are no errors)


After compilation we can start the program with the following command:

./mjpg_streamer -i "/root/mjpg-streamer-r63/input_uvc.so -d /dev/video0  -r 800x600" -o "/root/mjpg-streamer-r63/output_http.so -p 8080 -w /usr/www -n"

ATTENTION this command is customized to our system. The command could look totally different, depending on the name of the directory in which you copied mjpg-streamer. We have extracted the program into the home-directory (~/). The program file and the files input_uvc.so and output_http.so were located in the directory /root/mjpg-streamer-r63

After this you can watch the stream in a browser of your choice. You need the IP-Address of the Gnublin (with the command ifconfig you can list the network-device and the IP-addresses. If you got WLAN you should lookup the IP from wlan0. If u got LAN you should lookup the IP from eth0)

To watch the stream with a browser, you just have to type the following in your addressbar:

IP-ADDRESS:8080/?action=stream 

In our case (Gnublin IP-Address=192.168.0.182) the command looks like this:

192.168.0.182:8080/?action=stream

Possible errors

We got the following error message at the beginning:

MJPG Streamer Version.: 2.0
ERROR: could not find input plugin
       Perhaps you want to adjust the search path with:
       # export LD_LIBRARY_PATH=/path/to/plugin/folder

This error message says that the program couldn't find the file input_uvc.so or output_http.so. If you get this error message please check if the path to the files is correct in the mjpg-streamer command.

Trust Webcam VGA USb 1.1

Trust.jpeg

The easiest way to identify the chipset of the webcam is to connect the webcam to a PC/Laptop running Linux.

The output of lsusb looks like this:

Bus 001 Device 002: ID 093a:2600 Pixart Imaging, Inc. Typhoon Easycam USB 330K (newer)/Typhoon Easycam USB 2.0 VGA 1.3M/Sansun SN-508

The output of lsmod looks like this:

gspca_pac7311          13452  0 
gspca_main             27141  1 gspca_pac7311

So we know that the webcam is using the pac7311 driver. Luckily the driver also exists in the 2.6.33 kernel for Gnublin.

You can find the driver at Multimedia Support -> Video capture adapters -> V4L USB devices -> GSPCA based webcams

The modules and software can be installed exactly how it's described above.

Attention this webcam was not supported completely by fswebcam. To make this webcam work with fswebcam please read the section [Error handling fswebcam] above.


QuickCam Messenger Plus (V-UAS14)

Under Construction

Drivers for Quickcam

In other languages