Skip to content

Instantly share code, notes, and snippets.

@isann
Last active June 26, 2018 08:15
Show Gist options
  • Save isann/cb00bb7bc9876c9601b0bd869fc92cfd to your computer and use it in GitHub Desktop.
Save isann/cb00bb7bc9876c9601b0bd869fc92cfd to your computer and use it in GitHub Desktop.
Raspberry Pi3 でカメラと赤外線センサーであそぶ ref: https://qiita.com/isann_tech/items/778a8fc71a5c57bff72d
raspistill -o /tmp/image.jpg
VCC → Raspberry Pi 4番ピン の 5V
OUT → Raspberry Pi 12番ピンの PWMO(18)
GND → Raspberry Pi 6番ピンの GND
sudo apt-get install python-picamera
import pycamera
# -*- coding: utf-8 -*-
# 2016/12/20 0:51
import traceback
from functools import wraps
import time
import RPi.GPIO as GPIO
import picamera
__author__ = 'isann'
def wrapper(func):
@wraps(func)
def _func(*args, **keywords):
try:
func(*args, **keywords)
except Exception:
traceback.print_exc()
return _func
@wrapper
def main():
sensor_pin = 18
sleeptime = 5
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor_pin, GPIO.IN)
cam = picamera.PiCamera()
cam.resolution = (384, 288)
try:
print "App Start"
print "ctrl+c : if you want to stop app"
while True:
if (GPIO.input(sensor_pin) == GPIO.HIGH):
print('shot!!!!')
filename = time.strftime('%Y%m%d%H%M%S') + '.jpg'
save_file = '/tmp' + '/' + filename
cam.capture(save_file)
time.sleep(sleeptime)
print('wait...')
else:
time.sleep(1)
except KeyboardInterrupt:
print "Quit"
finally:
print "clean up"
GPIO.cleanup()
if __name__ in '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment