element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 PiFace input delays
  • 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 Suggested Answer
  • Replies 18 replies
  • Answers 1 answer
  • Subscribers 667 subscribers
  • Views 2539 views
  • Users 0 members are here
  • rasberry_pi_3_b_plus
  • raspberry_pi
Related

PiFace input delays

jmac67
jmac67 over 6 years ago

I have a PiFace on a RaspberryPi, and it works great, but there is a several second delay between when the input switches to when the script responds. Can someone tell me where to find/change this delay time? Thanks, Jim

  • Sign in to reply
  • Cancel
  • Jan Cumps
    0 Jan Cumps over 6 years ago

    How are you talking to the PiFACE? I'm using C++ and the effect is almost instant.

    Here is my code: SCPI on a Linux Board - Part 2b: PiFace Digital C++ programming

     

    Edit: here's an example that supports interrupts to react real time on input changes: https://github.com/piface/libpifacedigital/blob/master/example.c

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • jmac67
    0 jmac67 over 6 years ago in reply to Jan Cumps

    I'm using a Python script to run a simple routine when an input triggers, but the delay that I don't want, makes it not work for what I need it to do. I'm not very good at this programming, but I don't see anything that would cause it to have this lag. Thanks, Jim McNamee

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 6 years ago in reply to jmac67

    Ah. I have no experience with Python script.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 6 years ago

    Hi Jim,

     

    Unfortunately there's not enough information to help in a good way. If you could share your code it will help (ideally using syntax highlighting as shown here: How to Ask Questions using the Create Discussion tool   because Python uses spaces, and it will come out as a mess to the reader unless monospaced).

    Also, if you can explain what the code is to be used for, there may be a better solution based on context. For instance, if you're trying to activate (say) a camera shutter for capturing a balloon burst, then that requires a very different solution than activating a camera or alarm on intruder detection (this is just an example).

    Without seeing your code, it is not possible to tell if there is a deliberate or resolvable delay that can be changed in the code (and if the minimal delay will be sufficient for your needs), or if a different solution is needed.

    Right now it is not possible to tell if you need a script to execute and perform the unknown response within 10msec, or 1msec, or less.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • jomoenginer
    0 jomoenginer over 6 years ago

    There are multiple PiFace products, so which PiFace device are you using?  

     

    I've used multiple PiFace devices in a previous project that used Python and I don't remember any unnecessary delays when talking to the boards, even from a remote system using a web browser interface.

     

    If possible, post the code you are using either an attachment or pasted in the syntax highlighting option.

     

    It is possible that there is something else going on with your config, so you may want to check the output of the 'dmesg' command to see if there are any conflicts with the PiFace device.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • jmac67
    0 jmac67 over 6 years ago in reply to jomoenginer

    What I have made is a Mirror Prop for a haunted house. It is a two-way mirror in a picture frame, with a flat panel LCD mounted behind the glass. There is a photo eye running a 12VDC relay triggering an input on the PiFace Digital2 IO Board on a Raspberry Pi. It shows a blackscreen JPEG until the eye is read, then it plays an audio clip and a scary image is then displayed on the monitor. The way it is now, if the person doesn't stand in front of the mirror for 2-3 seconds, it does nothing. I've checked the eye and relay, and know they are basically instantaneous in triggering. I will post the PYTHON code below. I don't know this language well, and used stuff I found on various websites for what I have.

     

    import pifacedigitalio

    pifacedigitalio.init()

    import pygame.sys

    pygame.init()

    pygame.mixer.init()

    pygame.mixer.music.load("/media/inhale_scream2.mp3")

    screen=pygame.display.set_mode((1280,1024),pygame.NOFRAME)

    images=[]

    images.append(pygame.image.load("media/BLACKSCREEN.jpg"))

    images.append(pygame.image.load("media/creepyclown3.jpg"))

    show=0

    screen.blit(images[show], (0,0))

    pygame.display.update()

    pygame.time.delay(1)

     

    while True:

         input_state0 = pifacedigitalio.digital_read(0)

         input_state3 = pifacedigitalio.digital_read(3)

         input_slate2 = pifacedigitalio.digital_read(2)

         if input_state0==1:

              pifacedigitalio.digital_write(0,1)

              pygame.mixer.music.play()

              show=(show+1) % len(images)

              screen.blit(images[show], (0,0))

              pygame.display.update()

              while pygame.mixer.music.get_busy()==True:

                   continue

         else :

              pygame.time.delay(5750)

              show= % len(images)

              screen.blit(images[0], (0,0))

              pygame.display.update()

              pifacedigitalio.digital_write(0,0)

     

         if input_state2==1:

              pygame.quit()

              sys.exit()

     

         if input_state3==1:

              pygame.quit()

              sys.exit()

         pygame.time.delay(10)

         show=0

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 6 years ago in reply to jmac67

    it looks that your while loop is introducing the delay. the code is not interface driven.

     

    You are running the loop and polling the status of the input. my bet is that reading the 3 input states is very fast. the rest of your loop, including 5 second delay,waiting for the audio mixer to complete, drawing, ..., hold up the loop.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • jmac67
    0 jmac67 over 6 years ago in reply to Jan Cumps

    What would be a better way of polling the input for state change, and react when it goes high? I used this code from someone else's project for making a slideshow, and the input was to trigger the next image, then found the audio file info elsewhere and put it all together. I figured this wasn't the best way of doing this, but I'm not a programmer by trade, just an electronic tech/industrial electrician. This is hobby for me, building haunted house props. I usually use small PLCs or Arduinos, but I wanted to be able to work with video, so thought the Raspberry Pi would be good for this, but there's a lot to getting it ready to even function, especially when adding the PiFace.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • jomoenginer
    0 jomoenginer over 6 years ago in reply to jmac67

    When you post code, please use the ">>" insert symbol at the top of the edit screen, select Syntax Highlighting and select the language you are posting, or just Plan if unsure. 

     

    Uh, so you are not that familiar with Python and found some code on the web and just pasted it into your code hoping it works without issue and then blame the PiFace Digital2 IO Board? Okay.

     

    Looking at the code, in the else block you have "show= % len(images)".   Are you missing a (show+{num}) before the "%" cause I am not sure what it does otherwise since you are running the modulo on nothing.

     

    Also, your "pygame.time.delay(5750)" delay is like a 5sec delay, so if there is no input on pin 0 of the PiFace the loop will pause for 5 seconds before it does anything else.  Is that expected?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 6 years ago in reply to jmac67

    I think this is the peace of code that makes everything slow (if the image loading is fast and nhale_scream2.mp3 is a short sound):

     

    pygame.time.delay(5750)

    As long as the button is not pressed, the program repeats pausing for 5+ seconds.

     

    (I think your code may also miss some key presses because you have to have the luck to have the key down just when the pifacedigitalio.digital_read() is executed)

     

    In your state ==0 part, Instead of pausing, you could use a variable that is increased every loop (declare the variable in the start of your code, update it with one just after your delay(10) at the loop end)..

    Remove the delay(5750) line

    I expect that a loop without your 5750 delay line would take approx 10 ms, because there's a loop delay of that time at the end.

    Once that  variable has reached 575 or more, execute the code in the else part, and reset the counter to 0.

    Also reset the counter to 0 in the part where the state == 1. That will reset the timer after someone pressed a button.

    • 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