Skip to content

Instantly share code, notes, and snippets.

@bhive01
Created January 20, 2017 23:40
Show Gist options
  • Select an option

  • Save bhive01/e434773b29458382cf059f5c64a910d9 to your computer and use it in GitHub Desktop.

Select an option

Save bhive01/e434773b29458382cf059f5c64a910d9 to your computer and use it in GitHub Desktop.
#base packages
import os, sys
import errno
import datetime
from time import gmtime, strftime, sleep
#rPi packages
from picamera import PiCamera
import RPi.GPIO as GPIO
#setup GPIO pins
GPIO.setmode(GPIO.BCM)
GPIO.setup(12, GPIO.OUT)
GPIO.setup(4,GPIO.IN)
#setup Servo
servo=GPIO.PWM(12,50)
servo.start(2.5)
#Setup Camera
camera = PiCamera()
camera.rotation = 90
# Path to be created
# scripts current directory
basepath = sys.path[0]
# make images folder
fullpath = os.path.join(basepath, "images")
# mkdir_p function for creating path in current directory
def mkdir_p(path):
try:
os.makedirs(path)
print "Path is created."
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
print "Path exists, skipping."
else:
raise
print "Can't create path, check name."
mkdir_p(fullpath)
gpiopin4oldstate=0
try:
while True:
if GPIO.input(4)==1:
# Take IR photo at 2.5 servo position
gottime = datetime.datetime.now().strftime("%Y-%m-%d_%H%M%S.%f")
camera.start_preview()
sleep(0.5)
capturefile = gottime + '.jpg'
alllocation = os.path.join(fullpath, capturefile)
# print(alllocation)
camera.capture(alllocation)
camera.stop_preview()
#move servo
servo.ChangeDutyCycle(8.2)
#transfer image to pirgb
# delete image from piir
camera.start_preview()
sleep(2)
camera.capture('/home/pi/Desktop/RGBImage%s.jpg' % i)
i+=1
camera.stop_preview()
gpiopin4oldstate=1
if (gpiopin4oldstate==1 and GPIO.input(4)==0):
servo.ChangeDutyCycle(2.5)
gpiopin4oldstate=0
except KeyboardInterrupt:
servo.stop()
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment