adafruit_irremote

Demo code for Circuit Playground Express:

# Circuit Playground Express Demo Code
# Adjust the pulseio 'board.PIN' if using something else
import pulseio
import board
import adafruit_irremote
pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True)
decoder = adafruit_irremote.GenericDecode()

# size must match what you are decoding! for NEC use 4
received_code = bytearray(4)

while True:
    pulses = decoder.read_pulses(pulsein)
    print("Heard", len(pulses), "Pulses:", pulses)
    try:
        code = decoder.decode_bits(pulses, debug=False)
        print("Decoded:", code)
    except adafruit_irremote.IRNECRepeatException:  # unusual short code!
        print("NEC repeat!")
    except adafruit_irremote.IRDecodeException as e:     # failed to decode
        print("Failed to decode: ", e.args)

    print("----------------------------")
  • Author(s): Scott Shawcroft

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_irremote.GenericDecode[source]

Generic decoding of infrared signals

bin_data(pulses)[source]

Compute bins of pulse lengths where pulses are +-25% of the average.

Parameters:pulses (list) – Input pulse lengths
decode_bits(pulses, debug=False)[source]

Decode the pulses into bits.

read_pulses(input_pulses, *, max_pulse=10000, blocking=True, pulse_window=0.1, blocking_delay=0.1)[source]

Read out a burst of pulses until pulses stop for a specified period (pulse_window), pruning pulses after a pulse longer than max_pulse.

Parameters:
  • input_pulses (PulseIn) – Object to read pulses from
  • max_pulse (int) – Pulse duration to end a burst
  • blocking (bool) – If True, will block until pulses found. If False, will return None if no pulses. Defaults to True for backwards compatibility
  • pulse_window (float) – pulses are collected for this period of time
  • blocking_delay (float) – delay between pulse checks when blocking
class adafruit_irremote.GenericTransmit(header, one, zero, trail)[source]

Generic infrared transmit class that handles encoding.

transmit(pulseout, data)[source]

Transmit the data using the pulseout.

Parameters:
exception adafruit_irremote.IRDecodeException[source]

Generic decode exception

exception adafruit_irremote.IRNECRepeatException[source]

Exception when a NEC repeat is decoded