beejayf
Posts: 35
Joined: Fri Aug 16, 2013 2:30 pm

Buffered Sound Detector

Fri Oct 13, 2017 5:31 pm

Hey y'all,

I have a simple sound detector on a GPIO of my RPi. Problem it's that on medium sounds it flips to 1 only very briefly so when I detect the GPIO every few ms there it's a chance the script will miss it. My PIR on the other hand buffer a detection for a few seconds and the script won't miss that.

Any simple way to do this on or for a Pi?

Thanks!

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: Buffered Sound Detector

Sat Oct 14, 2017 9:05 pm

apparently wiringPi does interrupt based GPIO. check this page out
http://wiringpi.com/reference/priority- ... d-threads/
It looks like you will be able to setup an interrupt to trigger when the pin changes state, even for,an extremely short time.

beejayf
Posts: 35
Joined: Fri Aug 16, 2013 2:30 pm

Re: Buffered Sound Detector

Sun Oct 15, 2017 5:39 pm

Thanks! That was exactly what I was looking for - even better than a soldering solution ;-)

beejayf
Posts: 35
Joined: Fri Aug 16, 2013 2:30 pm

Re: Buffered Sound Detector

Sun Oct 15, 2017 6:40 pm

works like a charm!
SNDdetected is a global variable that I check whenever there is time and the set to zero again

Code: Select all

def SNDEventHandler (pin):
    print "Sound detected"
    SNDdetected = 1

GPIO.setmode(GPIO.BOARD)
GPIO.setup(SNDpin, GPIO.IN) 

#set interrupt handler
GPIO.add_event_detect(SNDpin, GPIO.BOTH, callback=SNDEventHandler, bouncetime=2000)


Return to “Automation, sensing and robotics”