How do you wait for rising edge with python?

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
maxmike001
 
Posts: 4
Joined: Mon Mar 03, 2014 6:25 pm

How do you wait for rising edge with python?

Post by maxmike001 »

I can use pwm out and adc works, but I cannot use the following - it just reports "not detected" when I feed a 2.5V 1 KHz pwm into the pin;
I tried other pins as well. I am running a vanilla version of Linux 3.8 Angstrom, with just TTYO1 enabled. I removed the pwm and just
used a simple DC toggle, and same problem.

Code: Select all

#!/usr/bin/python

import sys
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P9_12", GPIO.IN)
GPIO.add_event_detect("P9_12", GPIO.RISING)
print "starting test"
if GPIO.event_detected("P9_12"):
	print "rising edge detected"
else:
	print "not detected"
Last edited by maxmike001 on Tue Mar 04, 2014 1:34 pm, edited 1 time in total.

User avatar
akamediasystem
 
Posts: 79
Joined: Tue Apr 30, 2013 1:38 pm

Re: Can't detect edge with python

Post by akamediasystem »

I might be reading this wrong, but isn't your code only running once?

The example doesn't make it too clear, but I think to poll regularly you should do something like the following:

Code: Select all

#!/usr/bin/python

import sys
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P9_12", GPIO.IN)
GPIO.add_event_detect("P9_12", GPIO.RISING)
print "starting test"
while True:
    if GPIO.event_detected("P9_12"):
       print "rising edge detected" 
    else:
       print "not detected"
Unfortunately my BBB is in the middle of something and I can't test this myself. I'll try to remember to test tomorrow if you haven't already had a chance to do so...

Hope this helps,

AKA

User avatar
maxmike001
 
Posts: 4
Joined: Mon Mar 03, 2014 6:25 pm

Re: Can't detect edge with python

Post by maxmike001 »

Thanks AKA - I solved it - what I needed was wait_for_edge; didn't realize it was there for the taking.

Locked
Please be positive and constructive with your questions and comments.

Return to “Beagle Bone & Adafruit Beagle Bone products”