0

How can I make my pi's take pictures at the same time whenever I push a button? I've connected GPIO pin 2 to my button and a ground pin to the other end of the button for every pi. This is how I've connected it.

enter image description here

These are my python codes for each Pi.

#!usr/bin/python
from gpiozero import Button
from time import sleep
from picamera import PiCamera

button = Button(2)
camera = PiCamera()

while True:
    button.wait_for_press()
    camera.start_preview()
    sleep(3)
    camera.stop_preview()
    camera.capture(‘imagex.jpg’)

What happens is, only one pi out of 5 pis are taking the picture. I'm trying to make all 5 take pictures at the same time.

  • 1
    I am confused. (1) You have 5 Rpi's. (2) You have 1 button pulled up, using 1k to 3V3, so if you push the button, output will go from High to Low (3) The button output signal is connected to each of the GPIO pins through a 470R current limiting resistor. In other words, each GPIO pin 2 is connected to one 470R, and all the 5 other ends of the 5 470Rs are shorted/connected together to the output of the push button. (4) Now if you push the button, then all 5 Rpi's GPIO pin 2's should go from High to Low at the same time, and of course all 5 cameras should shoot at the same time. – tlfong01 May 21 '20 at 11:55
  • Run a program that reacts to the button on one RPI, use MQTT to send publish a command & control message to each RPi when the button gets pressed. Each RPi with a camera has a process subscribed to the MQTT topic that waits for the command & control message and triggers the camera. Hardware setup is simpler. Each RPi runs as a self-contained unit that only has to react to the MQTT command & control messages. – Dougie May 21 '20 at 13:13
  • @tlfong01 It's working now. I was confused as well because it wasn't working as intended previously. However for some reason after moving my workspace it worked as normal as intended. All is good. Thanks. – Roger May 21 '20 at 13:41
  • How nice to hear that you solved the problem. Question: I was curious of why you would use 5 Rpi's and 5 cameras. I would instead use 5 USB HD 1080p web cameras all controlled by a single Rpi. You need to use the python multi-processing module to run the 5 camera loop functions as 5 parallel/concurrent processes. And you don't need any physical push button. You just hit a key and all 5 cameras should shoot at the same time (I think within sub milliseconds.) I am just brainstorming. I have not tried it before.Cheers. – tlfong01 May 21 '20 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.