edsulst
Posts: 28
Joined: Sat Nov 16, 2019 7:39 am

Push button to make picture

Sat Nov 16, 2019 1:49 pm

Hi there,

I have a Raspberry PI 3B with an USB webcam attached.
With the fwebcam command I can take a photo and store in in a folder.

Now I want to use a push button to make a photo with the fswebcam command.
I've made a takepic.py script: (adapted from a script I found on the internet)
(There is some code to turn a led on and off, but I've chosen not to use an led, so that piece code can be deleted.
Also, the original script added a photo with a number. I want to overwrite the photo, so don't make use of the image_num +1)

Code: Select all

#!/usr/bin/env python

import sys, os, time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD) 
GPIO.setup(11, GPIO.IN)     # push button (pin 11)
GPIO.setup(12, GPIO.OUT)    # led (pin 12)

image_num = 1

GPIO.output(12, False)

while True:
	if GPIO.input(11):  # button is pushed
		strImage = str(image_num)
                "fswebcam --no-banner /var/www/html/webcam.jpg"
		image_num = image_num + 1
	        GPIO.output(12, True)    # led ON
	        time.sleep(3)
	        GPIO.output(12, False)   # led OFF

GPIO.cleanup()

Also I've made an createpic.sh script and placed this into /etc/rc.local

Code: Select all

#! /bin/bash
python /home/pi/takepic.py &
I'v connected 3 wires to the push button.
1 wire go's to the GROUND on PIN6
1 wire go's to PIN11 (signal)
1 wire with a 10K resistor go's to the 3.3V on PIN1

Whatever I try, the script will not take a picture of the webcam.
Can anyone see what I'm doing wrong here ?

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Push button to make picture

Sun Nov 17, 2019 10:52 am

please don't double post.

I have answered in you original thread. https://www.raspberrypi.org/forums/view ... 2&t=256959
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

edsulst
Posts: 28
Joined: Sat Nov 16, 2019 7:39 am

Re: Push button to make picture

Sun Nov 17, 2019 12:31 pm

Sorry, I wasn't aware I dubble post this question.
I will look at the other post.

Return to “Python”