{"id":937,"date":"2013-02-07T18:13:39","date_gmt":"2013-02-07T18:13:39","guid":{"rendered":"https:\/\/www.phillips321.co.uk:443\/?p=937"},"modified":"2013-02-13T17:03:35","modified_gmt":"2013-02-13T17:03:35","slug":"timelapse-with-the-raspberrypi","status":"publish","type":"post","link":"https:\/\/www.phillips321.co.uk\/2013\/02\/07\/timelapse-with-the-raspberrypi\/","title":{"rendered":"Timelapse with the RaspberryPi"},"content":{"rendered":"<p>So my Raspberry Pi has been sitting in the box for about a month now while it could have been doing something more useful.<\/p>\n<p>So as I had an evening free I decided to quickly throw something together in order to use a spare webcam to take a photo every 30 or so seconds.<\/p>\n<p><a href=\"https:\/\/www.phillips321.co.uk:443\/wp-content\/uploads\/2013\/02\/fswebcam.jpg\"><img loading=\"lazy\" src=\"https:\/\/www.phillips321.co.uk:443\/wp-content\/uploads\/2013\/02\/fswebcam-150x150.jpg\" alt=\"fswebcam\" width=\"150\" height=\"150\" class=\"aligncenter size-thumbnail wp-image-939\" \/><\/a><\/p>\n<p>I had plans to put the webcam and the pi inside an old external light fitting i had but unfortunately with the SD card and USB connections poking out it didnt fit!<br \/>\nI guess if I wanted to take this further I could do with a <a href=\"https:\/\/www.modmypi.com\/raspberry-pi-micro-sd-card-adaptor\" target=\"_blank\">microSD adaper<\/a> and flipping the USB ports around (<a href=\"http:\/\/www.oliverjenkins.com\/blog\/2012\/6\/changing-usb-socket-on-raspberry-pi\" target=\"_blank\">or hooking directly into the usb<\/a>).<\/p>\n<p>From a <a href=\"http:\/\/www.raspberrypi.org\/downloads\" target=\"_blank\">standard raspbian build<\/a> all that&#8217;s needed is fswebcam.<\/p>\n<div class=\"codecolorer-container bash vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"kw2\">apt-get install<\/span> fswebcam<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>.<\/p>\n<p>And now to write the <strong>timelapse.sh<\/strong> script:<\/p>\n<div class=\"codecolorer-container bash vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"co0\">#!\/bin\/bash<\/span><br \/>\n<span class=\"kw2\">touch<\/span> <span class=\"sy0\">\/<\/span>root<span class=\"sy0\">\/<\/span>IMG-<span class=\"nu0\">0<\/span>.jpg<br \/>\n<span class=\"kw1\">while<\/span> <span class=\"kw2\">true<\/span><br \/>\n<span class=\"kw1\">do<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">sleep<\/span> <span class=\"nu0\">15<\/span><br \/>\n&nbsp; &nbsp; <span class=\"re2\">name<\/span>=IMG<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#91;<\/span><span class=\"br0\">&#91;<\/span> <span class=\"re5\">-e<\/span> <span class=\"sy0\">\/<\/span>root<span class=\"sy0\">\/<\/span><span class=\"co1\">${name}<\/span>-<span class=\"nu0\">0<\/span>.jpg <span class=\"br0\">&#93;<\/span><span class=\"br0\">&#93;<\/span> ; <span class=\"kw1\">then<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re2\">i<\/span>=<span class=\"nu0\">1<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">while<\/span> <span class=\"br0\">&#91;<\/span><span class=\"br0\">&#91;<\/span> <span class=\"re5\">-e<\/span> <span class=\"sy0\">\/<\/span>root<span class=\"sy0\">\/<\/span><span class=\"co1\">${name}<\/span>-<span class=\"co1\">${i}<\/span>.jpg <span class=\"br0\">&#93;<\/span><span class=\"br0\">&#93;<\/span> ; <span class=\"kw1\">do<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">let<\/span> i++<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">done<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re2\">name<\/span>=<span class=\"co1\">${name}<\/span>-<span class=\"co1\">${i}<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">fi<\/span><br \/>\n&nbsp; &nbsp; fswebcam <span class=\"re5\">-b<\/span> <span class=\"re5\">--log<\/span> file:<span class=\"sy0\">\/<\/span>root<span class=\"sy0\">\/<\/span>timelapse.log <span class=\"re5\">-r<\/span> 1280x720 <span class=\"re5\">-S<\/span> <span class=\"nu0\">15<\/span> <span class=\"re5\">-d<\/span> <span class=\"sy0\">\/<\/span>dev<span class=\"sy0\">\/<\/span>video0 <span class=\"re5\">--no-banner<\/span> <span class=\"sy0\">\/<\/span>root<span class=\"sy0\">\/<\/span><span class=\"co1\">${name}<\/span>.jpg<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">sleep<\/span> <span class=\"nu0\">15<\/span><br \/>\n<span class=\"kw1\">done<\/span><br \/>\n<span class=\"kw3\">exit<\/span> <span class=\"nu0\">0<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>And to ensure that it runs at boot time a simple init scrip:<\/p>\n<div class=\"codecolorer-container bash vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"co0\">#!\/bin\/sh<\/span><br \/>\n<span class=\"co0\"># \/etc\/init.d\/timelapseinit.sh<\/span><br \/>\n<span class=\"co0\"># v0.1 phillips321.co.uk<\/span><br \/>\n<span class=\"co0\">### BEGIN INIT INFO<\/span><br \/>\n<span class=\"co0\"># Provides: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;timelapseinit.sh<\/span><br \/>\n<span class=\"co0\"># Required-Start:<\/span><br \/>\n<span class=\"co0\"># Required-Stop:<\/span><br \/>\n<span class=\"co0\"># Default-Start: &nbsp; &nbsp; 2 3 4 5<\/span><br \/>\n<span class=\"co0\"># Default-Stop: &nbsp; &nbsp; &nbsp;0 1 6<\/span><br \/>\n<span class=\"co0\"># Short-Description: fswebcam from \/dev\/video0 to \/root\/IMG-n.jpg<\/span><br \/>\n<span class=\"co0\"># Description: &nbsp; &nbsp; &nbsp; Takes photo from webcam at \/dev\/video0 every 30 seconds and put the jpg at \/root\/IMG-n.jpg<\/span><br \/>\n<span class=\"co0\">### END INIT INFO<\/span><br \/>\n<br \/>\nf_message<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;[+] $1&quot;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<br \/>\n<span class=\"co0\"># Carry out specific functions when asked to by the system<\/span><br \/>\n<span class=\"kw1\">case<\/span> <span class=\"st0\">&quot;$1&quot;<\/span> <span class=\"kw1\">in<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; start<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f_message <span class=\"st0\">&quot;Starting timelapse.sh...&quot;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">\/<\/span>root<span class=\"sy0\">\/<\/span>timelapse.sh <span class=\"sy0\">&amp;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f_message <span class=\"st0\">&quot;timelapse.sh Started&quot;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">;;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; stop<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f_message <span class=\"st0\">&quot;Stopping timelapse.sh...&quot;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">killall<\/span> fswebcam<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">killall<\/span> timelapse.sh<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f_message <span class=\"st0\">&quot;timelapse.sh stopped&quot;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">;;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">*<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f_message <span class=\"st0\">&quot;Usage: $0 {start|stop|status|restart}&quot;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">exit<\/span> <span class=\"nu0\">1<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">;;<\/span><br \/>\n<span class=\"kw1\">esac<\/span><br \/>\n<span class=\"kw3\">exit<\/span> <span class=\"nu0\">0<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>And don&#8217;t forget to ensure it actually executes:<\/p>\n<div class=\"codecolorer-container bash vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"kw2\">chmod<\/span> +x <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>timelapseinit.sh<br \/>\n<span class=\"kw2\">chmod<\/span> +x <span class=\"sy0\">\/<\/span>root<span class=\"sy0\">\/<\/span>timelapse.sh<br \/>\nupdate-rc.d timelapseinit.sh defaults<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p><a href=\"https:\/\/www.phillips321.co.uk:443\/wp-content\/uploads\/2013\/02\/webcambox.jpg\"><img loading=\"lazy\" src=\"https:\/\/www.phillips321.co.uk:443\/wp-content\/uploads\/2013\/02\/webcambox-150x150.jpg\" alt=\"webcambox\" width=\"150\" height=\"150\" class=\"aligncenter size-thumbnail wp-image-945\" \/><\/a><\/p>\n<p>I&#8217;ve got plans to power this from solar power and set it up in the green house to watch some plants grow overtime. (I know that not locking the exposure\/whitebalance\/focus and so on will give me crap results&#8230;. but remember, my RaspberryPi was sat in a box along with all this kit).<\/p>\n<p>I&#8217;ll post the results in a week or so \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So my Raspberry Pi has been sitting in the box for about a month now while it could have been doing something more useful. So as I had an evening free I decided to quickly throw something together in order to use a spare webcam to take a photo every 30 or so seconds. I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":945,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[352,350,351,270,333],"_links":{"self":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/937"}],"collection":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/comments?post=937"}],"version-history":[{"count":9,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/937\/revisions"}],"predecessor-version":[{"id":985,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/937\/revisions\/985"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/media\/945"}],"wp:attachment":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/media?parent=937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/categories?post=937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/tags?post=937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}