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 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!
I guess if I wanted to take this further I could do with a microSD adaper and flipping the USB ports around (or hooking directly into the usb).
From a standard raspbian build all that’s needed is fswebcam.
1 | apt-get install fswebcam |
.
And now to write the timelapse.sh script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #!/bin/bash touch /root/IMG-0.jpg while true do sleep 15 name=IMG if [[ -e /root/${name}-0.jpg ]] ; then i=1 while [[ -e /root/${name}-${i}.jpg ]] ; do let i++ done name=${name}-${i} fi fswebcam -b --log file:/root/timelapse.log -r 1280x720 -S 15 -d /dev/video0 --no-banner /root/${name}.jpg sleep 15 done exit 0 |
And to ensure that it runs at boot time a simple init scrip:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #!/bin/sh # /etc/init.d/timelapseinit.sh # v0.1 phillips321.co.uk ### BEGIN INIT INFO # Provides: timelapseinit.sh # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: fswebcam from /dev/video0 to /root/IMG-n.jpg # Description: Takes photo from webcam at /dev/video0 every 30 seconds and put the jpg at /root/IMG-n.jpg ### END INIT INFO f_message(){ echo "[+] $1" } # Carry out specific functions when asked to by the system case "$1" in start) f_message "Starting timelapse.sh..." /root/timelapse.sh & f_message "timelapse.sh Started" ;; stop) f_message "Stopping timelapse.sh..." killall fswebcam killall timelapse.sh f_message "timelapse.sh stopped" ;; *) f_message "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac exit 0 |
And don’t forget to ensure it actually executes:
1 2 3 | chmod +x /etc/timelapseinit.sh chmod +x /root/timelapse.sh update-rc.d timelapseinit.sh defaults |
I’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…. but remember, my RaspberryPi was sat in a box along with all this kit).
I’ll post the results in a week or so 🙂
Leave a Reply
You must be logged in to post a comment.