2012-06-05

Battery powered, Wireless, Motion detecting Raspberry Pi

Hardware

Software

  • Arch Linux ARM
  • Motion
  • Lighttpd

Set up

Update Arch

Before installing any new software it's a good idea to get up-to-date. I was caught out with an issue which seems to be catching others out too - when upgrading I got this:
error: failed to commit transaction (conflicting files)
hwids: /usr/share/hwdata/pci.ids exists in filesystem
hwids: /usr/share/hwdata/usb.ids exists in filesystem
Errors occurred, no packages were upgraded.
In this case, for these two files, it's OK to rename them and try again - it seems that there's been a change of which package supplies these files and it's not handled very gracefully.
[root@alarmpi ~]# mv /usr/share/hwdata/pci.ids /usr/share/hwdata/pci.ids.save
[root@alarmpi ~]# mv /usr/share/hwdata/usb.ids /usr/share/hwdata/usb.ids.save
[root@alarmpi ~]# pacman -Syu

Wifi

I chose the ASUS USB-N10 because of its size and the fact that it works out-of-the-box with Arch. It uses the r8712u module which is already installed with the distro. Getting the wireless to work well enough is not particularly straightforward. However there are some good instructions here: ArchWiki Wireless Setup. For the wireless management software I chose netcfg and wrote a script similar to the one given under "Intermittent Connection Failure" so I had complete control over what I wanted to do whenever I lost connection to my router. This was helpful for troubleshooting and useful when you're walking around the garden trying to find a good place to put the box.

Motion

Motion is a great piece of software. Just use pacman to install it and then follow the instructions on the Motion site for setting this up. My top tip would be to edit /etc/motion/motion.conf to set up the stream and control ports and switch off webcam_localhost and control_localhost. Then run it on the console "motion -s" and use the web control to fiddle with the settings - for some changes you'll have to restart motion. Sometimes you might need a mask file. I found that taking one of the snapshots, loading it in Gimp and painting over the top was the best way to do this. You can then export the file in pgm format. At 320x240 the Raspberry Pi was quite happy to run at 5fps with motion using about 20 to 25% CPU and low memory usage (I've still got 194M free).

Lighttpd

To get at the snapshots and movies that Motion has captured it's nice to be able to grab them from a web page. I'm going to write some Python to do this nicely, but in the mean time I've set up lighttpd to present the capture directory really quickly. Simply use pacman to install it and then edit /etc/lighttpd/lighttpd.conf following the quick instructions here: Tutorial Configuration

Note: I am now uploading my videos to Google Drive rather than keeping them on the Raspberry Pi. See: Motion Google Drive Uploader and Emailer

Results

I have been consistently getting nearly 12 hours running time from the battery pack on a full charge. That gave me enough time to leave the box out all day and catch some "wildlife". Now I just need to write some software at last! (More posts on that coming soon)

53 comments:

corruptsector said...

This might be a really stupid question but after playing for ages to use wicd-curses and it keep dropping my wifi connection i want to install netcfg but dont know how to install it. Do i have to compile it first?

corruptsector said...

Sorry I should add im using a PI with Debian Squeeze. Should i just install Arch?

Cappertil said...

This is very interesting, and the battery life looks promising, but have you had much luck with larger images? I'm finding, even at 320x240, results have been a bit choppy - and 640x480 will just crash the system after a while. It is some reassurance that you're using the same camera as I am though.

I moved to raspbian to enjoy the benefit of the hard floating point - but having seen your getting 5fps I'm going to try archlinux again. Last time i tried arch, network connectivity locked up when motion was running -but i don't know if i had run rpi-update...

Out of interest, are you over clocking? I was running at 800MHz on raspbian.

Cappertil said...

By the way -do you know off hand if there's a 3G modem that will do this?

I was going to run offline... but realised i am going to need a real time clock to get meaningful timestamps.

Getting the system online could be a neat workaround... besides being a very useful thing in it's own right!

jerbly said...

@corruptsector I'm no expert at this. I use Linux a lot but this is the first time I've set up Wifi on any Linux box. I can't really comment on Debian Squeeze either, I've heard that a recent update has improved it and I am running it on my other Pi (the one serving the web site) but I've found Arch just seems to work well and is minimalist - just what you need for the little Pi. As far as netcfg goes - I read about the other options and decided that netcfg would simplify things a bit but leave me to write the "keep-alive" script. Why not get another SD card and give Arch a go - what have you got to lose?

jerbly said...

@michael hartup I tried 640x480 for a while but it was a struggle for the hardware - I certainly haven't tried it on wifi. I haven't got round to updating the firmware yet either, and no, I'm not overclocking. I've found that if you push the network too hard on wifi it gives up - one of the reasons why I wrote my own script to restart the wifi if it loses connection to the router.

