1
+ #! /bin/sh
2
+
3
+ # Timelapse script, because timelapse options in raspistill don't power
4
+ # down the camera between captures. Script also provides a camera busy LED
5
+ # (v2 cameras don't include one) and a system halt button.
6
+ # 'gpio' command requires WiringPi: sudo apt-get install wiringpi
7
+ # Limitations: if DEST is FAT32 filesystem, max of 65535 files in directory;
8
+ # if DEST is ext4 filesystem, may have performance issues above 10K files.
9
+ # For intervals <2 sec, better just to use raspistill's timelapse feature.
10
+
11
+ # Configurable stuff...
12
+ INTERVAL=15 # Time between captures, in seconds
13
+ WIDTH=1280 # Image width in pixels
14
+ HEIGHT=720 # Image height in pixels
15
+ QUALITY=51 # JPEG image quality (0-100)
16
+ DEST=/boot/timelapse # Destination directory (MUST NOT CONTAIN NUMBERS)
17
+ PREFIX=img # Image prefix (MUST NOT CONTAIN NUMBERS)
18
+ HALT=21 # Halt button GPIO pin (other end to GND)
19
+ LED=5 # Status LED pin (v2 Pi cam lacks built-in LED)
20
+ prevtime=0 # Time of last capture (0 = do 1st image immediately)
21
+
22
+ gpio -g mode $HALT up # Initialize GPIO states
23
+ gpio -g mode $LED out
24
+ mkdir -p $DEST # Create destination directory (if not present)
25
+
26
+ # Find index of last image (if any) in directory, start at this + 1
27
+ FRAME=$(( $(find $DEST - name "* .jpg" - printf % f\\n | sed 's/ ^[^1 - 9 ]*// g' | sort - rn | head - 1 | sed 's/ [^0 - 9 ]// g') + 1 ))
28
+
29
+ while : # Forever
30
+ do
31
+ while : # Until next image capture time
32
+ do
33
+ currenttime=$( date +%s)
34
+ if [ $(( $currenttime - $prevtime )) -ge $INTERVAL ]; then
35
+ break # Time for next image cap
36
+ fi
37
+ # Check for halt button -- hold >= 2 sec
38
+ while [ $( gpio -g read $HALT ) -eq 0 ]; do
39
+ if [ $(( $(date +% s)- currenttime)) -ge 2 ]; then
40
+ gpio -g write $LED 1
41
+ shutdown -h now
42
+ fi
43
+ done
44
+ done
45
+
46
+ OUTFILE=` printf " $DEST /$PREFIX %05d.jpg" $FRAME `
47
+ # echo $OUTFILE
48
+ gpio -g write $LED 1
49
+ raspistill -n -w $WIDTH -h $HEIGHT -q $QUALITY -th none -t 250 -o $OUTFILE
50
+ gpio -g write $LED 0
51
+ FRAME=$(( $FRAME + 1 )) # Increment image counter
52
+ prevtime=$currenttime # Save image cap time
53
+ done
0 commit comments