RPi.GPIO add_event_detect()

Post Reply
SofiaRafael
Posts: 5
Joined: Fri May 31, 2019 1:53 am
languages_spoken: english
ODROIDs: ODROID C0 and C1
Has thanked: 3 times
Been thanked: 0
Contact:

RPi.GPIO add_event_detect()

Unread post by SofiaRafael » Mon Jun 03, 2019 11:48 pm

Hello,

I have been trying to implement an event_detect for one of the ODROID C1.

The error I am getting is

Code: Select all

GPIO.add_event_detect(DRDY_pin, GPIO.FALLING, callback=acquisition)
RuntimeError: Failed to add edge detection
My code snippet is like this

Code: Select all

import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)       # Numbers GPIOs by chip numbering scheme

DRDY_pin =  23   #PIN 16 of the ODROID
GPIO.setup(DRDY_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)   # Set LedPin's mode is output

def acquisition(channel):
	n = 8
 	bits = 24
 	received = spi.read(24+n*bits) # Read 24 bits status word + nrChanels*24bits
 	print received

GPIO.add_event_detect(DRDY_pin, GPIO.FALLING, callback=acquisition)

I have tried a bunch of things but so far nothing worked.
If someone can help me it would be great!

Best,
Sofia

User avatar
odroid
Site Admin
Posts: 31347
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 49 times
Been thanked: 182 times
Contact:

Re: RPi.GPIO add_event_detect()

Unread post by odroid » Tue Jun 04, 2019 10:01 am

I think the GPIO interrupt feature is missing in RPi.GPIO library while WiringPi Python wrapper has it.

joshua.yang
Posts: 229
Joined: Fri Sep 22, 2017 5:54 pm
languages_spoken: Korean, English
ODROIDs: XU4, XU4Q + Cloudshell2, H2
Has thanked: 2 times
Been thanked: 20 times
Contact:

Re: RPi.GPIO add_event_detect()

Unread post by joshua.yang » Tue Jun 04, 2019 4:15 pm

Hi.

I figured out what was wrong and have fixed, confirmed working fine with the following codes.

Code: Select all

import RPi.GPIO as GPIO

def detector(channel):
    print 'detected'

if __name__ == '__main__':
    GPIO.setwarnings(False)
    GPIO.cleanup()
    GPIO.setmode(GPIO.BCM)

    # BCM 25 == WiringPi 6 == C1 Physical 103
    io_board_btn = 25

    GPIO.setup(io_board_btn, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.add_event_detect(io_board_btn, GPIO.FALLING, callback=detector)
    
    try:
        print 'Press Ctrl-C to exit'
        while True:
            pass
    except KeyboardInterrupt:
        GPIO.cleanup()
Seems it works well.

Code: Select all

root@odroid:~# python rpi_int_test_with_io_board.py 
Press Ctrl-C to exit
detected
detected
detected
detected
detected
detected
detected
detected
detected
detected
detected
detected
detected
detected
detected
The culprits are,
- The buffer size. GPIO pin numbers of ODROID boards are, in general, starts from 100 but it isn't on Raspberry Pis. So the RPi.GPIO library doesn't consider that big number, and this causes an unexpected problem.
- Accessing legacy-old path for GPIO nodes. /sys/class/aml_gpio is no longer used.

I committed the patch to my Github repository. Please clone that and test again.
https://github.com/joshua-yang/RPi.GPIO-Odroid
These users thanked the author joshua.yang for the post:
SofiaRafael (Tue Jun 04, 2019 5:14 pm)

SofiaRafael
Posts: 5
Joined: Fri May 31, 2019 1:53 am
languages_spoken: english
ODROIDs: ODROID C0 and C1
Has thanked: 3 times
Been thanked: 0
Contact:

Re: RPi.GPIO add_event_detect()

Unread post by SofiaRafael » Tue Jun 04, 2019 5:14 pm

Thank you so very much Joshua. It works!

joshua.yang
Posts: 229
Joined: Fri Sep 22, 2017 5:54 pm
languages_spoken: Korean, English
ODROIDs: XU4, XU4Q + Cloudshell2, H2
Has thanked: 2 times
Been thanked: 20 times
Contact:

Re: RPi.GPIO add_event_detect()

Unread post by joshua.yang » Tue Jun 04, 2019 5:15 pm

SofiaRafael wrote:
Tue Jun 04, 2019 5:14 pm
Thank you so very much Joshua. It works!
Glad to hear that. :)

