Skip to content

Instantly share code, notes, and snippets.

@miaoski
Created February 27, 2015 16:48
Show Gist options
  • Save miaoski/7638175fd1ee0989d4d4 to your computer and use it in GitHub Desktop.
Save miaoski/7638175fd1ee0989d4d4 to your computer and use it in GitHub Desktop.
picamera + PIR
# -*- coding: utf8 -*-
import RPi.GPIO as GPIO
import time
import picamera
import datetime
SENSOR = 4
CAMDIR = '/cam'
GPIO.setmode(GPIO.BCM)
GPIO.setup(SENSOR, GPIO.IN, pull_up_down=GPIO.PUD_UP)
cam = picamera.PiCamera(resolution = (640,480))
def get_file_name():
fn = datetime.datetime.now().strftime("%Y%m%d-%H%M%S.h264")
d = fn[0:8]
if not os.path.isdir(os.path.join(CAMDIR, d)):
os.mkdir(os.path.join(CAMDIR, d))
return os.path.join(CAMDIR, d, fn)
def recording(channel):
if GPIO.input(SENSOR):
fileName = get_file_name()
print 'Start recording to ' + fileName
#cam.start_preview()
cam.start_recording(fileName)
#camera.capture('foo.jpg')
else:
print 'Stop recording.'
#cam.stop_preview()
cam.stop_recording()
try:
GPIO.add_event_detect(SENSOR, GPIO.BOTH, callback=recording)
while True:
time.sleep(100)
except:
print 'Cleanup and quit.'
GPIO.cleanup()
cam.close()
raise
@miaoski
Copy link
Author

miaoski commented Feb 27, 2015

7. Camera Hardware 的說明,其實 1926x972 15-30fps 才是符合硬體規格的設定,不過就先不管了...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment