jmansonphoto
Posts: 3
Joined: Mon Mar 23, 2015 10:36 am

Shutter Release trouble

Wed Mar 25, 2015 10:40 am

Hey, I am quite new to all this so please excuse me for the basic question. I'm running a camera shutter release through a button with this code

Code: Select all

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

GPIO.setup(15,GPIO.OUT)

try:
        while True:
		GPIO.output(15, GPIO.input(11) )
                
except KeyboardInterrupt:
        GPIO.cleanup()
and i want to integrate it with this code so it takes several shots with a pause when I press the button.

Code: Select all

import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BOARD)

GPIO.setup(15, GPIO.OUT)

while True:
    GPIO.output(15, True)
    sleep(0.1)
    GPIO.output(15, False)
    sleep(4)
I have attempted many mash-ups with little success. Any help would be greatly appreciated while I'm still learning python :)

User avatar
paddyg
Posts: 2555
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Shutter Release trouble

Wed Mar 25, 2015 11:21 am

something along the lines of:

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(15,GPIO.OUT)
SHOT_PAUSE = 4.0
next_shot = 0.0

try:
  while True:
    tm = time.time()
    if GPIO.input(11) and tm > next_shot:
      GPIO.output(15, True)
      sleep(0.1)
      GPIO.output(15, False)
      next_shot = tm + SHOT_PAUSE
    time.sleep(0.01)
               
except KeyboardInterrupt:
  GPIO.cleanup()
I think it's better to pull the input pin up then connect it to GND (less things can go wrong) in which case you would need a 'not' in there
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Return to “Python”