SofiaRafael
Posts: 5
Joined: Fri May 31, 2019 1:53 am
languages_spoken: english
ODROIDs: ODROID C0 and C1
Has thanked: 3 times
Been thanked: 0
Contact:

Re: RPi.GPIO add_event_detect()

Unread post by SofiaRafael » Wed Jun 12, 2019 4:53 am

Hello Joshua,

Do you know what is the limit for the signal frequency and after how long the signal needs to be in a different position before the event can be detected?

My exact problem is that I have a signal at 500Hz and the signal stays high for ~ 2.2us. I want to detect the falling edge but it is detected very few times.

Is this signal frequency pass the frequency the add_event_detect can reliably be used for? Do you have any suggestion for me to improve the number of times the falling edge is detected?

Thank you very much in advance,
Best,
Sofia

joshua.yang
Posts: 229
Joined: Fri Sep 22, 2017 5:54 pm
languages_spoken: Korean, English
ODROIDs: XU4, XU4Q + Cloudshell2, H2
Has thanked: 2 times
Been thanked: 20 times
Contact:

Re: RPi.GPIO add_event_detect()

Unread post by joshua.yang » Wed Jun 12, 2019 5:54 pm

SofiaRafael wrote:
Wed Jun 12, 2019 4:53 am
Hello Joshua,

Do you know what is the limit for the signal frequency and after how long the signal needs to be in a different position before the event can be detected?

My exact problem is that I have a signal at 500Hz and the signal stays high for ~ 2.2us. I want to detect the falling edge but it is detected very few times.

Is this signal frequency pass the frequency the add_event_detect can reliably be used for? Do you have any suggestion for me to improve the number of times the falling edge is detected?

Thank you very much in advance,
Best,
Sofia
Hi.

I have tested with RPi.GPIO and C1.

A function generator generates a signal at 500Hz and I double-checked that frequency with an oscilloscope to confirm its outputs.

Wrote a Python 3 script using RPi.GPIO, which checks interrupt count every 1 second. It detects falling-edge interrupts.

So,
rpigpio_c1_500hz.resized.jpg
rpigpio_c1_500hz.resized.jpg (606.13 KiB) Viewed 268 times

Well, it works well with a 500Hz signal on my end. :)
As the short test, I found that it can detect above 10 KHz with a little error range.

One thing weird I found is rising-edge and both-edge ain't work. I can write Python code using rising-edge and both-edge.

If you still have a problem, I would like to recommend you to use our WiringPi ports (with C language). Actually, RPi.GPIO isn't our official project. :)

edit) All of the 3 edge types(falling, rising, both) are working well. There was a mistake on my test code. :shock:

joshua.yang
Posts: 229
Joined: Fri Sep 22, 2017 5:54 pm
languages_spoken: Korean, English
ODROIDs: XU4, XU4Q + Cloudshell2, H2
Has thanked: 2 times
Been thanked: 20 times
Contact:

Re: RPi.GPIO add_event_detect()

Unread post by joshua.yang » Wed Jun 19, 2019 6:46 pm

I have written a Wiki page to guide for using RPi.GPIO add_event_detect().

https://wiki.odroid.com/odroid-xu4/appl ... i.gpio_irq

Post Reply

Return to “Issues”

Who is online

Users browsing this forum: No registered users and 2 guests