element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Event Listeners do not work (PiFace 2) with Python3
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 14 replies
  • Subscribers 665 subscribers
  • Views 1989 views
  • Users 0 members are here
  • pi
  • raspberry_pi
  • event
  • listener
  • piface
Related

Event Listeners do not work (PiFace 2) with Python3

Former Member
Former Member over 10 years ago

Hi,

 

I have tried multiple examples of using interrupts on the Pi with PiFace 2 board including the ones from the the documentation site.

 

None work. No apparent errors but the interrupts just don't fire. Polling or writing directly to the ports still works fine.

 

Keyboard Interrupt is detected.

 

Anyone know why this is happening and even better, how I could tell what is happening ?

 

Thanks

Mark

  • Sign in to reply
  • Cancel
  • clem57
    0 clem57 over 10 years ago

    Have you tried Python 2 as well?

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to clem57

    Hi Clem,

     

    It appears to be exactly the same. No errors but listeners just don't trigger.

     

    I tried my own program, the sample from the pifacedigitalio documentation and a variety of other interrupts programs that I found on Google.

     

    Very frustrating image

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 10 years ago in reply to Former Member

    Can you post code to see if there may be any apparent problem?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to clem57

    Hi Clem,

     

    One of the examples I tried.....I also typed in the example on the pifacedigitalio docs page.

     

    Mark

     

     

    from time import sleep

    import pifacedigitalio

     

    DELAY = 0.5  # seconds

    pfd = pifacedigitalio.PiFaceDigital() # creates a PiFace Digtal object

     

    def switch_pressed(event):

        print "Hello"

        pfd.leds[0].value = 1

       

    def switch_unpressed(event):

        print "Bebop"

        pfd.leds.leds[1].value = 1

     

    listener = pifacedigitalio.InputEventListener(chip=pfd)

    for i in range(4):

        listener.register(i, pifacedigitalio.IODIR_ON, switch_pressed)

        listener.register(i, pifacedigitalio.IODIR_OFF, switch_unpressed)

    listener.activate()

     

    try:

        while True:     #check program is still running by flashing led 3

            pfd.leds[2].toggle()     # toggle third LED

            sleep(DELAY)

     

     

    except KeyboardInterrupt:

        print "Closing Down....Ctrl+C"

        listener.deactivate()

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 10 years ago in reply to Former Member

    from time import sleep
    import pifacedigitalio
    pifacedigital = pifacedigitalio.PiFaceDigital()
    PushOver('Doorbell','Started','')
    print 'Doorbell Server Started\r'
    
    listener = pifacedigitalio.InputEventListener(chip=pifacedigital)
    listener.register(1, pifacedigitalio.IODIR_OFF, door_open)
    listener.register(1, pifacedigitalio.IODIR_ON, door_closed)
    listener.register(4, pifacedigitalio.IODIR_ON, switch_pressed)
    listener.register(4, pifacedigitalio.IODIR_OFF, switch_unpressed)
    listener.activate()
    while True:
        sleep(3600)    # or any very long time
    def door_open(event):
        print "Hello"
        pfd.leds[0].value = 1
      
    def door_closed(event):
        print "Bebop"
        pfd.leds[0].value = 0
    def switch_pressed(event):
        print "Hello2"
        pfd.leds[1].value = 1
      
    def switch_unpressed(event):
        print "Bebop2"
        pfd.leds[1].value = 0

    Try this please,

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to clem57

    Hi Clem,

     

    Cut and pasted your example and tried it. Same as before in that the events did not trigger.

     

    One odd thing though is that the code needed modified to work. I assume it was for python2 given the statements but I had to move the function definitions above the listener statements to get it to compile. Is that what you would have expected ?

     

    I'm using the python 2 (or 3) that comes setup when you log in to the pi from the NOOB's SD card.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 10 years ago in reply to Former Member

    Sorry I misplaced them. I am left to conclude there is hardware issue underlying the problem(s).

    clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to clem57

    Hi Clem,

     

    I noticed while trawling Google that others have experienced this too. I suspect that there is some software update that has disabled it.

     

    I've ordered an Arduino for my project as at least there will be no ambiguity about what is currently running. Not a great solution but it might actually prove easier for my son to do as he was really struggling with all the ancillary stuff you need to know to use Raspbian.

     

    Thanks for your help.

     

    Regards

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 10 years ago in reply to Former Member

    Please look through this: http://www.element14.com/community/message/133136/l/piface-digital-2--setup-and-use#133136

    Maybe a setup step was missed...

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to clem57

    Has anyone found a resolution to this problem yet?

     

    I had some code working fine earlier in the year but now it no longer works.

    The listener just does not seem to be activated.

    The piface works well using a while loop but I really want to use the listener for my project.

     

    I have been through and reinstalled everything as per the docs above but no luck.

    I code snippet given above does not work for me either.

     

    Really hope someone can help with this.

    Cheers

    Phil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube