A physical button to take photos

S.L.P. image questions, stereoscopic video livestream and recording, stereoscopic photo capture etc.
Post Reply
stereomaton
Posts: 45
Joined: Tue May 21, 2019 12:33 pm
Location: France

A physical button to take photos

Post by stereomaton » Tue Jun 25, 2019 12:08 pm

Today I had another small time to play with stereopi.
I decided to add a physical button on it to take photographs.

The idea is simple : A script launched at startup waits for the button and than call the SLP "make_photo" page as if we pressed the icon on the web interface. (Need SLP with such photo icon in the interface, I use version 0.2.3)

To do so, I added a script in /opt/StereoPi/scripts/button.py (which does the job mentionned) and stated it in /opt/StereoPi/run.sh with "./scripts/button.py &".
Here is the script if you want to reproduce:

Code: Select all

#!/usr/bin/env python

# Configuration
button = 3

# Imports
import RPi.GPIO as GPIO
from time import sleep
from urllib2 import urlopen

# Setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Wait button loop
while True:
  GPIO.wait_for_edge(button, GPIO.FALLING)
  print "Shoot!"
  urlopen('http://localhost/make_photo.php')
  sleep(0.5)
Simple, but effective.
Stereophotographer and hacker
StereoPi Standard Edition + CM3Lite module

User avatar
Realizator
Site Admin
Posts: 182
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: A physical button to take photos

Post by Realizator » Wed Jun 26, 2019 10:55 am

Stereomaton, thank you for your code!
By the way, this 1.44 TFT screen has 3 buttons and 4-position joystick embedded. And all these goodies are connected to GPIOS. I will try to implement your code to one of the buttons!
Eugene a.k.a. Realizator

stereomaton
Posts: 45
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: A physical button to take photos

Post by stereomaton » Sat Jun 29, 2019 10:19 am

Forgot to mention:
The button in my example is GPIO n°3 as noted in the pinout of the wiki: GPIO03 (SCL1, I2C)
Image

I chose this one because there is a GND pin very close, but it can be anything else not already used (just change the number at the top of script). I let the full configuration in code even if this particular pin seems to already have a pull-up in hardware (according to the library which complains) because you may want another pin without hardware pull-up.
Stereophotographer and hacker
StereoPi Standard Edition + CM3Lite module

Alik
Posts: 1
Joined: Sun Aug 18, 2019 12:07 pm

Re: A physical button to take photos

Post by Alik » Sun Aug 18, 2019 12:18 pm

Great idea, but I don't understand how to get it to work!
I did everything as described. But I can't take photos. May be I don't understand what "button" is.
I have shorted the:
GPIO03 (SCL1, I2C) and GND
GPIO03 (SCL1, I2C) and 3,3v

I have insert "./scripts/button.py &" in this place:

./scripts/loop-ws.sh &
./scripts/button.py &

cd ./skybox-server
./skybox-server.js &
cd ..


Nothing works. What did I miss? Can you help me?

Post Reply