I am building a network of Raspberry Pis, and want a lot of Raspberrys to take a picture after receiving a Trigger Signal. I want to send this Trigger Signal via a GPIO Pin. It sounds simple, and I have looked at many posts, but I just can't get it to work properly!
Here is the code:
#!/usr/bin/python
import RPi.GPIO as GPIO
import socket
import time
import picamera
# PiCamera Setup
camera = picamera.PiCamera()
camera.ISO = 100
flip = input("Is de camera ondersteboven? (1=Ja, 0=Nee) ")
if flip == 1:
camera.hflip = True
camera.vflip = True
image_num = 1
ready = 1
# GPIO Setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(25, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, 0)
# Begin Loop
try:
while True:
if ready == 1:
print ""
print "Ready to press button.."
ready = 0
if GPIO.input(23):
strImage = str(image_num)
camera.capture('TEST' + strImage + '.jpg')
print('input van 23, Button pressed, Picture taken!')
ready = 1
image_num += 1
time.sleep(3)
if GPIO.input(25):
print('input van 25, stuur signaal op 18')
GPIO.output(18, 1)
time.sleep(1)
GPIO.output(18, 0)
time.sleep(1)
except KeyboardInterrupt: # trap a CTRL+C keyboard interrupt
GPIO.cleanup() # resets all GPIO ports used by this program
I use the same script on both Raspberrys. I connected Pin 18 (of RPi1) to Pin 23 (of RPi2). And I connected pin 25 (of RPi1) to a switch. The idea is that i want to trigger pin 25 of RPi1, and this triggers Pin 18 of RPi1, what will give the signal to Pin 25 of RP2, what will trigger the camera (haha, hope that it is not too confusing!).
Right now, the Pin 25 reads a constant High and keeps on taking pictures, unless I disconnect the wire. But i just want the signal from Pin 18 to be high when the button is pressed.
Please help guys, I just can't find the mistake in the set-up or code...