0

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...

3
  • 1
    Presumably your wiring is faulty. How is the switch connected to gpio 25? Is the same software running on both Pis?
    – joan
    Commented Apr 8, 2015 at 15:40
  • There is a button (and a 220 ohm resistor) between the 3.3V pin and the GPIO25. Yes, they run the same script. It now works if I connect both ground pins together; but I wonder if this system is possible without having to connect all the ground pins..
    – Pita
    Commented Apr 9, 2015 at 11:52
  • The ground wire is needed to complete the circuit. Current flows from one Pi to another via the gpios but it needs to find its way back.
    – joan
    Commented Apr 9, 2015 at 12:34

1 Answer 1

1

I suspect that you need to connect the ground pins of both pi's together.

1
  • This worked! Thanks!! I just wonder if there is a way to make it work without having to connect all the ground pins?
    – Pita
    Commented Apr 9, 2015 at 11:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.