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

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

2
  • Thanks, I will give a try to pigpio
    – B.Ondrej
    Sep 22 at 14:15
  • Confirming the pigpio works as expected in terms of events caching
    – B.Ondrej
    Sep 22 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.