0

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:


#1

import cam stuff

set previewon = false

:loop

check for button1 press

if{ prevon = false

[camera.preview.start]

[prevon==true]}

else{[camera.preview.stop]

[prevon==false]}


#2

import cam stuff

declare date/timestamp layout

:loop

check for button2 press

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

1
  • 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 – Riley Scott Jacob Aug 28 '20 at 18:41
1

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.

1
  • 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! – Icyartillery Aug 27 '20 at 4:30
1

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, privacy policy and cookie policy

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