Professional Documents
Culture Documents
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
From : http://www.bluemoonblog.co.uk/
I’m planning to do some high altitude photography with my Raspberry Pi, webcam, and GPS
soon. (but that’s 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.
I’m using Raspbian Wheezy Distro (2013-02-09), so if you’re 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 we’ll get started.
Download and run rpi-update as described here. This will update your image to include the
initially-missing UVC support. Reboot as suggested.
There are a few things to keep in mind, the webcam must be connected before powering up the
Raspberry Pi. If not you need to run sudo rmmod uvcvideo and sudo modprobe uvcvideo before
it will work.
Hopefully this how-to helps you out and if you have more luck than I using a mouse and/or
higher resolutions please let me know in the comments.
Related Posts
Zemanta
Raspberry Pi – Webcam streaming 54
This entry was posted in Raspberry Pi and tagged C270 Creative fswebcam HowTo
Now it’s 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
Note: Since some kernel updates, it’s required to boot the system with a kernel
parameter that lets the webcam work again instead of taking just black pictures. Thanks
to WebS1821 for this precious insight!
fswebcam:
fswebcam is the simplest and easiest way to have your webcam capture single
frames, also programmatically at a specified timer interval. Of course it’s also
possible to call fswebcam from a bash script anytime it’s required, but this is
another story.
To install fswebcam simply run:
One of the nice features of fswebcam is that it’s 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
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:
It comes with a plain web configuration interface, but first of all we need to specify
which port motion will run on. Let’s 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, it’s 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 it’s 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 it’s 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:
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 couldn’t find a binary version of mjpeg-
streamer 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:
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
$ export LD_LIBRARY_PATH=.
$ ./mjpg_streamer -i './input_uvc.so -d /dev/video0 -r 640x480 -f 15' -o './output_http.so -w ./www
-p 8080'
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
It’s 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
Skip to content
Home
About Astroland
Astro Gear
Astro Photography
Astro Weather
ScopeHunter
If you are looking for a cheap camera surveillance setup, the Raspberry Pi is a great solution.
It is small, easy to install and, most important, has low energy usage.
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 it’s too
bloated and too CPU heavy for the Raspberry Pi.
Motion is more lightweight and doesn’t stress the CPU too much when processing 320×200
camera data.
With 2 IP camera’s 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
Besides some libraries from the Raspbian repository, you’ll also need libapp and libjson.
Get the latest commits from boxfs2, libapp and libjson:
git clone https://github.com/drotiro/boxfs2.git
git clone https://github.com/drotiro/libapp.git
git clone https://github.com/vincenthz/libjson.git
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.
Open an editor and the configuration file would look something like this:
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 I’m 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:
Forgetting this will cause mounting to fail with this error message:
fuse: failed to exec fusermount: Permission denied
boxfs -f .boxfs/boxfs.cfg
The first time you run boxfs, you will need to complete the authentication (oauth2) process and
grant access to your box.com account. It’s easy, just follow the instructions on the terminal and
on your browser.
When the mount is successful, set the right permissions with the command chmod -r 755
<mountpoint>.
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.
Be sure that your camera’s and/or webcams output a 320×200 (or 240) image and Motion is
configured with the same resolution.
I’ve tried a resolution like 640×400 pixels, but the CPU load went sky high on the RasPi, so I’ve
settled for a lower resolution.
The images generated by my camera’s are quite clear and useful, so I’m 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
When you’ve 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 you’re on holiday for example, and want to know what’s 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 (that’s 2 decent IP camera’s and a RasPi) you’re all set to go.
This entry was posted in Raspberry Pi and tagged cloud storage, motion detection, raspberry pi. Bookmark the
permalink.
← The Registax 6 initialize error
Lichtvervuiling in Utrecht →
1. Visperas says:
Thanks
Reply
2. Astroland says:
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 you’re about to leave the house you call a bookmarked webpage on your smartphone to
start motion detection.
Reply
Reply
Shotca says:
February 20, 2013 at 23:23
Reply
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 I’m asking you:
How can you access the mounted boxfs directory on vnc without root permissions on GUI?
Thanks: Robert
Reply
Astroland says:
January 22, 2013 at 21:51
Hello Robert
Why don’t you connect using ssh?
I don’t understand why you should connect a directory using a remote desktop utility.
Reply
5. Jim says:
Thanks, this looks like what I need. I’m 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. I’m
goning to try a few more tweaks in before I give up and try motion instead. But this is good info
and I didn’t think of using boxFS.
Reply
Hi astroland, thanks for the tutorial. A question: why if I contact the webcam at
http://ipwebcam:8081 I don’t 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:
March 26, 2013 at 09:53
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
to stick with Internet Explorer:
http://www.lavrsen.dk/foswiki/bin/view/Motion/WebcamServer
Reply
Reply
7. Rich says:
Thanks for the article, Astroland. I’ve 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. I’ve
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 I’ve managed so far is a tiny 176×144 image size (I was hoping to use at least 640×480,
and the camera says it supports 1280×960 at 30fps with MJPEG/MJPG ‘pixel format’) and it
stayed up for 30 minutes before crashing out with some watchdog timeout error and a non-
graceful 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? I’m using ‘Linux raspberrypi 3.6.11+ #397
PREEMPT’ if that’s any use, and I’ve done update/upgrade?
Reply
Astroland says:
April 3, 2013 at 19:41
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 you’re
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.
Don’t know if it works but it is worth a try.
Reply
Rich says:
April 9, 2013 at 16:04
My camera won’t work with motion if I pick MJPEG as the palette so I’m using YUYV at the
moment. To hack it to work at the moment I’m using 320×240 resolution with about 2 frames a
second if I’m lucky.
Reply
8. Ben says:
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:
May 30, 2013 at 11:31
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:
May 30, 2013 at 17:48
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:
May 30, 2013 at 19:32
Hi Ben
Reply
Ben says:
June 4, 2013 at 14:57
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:
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:
November 6, 2013 at 16:55
Reply
as root:
drwxr-xr-x 2 root root 4096 Aug 19 14:38 mnt
drwxr-xr-x 2 motion motion 8 Dec 31 1969 motion
drwxr-xr-x 5 root root 4096 Oct 4 22:32 opt
as user motion ( had to give him /bin/sh instead of /bin/false in order to test ):
drwxr-xr-x 2 root root 4096 Aug 19 14:38 mnt
d????????? ? ? ? ? ? motion
drwxr-xr-x 5 root root 4096 Oct 4 22:32 opt
Reply
https://github.com/drotiro/boxfs2
It not longer uses the old and depreciated v1 openbox api
Reply
FWIW, I’m having the Exact same issues as Matolok. I’ve also tried (and failed) all solutions
offered here. The only thing I notice is that when BoxFS is loaded, it’s 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. I’m a fan of K.I.S.S. though, so it’s
slightly irritating.
Reply
Astroland says:
December 24, 2013 at 16:52
Reply
13. Ed says:
Reply
Reply
Astroland says:
February 6, 2014 at 14:13
Reply
Reply
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 0
1cf401da6d
1419421182593
Search for:
Search
Waxing Crescent
Latest Image of the Sun
Next »
$14.00 (0 bids)
Buy It Now available
Time Left: 0d 3h 8m
View Item »
LARGE CELESTRON BYERS WORM GEAR DRIVE TELESCOPE& STAND
$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 »
$60.00 (0 bids)
Buy It Now available
View Item »
Vintage Criterion Paper Telescope Spy Glass Spyglass Or…
$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.