Cappertil said...

Thanks for the feedback - I suppose that confirms my results for 640x480, and it wasn't just something i had done.

Anonymous said...

Jeremy, any reason you ditched the PS3 eye? Cheers, Ashley

jerbly said...

I had to give the PS3 EyeToy back to the kids! Also I wanted a higher res camera for another project.

Anonymous said...

[I had to give the PS3 EyeToy back to the kids! Also I wanted a higher res camera for another project.]

No argument there :-) just wondered because I have one on order for my pi, thanks for publishing your efforts!

Anonymous said...

Are you able to stream audio and video? Is so...how?

jerbly said...

@Anonymous - I haven't had a go at streaming Audio and Video yet. No.

jbuehl said...

This is exactly the setup that I want the Raspberry Pi to do. I have the ASUS USB-N10 and I have successfully used it on Fedora with the r8712u driver. I downloaded the archlinuxarm-29-04-2012 distribution from the rPi downloads site, but that driver isn't included. The firmware is there, but no driver. What did I do wrong?

jerbly said...

@jbuehl - Try a complete system upgrade: pacman -Syu

A lot has changed since the 29-04-2012 release.

jbuehl said...

I tried that according to what you posted above, but it failed with "error: failed to commit transaction (conflicting files)". I had previously updated some other packages related to getting the camera to work, so maybe that caused the conflict. I'm going to start over from the downloaded distro. I just wanted to confirm that 29-04-2012 was the one that you started with.

jerbly said...

@jbuehl - Yes, I started with 29-04-2012.

Anonymous said...

When I view the live webcam stream, I only see the video with the motion tracking in process, i.e. black screen attempting to identify motion. Is it possible to just view the actual live stream as a standard live stream without the motion tracking?

jerbly said...

You should see a normal stream when you're not in setup mode. Make sure you're not running: motion -s. See the getting it running page

Anonymous said...

Oops - knew I was probably doing something stupid!

Thanks.

Anonymous said...

1 other thing I meant to ask - your camera runs straight off the rpi? My logitech doesnt seem to get enough power when I run it from the rpi. The camera light doesnt come on and the terminal shows a problem opening video. Any tips on what I could try? It works 100% when I use a powered USB hub, but in doing so I am unable to create a fully wireless version like yours.

jbuehl said...

I was able to upgrade the software and now the wireless driver is loading, but it required a couple of additional steps. First, I had to upgrade pacman, and then it complained about the existence of /var/lock and /var/run, so I deleted those.

# mv /usr/share/hwdata/pci.ids /usr/share/hwdata/pci.ids.save
# mv /usr/share/hwdata/usb.ids /usr/share/hwdata/usb.ids.save
# pacman -S pacman
# rm /var/lock
# rm /var/run
# pacman -Syu

Unknown said...

Do you now why i get this error? it works but i get errors :S

Corrupt JPEG data: premature end of data segment

Kristoffer said...

Do you now why i get this error? it works but i get errors :S

Corrupt JPEG data: premature end of data segment

Anonymous said...

Please I need the file (raspberry pi-conf)

/etc/motion/motion.conf

makaco.link@gmail.com

Kotek said...

I have managed to follow your blog for RaspPi and I have motion up and running with Logitech STX Communicate at 640x480.
I even plugged my TP Link wifi card that runs Atheros 9k.

The only issue I have is the stability of WiFi link, so I am going back to wired Ethernet.

Thanks for nice tutorial :)

Anonymous said...

Have you considered something like this to power it: http://cgi.cottonpickers.plus.com/~cottonpickers/forum/viewtopic.php?f=5&t=4#p4

KEnikuv Blog said...

Hi, nice job!
I try run motion but I cannot get images greater then 352x288. more.
http://www.lavrsen.dk/foswiki/bin/view/Motion/SupportQuestion2012x07x20x193051
I try to only snap one images but there no aps for that in Arch-linux.
I found http://aur.archlinux.org/packages.php?ID=28170 but I do not know how to install.. :( pacman -S uvccapture do not work.
make DO NOT work :(

freezerburn said...

I'm interested in the battery pack, did you have to make any modifications to the cord or use any sort of converter?

jerbly said...

@freezerburn No modifications required. Just plug in and switch on!

Anonymous said...

is it possible to stream with motion live flv?

Peter Cock said...

Not sure if it would be possible using the battery approach, and I needed both the USB ports, but two webcams at once can work on the Rapsberry Pi. I used Motion under the "Raspian" distribution.

Peter Cock said...

Did you consider Power over Ethernet (PoE) for the Raspberry Pi? This seems to work OK in my limited testing so far, and means just one cable to run :)

