Skip to content

Instantly share code, notes, and snippets.

@pojda
Created March 18, 2020 14:50
Show Gist options
  • Save pojda/a3385687c6728f4cdda130bb126f2754 to your computer and use it in GitHub Desktop.
Save pojda/a3385687c6728f4cdda130bb126f2754 to your computer and use it in GitHub Desktop.
Code for capturing time lapse images with a raspberry pi. It only saves one file at a time, so it should be scheduled in cron.
from time import sleep
from datetime import datetime
import picamera
now = datetime.now()
filename = now.strftime('%Y-%m-%d_%H-%M-%S-%f')
# Camera settings depending of daylight
sunrise = range(6,7,1)
daylight = range(7,16,1)
dawn = range(16,19,1)
camera = picamera.PiCamera()
#camera.resolution = (1280, 720)
# Camera warm-up time
sleep(3)
# Common settings
camera.exposure_mode = 'off'
g = camera.awb_gains
camera.awb_mode = 'off'
camera.awb_gains = g
if now.hour in daylight:
#it's day
camera.iso = 150
camera.sensor_mode = 2
elif now.hour in dawn or now.hour in sunrise:
# set to medium iso
camera.iso = 400
#camera.framerate = Fraction(1,6)
camera.sensor_mode = 2
#camera.shutter_speed = 6000000
else:
# It's night
camera.iso = 800
camera.framerate = Fraction(1,6)
camera.sensor_mode = 3
camera.shutter_speed = 6000000
camera.capture('/home/pi/projects/time-lapse/img%s.jpg' % filename)
camera.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment