I'm trying to build a camera with the new HQ Camera module, but am running into some trouble. I don't want to have to run my little camera.py script (that just opens preview, waits, takes a photo, and closes preview) every time I want to take a picture. I'd like to solve this by adding 2 gpio buttons, #1 that toggles the camera preview on and off, and #2 that takes a picture and saves it to my designated folder. Would something like this work? Apologies for the beginner question, I get a bit ahead of my abilities on projects like this:


import cam stuff

set previewon = false


check for button1 press

if{ prevon = false






import cam stuff

declare date/timestamp layout


check for button2 press

camera.capture("to destination folder" + timestamp + ".jpg")

  • I've been working on a camera control app for the HQ for the last couple months -- github.com/RiScJ/camctrl -- see GPIOUtils::attach_interrupt in src/gpio_utils.cpp to see how I address this issue Aug 28, 2020 at 18:41

2 Answers 2


It would be possible to write a bash script but inefficient and poor practice.

Especially as you are using python just install gpiozero and use one (or several ) of the Button callbacks in your python script.

  • This looks like the answer, I looked it up and there's actually an example for exactly what I wanted, a button to turn on and off the preview and one to snap a photo, thanks a bunch! Aug 27, 2020 at 4:30

Rather that starting and stopping the Python script for every picture, you really want a long running Python program, probably set up as a Linux service that autostarts at boot time, that monitors the gpio pins your buttons are attached to with interrupts that trigger functions in your program to do exactly what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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