Introduction¶
CircuitPython driver for use with IR Receivers.
Examples of products to use this library with:
Dependencies¶
This driver depends on:
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.
Installing from PyPI¶
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:
pip3 install adafruit-circuitpython-irremote
To install system-wide (this may be required in some cases):
sudo pip3 install adafruit-circuitpython-irremote
To install in a virtual environment in your current project:
mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install adafruit-circuitpython-irremote
Usage Example¶
# 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()
while True:
pulses = decoder.read_pulses(pulsein)
print("Heard", len(pulses), "Pulses:", pulses)
try:
code = decoder.decode_bits(pulses)
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("----------------------------")
Contributing¶
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Documentation¶
For information on building library documentation, please check out this guide.
Table of Contents¶
Simple test¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
# 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()
while True:
pulses = decoder.read_pulses(pulsein)
print("Heard", len(pulses), "Pulses:", pulses)
try:
code = decoder.decode_bits(pulses)
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("----------------------------")
|
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()
while True:
pulses = decoder.read_pulses(pulsein)
print("Heard", len(pulses), "Pulses:", pulses)
try:
code = decoder.decode_bits(pulses)
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:
- Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: https://github.com/adafruit/circuitpython/releases
-
exception
adafruit_irremote.
FailedToDecode
[source]¶ Raised by decode_bits. Error argument is UnparseableIRMessage
-
class
adafruit_irremote.
GenericDecode
[source]¶ Generic decoding of infrared signals
-
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, *, debug=False)[source]¶ Generic infrared transmit class that handles encoding.
Parameters: -
transmit
(pulseout, data, *, repeat=0, delay=0, nbits=None)[source]¶ Transmit the
data
using thepulseout
.Parameters: - pulseout (pulseio.PulseOut) – PulseOut to transmit on
- data (bytearray) – Data to transmit
- repeat (int) – Number of additional retransmissions of the data, default 0
- delay (float) – Delay between any retransmissions, default 0
- nbits (int) – Optional number of bits to send, useful to send fewer bits than in the data bytes
-
-
class
adafruit_irremote.
IRMessage
(pulses, code)¶ Pulses and the code they were parsed into
-
code
¶ Alias for field number 1
-
pulses
¶ Alias for field number 0
-
-
class
adafruit_irremote.
NECRepeatIRMessage
(pulses)¶ Pulses interpreted as an NEC repeat code
-
pulses
¶ Alias for field number 0
-
-
class
adafruit_irremote.
NonblockingGenericDecode
(pulses, max_pulse=10000)[source]¶ Decode pulses into bytes in a non-blocking fashion.
Parameters: >>> pulses = PulseIn(...) >>> decoder = NonblockingGenericDecoder(pulses) >>> for message in decoder.read(): ... if isinstace(message, IRMessage): ... message.code # TA-DA! Do something with this in your application. ... else: ... # message is either NECRepeatIRMessage or ... # UnparseableIRMessage. You may decide to ignore it, raise ... # an error, or log the issue to a file. If you raise or log, ... # it may be helpful to include message.pulses in the error message. ... ...
-
adafruit_irremote.
UnparseableIRMessage
¶ Pulses and the reason that they could not be parsed into a code
alias of
adafruit_irremote.IRMessage