Kevin said...

Excellent work Jeremy!

would it be possible to skip the wifi part altogether if this is running in my house and over ethernet?
would I need to do anything other than ignore that step?

thank you...

jerbly said...

@kevin just skip that bit. In fact that's the most problematic part anyway due to the USB power problem. Have fun!

Kevin said...

Brilliant thanks for the reply am on it now...love arch!

Kevin said...

Strange... Using the vx 700 which is supported and dmesg picks it up but lsusb doesn't... Works fine in windows but not on arch... /scratches head

kk said...

It's impressive! I've got a simple question about LifeCam Cinema. Does it work well in bad light? I've got hedgehog breeding and I am using old cheap Creative cam with Motion to show hedgehogs live on my website. Main activity of the animals is at night (and I don't want them to feel like it's a day - turning on strong light), so I need a camera that works well in bad light.

Peter Cock said...

Regarding low light usage for hedgehogs, I would modify the camera to make it infra-red sensitive by removing the red glass filter (example). This is done for astronomy usage too. You could then supplement this with an infra-red light source. This is also done for bird nesting boxes (example). The downside of IR is the colours don't look natural.

Front Line Assembly Computers said...

Can i combine this power pack with a solar panel for better mobility?

I am actually happy that you are so involved with the raspberry pi.

CrystalCowboy said...

Response to KEnikuv: I am also seeing the limitation to 352x288 resolution. It must be a problem with the USB camera driver, since I see the same limitation with fswebcam and mjpg-streamer. It has nothing to do with motion itself.

Roland said...

I'm currently using an NSLU2 with a Quickcam Pro 9000 running Openwrt and MJpeg Streamer and it works great as a remote internet webcam streamer. the NSLU2 is less powerful than the Raspberry Pi and I am planning on using a Pogoplug or my dockstar to replace the NSLU2 as soon as I have time (I'm planning on using it as a security webcam storing recordings. For me I think the RPi, although more powerful than the NSLU2 or Pogoplug, is a waste of CPU for just webcam duties as the GPU won't be used.. I am using my RPi as portable XBMC device instead...

A.J.Bevan said...

Jeremy, after following your instructions I too have built this system.

Picture : www.flickr.com/photos/ajbevan/7900597230/
Video : www.flickr.com/photos/ajbevan/7913993492/

Although it's running off mains electricity at the moment, it will also get it's own custom built wooden box to live in.

Regards, Adrian...

Anonymous said...

Interesting project and comments . I am disappointed to hear that the rpi struggles with a resolution greater than 320x240. I currently use scrap $20 pentium machines and can record 2Mpixel at 5fps. Anything less is useless for a security system. I was hoping to relplace the desktop boxes with rpi even though it would cost more. Now...no way.

0845 numbers said...

If you need audio, then you have to opt for a camera system having audio recording equipment wherein you not only see what happens, but can hear as well.

TinTin said...

Wow , thats neat. Adding a solar panel (like a cottonpickers panel) should be easy and keep running for days. Just need to improve picture quality now!

Anonymous said...

what about heat? I want to install in 90+ F , with high humidity environment. You think it's doable?

Chris said...

Awesome. I have my Raspberry Pi w/ that same webcam. I was wanting to use it for a security system. The HD cameras provide great quality, but using 10m extension USB cables daisy chained can only get you so far.. I was wanting to switch to ethernet, but then I thought Raspberry Pi would be a great video server, which could be read from a Security DVR and recorded.. Hopefully they get PoE working on future generations of Raspberry Pi..

Michael Horne said...

Great stuff. Thanks Jeremy.
Got this all working nicely with an XBox Live Vision camera (tiny little thing, but it does the job!)

Anonymous said...

Just for all people's info, I've noticed that the 256MB RAM version does not handle well 640x480..but 512MB versions can handle something like 1-2 frames a second at 864x480 even over WiFi.
This however comes with a 3-4 second delay. I am using the recommended Debian Wheezy and Motion and a little overclocking (~800..900MHz) with Logitech C910 or B910 USB webcams. Changing CPU/GPU RAM proportions with 256MB version did not seem to affect outcome.

jerbly said...

It's probably failing to make a pid file in /var/run - I'd check permissions.

Anonymous said...

I just got this working with a Microsoft HD-5001 camera using Motion, 640x480 @ 5fps. Using the new v2 Pi.

I would like to monitor the performance of the Pi so I can tweak the Motion settings and find the sweet spot. How would I do that exactly?

(Linux noob here, so please be kind...)

Ryan said...

Beautiful :) Thanks for sharing.

Anonymous said...

то же самое я выжимал из роутера tp link 3020 с той же камерой. распберру тут использовать явно нет смысла