0

I'm using a simple laser beam alarm circuit similar to http://2.bp.blogspot.com/-DlpGa_yyJ0Y/U ... iagram.png

I took a input from this circuit to the Pi using a 4k7 resistor instead of the buzzer and capture images when the beam get obstructed. I used the pigpio library callback function to capture images as

import pigpio
import os 
pi=pigpio.pi()
pi.set_mode(4,pigpio.INPUT)
pi.set_pull_up_down(4,pigpio.PUD_DOWN)
i=0
def capture(gpio,level,ticks):
  global i
  i=i+1
  os.system(("raspistill -o img%s.png -md 6 -t 500")%i)

callf=pi.callback(4, pigpio.RISING_EDGE, capture)
while True:
  pass

but the issue was sometimes it capture multiple images for single obstruct. I found out that debounce is a solution for this kind of situations. How to use debouncing with the pigpio library.

Hasi
  • 21
  • 1
  • 8

1 Answers1

0

My recommendation to you doesn't include an explanation of handling debounce in pigpio, as I have similar questions on that as well.

However - one way to fix your issue would be to have your interrupt callback function only do one of two quick things.

  1. Check a global flag (let's call it "ImageCaptureRequested") and if that flag is already set - do nothing in the callback but return. That would mean that a previous image capture is in progress.
  2. If the flag is not set to True, simply set it to True and return from the interrupt. That keeps your interrupt callback short and quick. The other part of the process would be to have a main loop (or thread) that watches that global flag and when it gets set, make the system call or library call to do your image capture. Once that image is saved, you can clear the global flag so your program will be ready for the next "trip" interrupt. Since the flag prevents duplicate operations in your interrupt, you should no longer get multiple image captures with one gpio change.

I hope this is helpful although I know it doesn't answer the related question of handling hardware debounce in the pigpio class library. I am looking for documentation or help on that issue myself for a project I am working on. It was easy to do in RPIO, and my guess is that it is easy in pigpio as well once someone "in the know" sheds some light on it.

Marty C

saraf
  • 530
  • 7
  • 22
Marty C
  • 16
  • 1