Setting Up My Raspberry Pi and A Logitech C270 Webcam
Setting Up My Raspberry Pi and A Logitech C270 Webcam
Setting Up My Raspberry Pi and A Logitech C270 Webcam
C270 webcam
Categories:
OpenCV, Raspberry
by Yusro
February 24, 2013
From : http://www.bluemoonblog.co.uk/
Im planning to do some high altitude photography with my Raspberry Pi, webcam, and GPS
soon. (but thats another story) And remembering the nightmare I had setting up my Raspberry Pi
and C270 Logitech webcam, I thought it was about time I shared how I did it.
These instructions are very simple an should hopefully save you some trial and error.
Importantly, thanks must go to Insipid Ramblings and Hexxeh for their information and work
that helped me get this far.
Im using Raspbian Wheezy Distro (2013-02-09), so if youre using another Linux OS, your
results may vary depending on what version you use. However, I am assuming that you have
already installed a Raspbian image, and can successfully boot to the desktop. So plug in your
C270 Logitech webcam, and well get started.
1. Add UVC support to the image
Download and run rpi-update as described here. This will update your image to include the
initially-missing UVC support. Reboot as suggested.
2. Update your packages
sudo apt-get update
sudo apt-get upgrade
3. Install the guvcview webcam viewer
sudo apt-get install guvcview
4. Set up your permissions and enable the driver
Related Posts
Zemanta
Now its time to make my old Creative Live! Cam Vista IM (VF0260) Webcam work
on the RasPi, I also tried a new Logitech C270 HD Webcam and they both work
flawlessly out of the box.
I have tried three softwares for the webcam, which I previously tested on my desktop
machine running Fedora and I wanted to try them also on the Pi. These are:
fswebcam
motion
mjpeg-streamer
and append:
dwc_otg.fiq_split_enable=0
fswebcam:
fswebcam is the simplest and easiest way to have your webcam capture single
frames, also programmatically at a specified timer interval. Of course its also
possible to call fswebcam from a bash script anytime its required, but this is
another story.
To install fswebcam simply run:
# apt-get install fswebcam
One of the nice features of fswebcam is that its possible to add a footer to the
capture, where you can specify your text of choice.
For instance, this is the command I ran fswebcam with:
$ fswebcam -r 640x480 -S 15 --flip h --jpeg 95 --shadow --title "SLB Labs" --subtitle "Home" --info
"Monitor: Active @ 1 fpm" --save home.jpg -q -l 60
switches:
-r: frame resolution width*height
-S: numbers of frame to skip for the webcam to capture a stable and well illuminated
frame
--flip: frame flipping, in this case horizontal
--jpeg: jpeg compression quality
--shadow: adds a drop shadow to the footer text
--title, --subtitle, --info: different fields of the footer text
--save: path and file name where to saved the frame to
-q: leaves the process running in background
-l: takes a snapshoot every specified number of seconds
Many more options are described in the man pages of fswebcam
$ man fswebcam
Okay, this wasnt exactly streaming, so lets get into more serious stuff.
motion:
motion is a rather complete surveillance system with no fancy stuff and straight to
the point, yet very customizable. Among what it can do, it is capable of motion
detection, frame recording, video recording, timelapse.
Its installation is as simple as usual:
# apt-get install motion
It comes with a plain web configuration interface, but first of all we need to specify
which port motion will run on. Lets now edit its configuration file:
# nano /etc/motion/motion.conf
and look for the settings webcontrol_port (default 8080) and stream_port (default 8081),
which refers to the web configuration interface and the streaming port, respectively.
Change them as needed or simply get aware of their default values.
To start motion run:
# motion
You can now access to the web configuration interface by pointing your browser to:
http://RPI-IP:webcontrol_port
where RPI-IP is the local IP address of your RasPi and webcontrol_port is the same port
set in the config file.
That said, its now possible to browse all the available settings.
Some of them that are worth a mention are:
width and height: frame dimensions, camera dependent
framerate: maximum number of frames to be captured per second
threshold: number of pixels in the image that must change to trigger the motion
detection
quality: compression level for frame capture
ffmpeg_timelapse: number of seconds between which to take a frame shoot for
timelapse recording
ffmpeg_bps: constant bitrate for video encoding (ignored for timelapses)
ffmpeg_variable_bitrate: variable bitrate for video encoding (using a variable bitrate is
the only way to get decent timelapse videos, this setting is used for both video
motion recording and timelapses)
and of course the different images/video/timelapses paths where to save the
captures to are among the settings you might want to customize.
Another important feature of motion is that its possible to execute any particular
command anytime an event starts and/or a picture is captured, this is achieved by
the setting on_event_start and on_picture_save.
For instance its possible to send an email and upload the saved picture to an ftp
server by setting on_event_start and on_picture_save as follows:
on_event_start sendmail -f YOURFROMEMAIL@gmail.com -t YOURTOEMAIL@gmail.com
-u \"SUBJECT\" -m \"Movement has been detected on: %d %m %Y. The time of the movement was:
%H:%M (Hour:Minute). The Pictures have been uploaded to your FTP account.\" -s
smtp.gmail.com:25 -xu YOURGMAIL@gmail.com -xp YOURGMAILPASSWORD
on_picture_save wput ftp://USERNAME:PASSWORD@YOUTFTP.COM %f
Like said above, the video stream will be available pointing the browser here:
http://RPI-IP:stream_port
mjpeg-streamer:
Another streaming software that I tried was mjpeg-streamer, which is not as features
complete as motion, but it is perfect if you just need a video stream. It also provides
a web interface to display the stream. I couldnt find a binary version of mjpegstreamer for arm processor, so I had to compile it myself as follows.
First off we need mjpg-streamer source code from > here < and save it in your
folder of choice. I usually save and extract the source packages under /usr/local/src.
Position yourself whichever folder the archive has been saved into, and extract the
archive with the command:
# tar xvzf mjpg-streamer-r63.tar.gz
I also needed to create a symbolic link of one header file which, to me, resulted
missing:
# ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h
Now everything should be set to proceed with the compilation process. Switch to
mjpg-streamer newly created folder and compile it with:
# cd mjpg-streamer-r63
# CFLAGS+="-O2 -march=armv6 -mfpu=vfp -mfloat-abi=hard" make
switches:
-i: configure the input section
-d: device selection, in case of multiple webcams
-r: frame resolution width*height
-f: frame per seconds
-o: configure the output section
-w: website folder
-p: port
Its now possible to get access to the web interface at the address:
http://RPI-IP:8080
Share this:
Facebook23
Twitter6
More
Tumblr
StumbleUpon
About SLB
Computer Science Engineer. I'm @slabua pretty much everywhere. Feel free to check
my Google+ profile for more infos: http://plus.google.com/+SalvatoreLaBua
View all posts by SLB
Astroland
Extreme Urban Astronomy In The Netherlands
Skip to content
Home
About Astroland
Astro Gear
Astro Photography
Astro Weather
ScopeHunter
I own Model B (see the Raspberry Pi Wikipedia page for detail about the models) which uses 3.5
Watts.
There are several open source motion detection applications for Linux such as ZoneMinder and
Motion.
Both programs are available through the Rasbian repository.
ZoneMinder looks like a real security control center with all those nice cam screens, but its too
bloated and too CPU heavy for the Raspberry Pi.
Motion is more lightweight and doesnt stress the CPU too much when processing 320200
camera data.
With 2 IP cameras my average load is less than 0.50 on my RasPi, which also serves as an
caching DNS server.
For storage of the AVI video files which contain the captured motion frames, I use a free
Box.com account.
Box.com provides the same service as the popular Dropbox.
The reason for choosing Box.com is because Dropbox has no open source client. The Dropbox
Linux client is closed source and has, at the moment, no support for ARM devices like the
Raspberry Pi.
Furthermore the free Box.com account gives you 10 GB of free storage. Way enough to store
home camera data for a couple of months.
BoxFS2 is the weapon of choice to mount your Box.com account as a drive partition on your
Raspberry Pi.
Some basic Linux knowledge is preferred.
Setting up BoxFS2
First, read the README file on the BoxFS2 site carefully for the needed dependencies
Install the needed libraries from the command prompt:
sudo apt-get install libxml2-dev libfuse-dev libcurl4-gnutls-dev
Besides some libraries from the Raspbian repository, youll also need libapp and libjson.
Get the latest commits from boxfs2, libapp and libjson:
Compile libapp first, then libjson and boxfs2 last using make and sudo make install.
After installing make sure you run the command ldconfig to update links to the libraries for the
operating system.
Forgetting this might give you some error messages about not found libraries.
The BoxFS2 binary will be installed in /usr/local/bin.
Creating a BoxFS2 config file
With the command boxfs-init you can create a config file for BoxFS2.
The configuration file will be placed in the directory .boxfs2.
Open an editor and the configuration file would look something like this:
# Conf file for boxfs
# edit to fit your needs.
# Put oauth2 tokens here:
token_file = /home/pi/.boxfs/token
dperm = 755
The mountpoint must be provided in either way. This can be an empty directory called /motion
for example.
Also check the user id (uid) and the group id (gid) of the user you are using.
You can check this in the passwd file which is located in /etc.
In my case Im using user pi which has user id 1000 and group id 1000.
To let Boxfs2 run as a non-root user you have to add your user to the fuse group:
sudo gpasswd -a fuse
Forgetting this will cause mounting to fail with this error message:
fuse: failed to exec fusermount: Permission denied
To check if everything is doing what it should be doing, go to your BoxFS mount point and try to
create or copy some files.
For debugging I recommend to be logged in to your Box.com account with your browser to see if
things are actually written in to the cloud storage.
Installing and configuring Motion
To install Motion just run this command:
sudo apt-get install motion
Be sure that your cameras and/or webcams output a 320200 (or 240) image and Motion is
configured with the same resolution.
Ive tried a resolution like 640400 pixels, but the CPU load went sky high on the RasPi, so Ive
settled for a lower resolution.
The images generated by my cameras are quite clear and useful, so Im happy.
I have no experience over clocking the Pi in combination with Motion, but if you do, please share
your findings in the comments.
Same goes for solving the above resolution problem
Further configuring Motion is something you have to do on your own.
The on line manual is quite clear about the numerous settings which can be done.
Mailing an image snapshot or a simple message when motion is detected is just one of the many
possibilities.
Oh, and dont forget to set the path to your BoxFS2 mount point to store your videos
When youve got an mobile device, you can use the Box.com app to download an AVI file and
watch it using a movie player which supports the file format.
Great when youre on holiday for example, and want to know whats going on at home.
And all of this without tampering your firewall, keeping your home network closed and secure.
I hope this post helps you to set up your own budget camera surveillance system.
For less than 180 euro (thats 2 decent IP cameras and a RasPi) youre all set to go.
This entry was posted in Raspberry Pi and tagged cloud storage, motion detection, raspberry pi. Bookmark the
permalink.
Visperas says:
November 28, 2012 at 13:42
2.
Astroland says:
November 28, 2012 at 20:42
Hi Visperas,
On the Motion website you can read about the built in http interface:
http://www.lavrsen.dk/foswiki/bin/view/Motion/RemoteControlHttp
With a simple call from a browser, you can set (for example) motion detection on or off.
So when youre about to leave the house you call a bookmarked webpage on your smartphone to
start motion detection.
Reply
3.
Shotca says:
4.
Hi!
Thank you for this tutorial, it was very helpful to me, but the my main project is not exactly this.
And this is why Im asking you:
How can you access the mounted boxfs directory on vnc without root permissions on GUI?
Thanks: Robert
Reply
Astroland says:
Hello Robert
5.
Jim says:
February 22, 2013 at 22:43
Thanks, this looks like what I need. Im planning on using an older android phone (wifi only) as
a IP camera. I tried this setup with zoneminder but performance on the pi was very poor. Im
goning to try a few more tweaks in before I give up and try motion instead. But this is good info
and I didnt think of using boxFS.
Reply
6.
Hi astroland, thanks for the tutorial. A question: why if I contact the webcam at
http://ipwebcam:8081 I dont see the but receive a poup with do you want to save this file, or
find a program online to open it?
Thanks in advance
Reply
Astroland says:
Hi Antonio,
The Motion webserver outputs an MJPEG (Motion JPEG) video stream.
Looking at the message you get, you are using Internet Explorer which does not support
MJPEG. Therefor it asks to use a program which can display a MJPEG stream.
Firefox, Chrome, Opera and Safari support MJPEG without installing any extra programs.
On the Motion website you can find some other solutions to display a MJPEG stream if you want
7.
Rich says:
April 3, 2013 at 11:52
Thanks for the article, Astroland. Ive been trying to set Motion up on my Pi for a few weeks
now, and have got it to work initially but it invariably terminates after about 5-10 minutes. Ive
tried low resolutions, have moved the camera (Logitech C270 bought especially because it said
supported on the R-Pi compatibility list) to a powered USB hub.
The best Ive managed so far is a tiny 176144 image size (I was hoping to use at least 640480,
and the camera says it supports 1280960 at 30fps with MJPEG/MJPG pixel format) and it
stayed up for 30 minutes before crashing out with some watchdog timeout error and a nongraceful restart:
Apr 1 21:51:28 raspberrypi motion: [1] Started stream webcam server in port 8081
Apr 1 22:20:17 raspberrypi motion: [0] Thread 1 - Watchdog timeout, trying to do a graceful
restart
Apr 1 22:20:17 raspberrypi motion: [0] httpd Closing
Apr 1 22:20:17 raspberrypi motion: [0] httpd thread exit
Apr 1 22:21:17 raspberrypi motion: [0] Thread 1 - Watchdog timeout, did NOT restart
graceful,killing it!
Apr 1 22:21:17 raspberrypi motion: [0] Calling vid_close() from motion_cleanup
Apr 1 22:21:17 raspberrypi motion: [0] Closing video device /dev/video0
Any ideas how I can get this working continuously? Im using Linux raspberrypi 3.6.11+ #397
PREEMPT if thats any use, and Ive done update/upgrade?
Reply
Astroland says:
This seems to be a specific Logitech problem in combination with the Pi running Motion.
I did some googling and found on the Raspberry Pi forum users with a similar problem youre
having.
If you scroll all the way down in that thread, you can read some solutions/workarounds given by
forum users ahynes1 and johnsonfamily38.
You have to fiddle around with the palette MJPEG is using.
Dont know if it works but it is worth a try.
Reply
Rich says:
I was assuming/hoping all this would basically just work by now on Linux so its all rather
disappointing when these cameras work flawlessly at 30fps without crashes on Windows 8-(
Reply
8.
Ben says:
May 29, 2013 at 18:01
Hi Astroland, Thanks for the article. I have compiled and installed boxfs on my pi. And I am able
to mount my directory to box using
boxfs -u name@mail.com -U 1000 -G 1000 -F 644 -D 755 -v /home/motion.
The problem is that I am not able to write to /home/motion using my pi user after it is
mounted. And I can only create a new file in /home/motion as root.
drwxr-xr-x 2 motion motion 0 Jan 1 1970 motion
Any ideas? Many thanks.
Reply
Astroland says:
Hi Ben
I see your /home/motion directory has the owner motion and the group motion.
Your boxfs command line uses user id 1000 and group id 1000. These belong to the user pi.
Try to find the correct user id and group id for the user motion in /etc/passwd and use these in
the boxfs commandline.
Hope this helps.
Reply
Ben says:
Hello Astroland,
Thanks for the reply. The problem is that only the root user is only to write to the directory after
boxfs mounted. Thanks.
Reply
Astroland says:
Hi Ben
Yes, I understand your problem.
Have you tried the possible solution in my previous reply?
In your boxfs commandline you use the uid and gid of user pi while you want to write as user
motion.
Thats giving you the problem.
User root can read/write (almost) everywhere on a filesystem, so thats understandable in your
situation.
Reply
Ben says:
Hi Astroland,
Thanks and I have tried that and it is writing now. But unfortunately, I have a new issue SD
card I/o error. Cheers.
9.
Matolok says:
November 6, 2013 at 06:19
Applying UID and GID of user motion to boxfs mounting options not helping.
User motion is not even able to browse mount point.
Compiled rev 95 from SVN.
Reply
Astroland says:
10.
Matolok says:
November 7, 2013 at 03:23
11.
No Name says:
December 19, 2013 at 17:18
12.
Brian says:
December 22, 2013 at 15:09
FWIW, Im having the Exact same issues as Matolok. Ive also tried (and failed) all solutions
offered here. The only thing I notice is that when BoxFS is loaded, its root-only access.
I did a sloppy fix of just running a cronjob to move files as they appear from where motion
outputs to the boxfs directory which is working well enough. Im a fan of K.I.S.S. though, so its
slightly irritating.
Thanks for the blog entry, it has helped me.
Reply
Astroland says:
13.
Ed says:
January 2, 2014 at 14:27
any luck with Pi Noir ? I would like to stack drift-scan images with this imager.
Word has it one could use the raw format, and go beyond 10 seconds of imaging. Not sure if the
over 10sec. treshold could be used but I do not plan high magnifications anyway.
Reply
14.
awosome says:
February 5, 2014 at 13:57
Astroland says:
15.
Leave a Reply
Your email address will not be published. Required fields are marked *
Name *
Email *
Website
Comment
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b>
<blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Post Comment
44
1cf401da6d
1419421182593
Search for:
Search
Waxing Crescent
Next
Time Left: 0d 3h 8m
View Item
$599.99 (0 bids)
Buy It Now available
Time Left: 0d 5h 5m
View Item
$175.00 (0 bids)
Buy It Now available
View Item
View Item
$49.99 (0 bids)
Buy It Now available
View Item
Next
eBay affiliate tools from Auction Affiliate
Recent Posts
Introducing: ScopeHunter
Remote control your GoTo telescope mount using a Raspberry Pi and SkySafari
Recent Comments
Jose Brandao on Using the Raspberry Pi for camera surveillance using Motion and cloud storage
Sunspot AR2014 on a sunny Dutch morning | Astroland | Solar Flare 2012 on Sunspot AR2014 on a
sunny Dutch morning
Ashish Mehra on Remote control your GoTo telescope mount using a Raspberry Pi and SkySafari
Archives
June 2014
March 2014
September 2013
August 2013
April 2013
February 2013
November 2012
July 2012
Categories
Astronomy
DIY
Internet
Linux
Raspberry Pi
Astroland
Proudly powered by WordPress.