0

How many callback events is cached in add_event_detect function? In my example below start_thread is executed just twice, but it is fired up five times (by the loop). To me it looks, that GPIO library is not able to hold more than 2 callback requests. or have i missed anything?

import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
start_thread_id = 1
_gpin = 10
i = 0
def start_thread(channel):
 global start_thread_id
 print("_***** F: start_thread called")
 for i in range(0, 5):
 print("doing job for thread #{}:".format(start_thread_id))
 time.sleep(0.3)
 start_thread_id += 1
 return
GPIO.setup(
 _gpin,
 GPIO.IN,
 pull_up_down=GPIO.PUD_UP
 )
GPIO.add_event_detect(
 _gpin, GPIO.RISING,
 callback=start_thread,
 bouncetime=5
 )
while True:
 if i <= 5:
 print("_gpin change #{}".format(i))
 GPIO.setup(_gpin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
 time.sleep(.1)
 GPIO.setup(_gpin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 else:
 time.sleep(40)
 break
 i += 1
goldilocks
60.4k17 gold badges117 silver badges236 bronze badges
asked Sep 22, 2021 at 12:58

1 Answer 1

1

I have no reason to doubt that your tests are correct for the RPi.GPIO Python module.

If you need to have more events queued you could use the pigpio Python module. It will queue up hundreds of events.

pigpio callbacks

answered Sep 22, 2021 at 13:37
2
  • Thanks, I will give a try to pigpio Commented Sep 22, 2021 at 14:15
  • Confirming the pigpio works as expected in terms of events caching Commented Sep 22, 2021 at 15:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.