Skip to content

PulseIn seems to be holding back data until displaced by further data, resulting in unpredictable behaviour #10586

Open

Description

@SuperThunder

CircuitPython version and board name

CircuitPython 9.2.8 on Pi Pico RP2040 with adafruit_irremote 5.0.5
A basic IR receiver module is connected to GND, 3v3, and a data pin

same behaviour:
10 beta 2 on Feather RP2040
10 beta 2 on WeAct STM32F411CEU6

Code/REPL

print("code.py")

import board,time
import pulseio,adafruit_irremote

# Maxlen is set high to mitigate a separate hard fault issue encountered, Adafruit_CircuitPython_IRRemote issue #76
pulsein = pulseio.PulseIn(board.D4, maxlen=600, idle_state=True)
decoder = adafruit_irremote.NonblockingGenericDecode(pulsein)
    
def main():
    while True:
        for message in decoder.read():
            if isinstance(message, adafruit_irremote.IRMessage):
                code = message.code
                print("Decoded:", code)
            elif isinstance(message, adafruit_irremote.NECRepeatIRMessage):
                print("NEC repeat!")
            elif isinstance(message, adafruit_irremote.UnparseableIRMessage):
                print("Failed to decode", message.reason)
            
            print("pulsein rem: ", len(pulsein))
        

if __name__ == "__main__":
    main()

Behavior

Following issues are while using the adafruit_irremote library but I believe it's caused by pulseio based on report here I believe is happening because of pulseio

Issue 1: Last NEC repeat code is "held back" until next button press and displaces that button press (the next button press after the late repeat will be correct)

Issue 2: Pressing a button multiple times without repeat seems to cause a duplicate to be inserted. For example if you press 5 5 8 8 9 9 on the remote with then CircuitPython outputs 5 5 5 8 8 9

Description

Here's why I think it's to do with pulseio:

  • len(pulsein) is 0 after each NEC repeat, including the last one.
  • It seems like a subsequent PR [to the irremote lib] means _unparsed_pulses to be fully cleared out each time so there won't be any unparsed pulses there
  • There is clearly some form of extra data/state being held until more pulses arrive but the above 2 showing as empty makes me believe it must be coming from a user inaccessible part of PulseIo

Additional information

  • I used a logic analyzer to verify the pulses being sent to the board match what's being pressed on the remote
  • Willing to do more testing but not sure what else would test PulseIn in the same way. Maybe a really slow UART stream?

Activity

  1. added this to the 10.x.x milestone on Aug 27, 2025
  2. modified the milestones: 10.x.x, 11.0.0 on Sep 28, 2026
  3. self-assigned this
    on Nov 5, 2026
  4. mikeysklar commented on Nov 9, 2026

    @mikeysklar
    Collaborator

    I could not reproduce this on a Metro RP2040 with 11.0.0-alpha.2.

    D5 sent NEC frames and repeat codes over a jumper to PulseIn on D6, and I read PulseIn 150 ms after each burst.

    Burst Runs Last pulse arrived
    NEC frame, including 5 5 8 8 9 9 16 16/16
    NEC repeat 20 20/20

    No pulse was held back and no frame was duplicated.

    The RP2 PulseIn code has not changed since this was reported, so the problem may be in the irremote decoder rather than PulseIn.

    Each burst after the first starts with 65535, which is the idle time before the first edge, and the decoder has to handle that.

    @SuperThunder could you print the raw pulses from PulseIn when it happens, so we can see whether the data is already there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions