Search code examples
linuxpython-2.7pollinggpio

How to poll for GPIO interrupts in python?


I need to poll for interrupts on a GPIO pin using python 2.7, and I wonder if there are any native functions or libraries to help me do that?
When searching for anything like this I find a lot about Raspberry Pi, but that is not what I need.

Is this doable?


Solution

  • It will be greate if you post what you already tried so we can help.

    I did it like this

    while 1:
        events = po.poll(30000)
        if not events:
            print ('TIMEOUT!')
        for fd, flag in events:
            # check what's been done with os.lseek and os.read
    

    This code is based on How do I wait for interrupts in different languages? question.

    Whole code was done as a simple game for emebeded system on Raspberry PI and is available here