Just got a Fruit Jam and have been learning a lot - so many cool components wrapped into a neat little package.
One of the goodies included is an IR receiver that is available as board.IR, so I thought it might be neat to send commands to the Fruit Jam with a remote control. This is a quick look receiving input from a remote control. But this article is also a lesson on the power of the Adafruit CircuitPython community.
First, the parts for the project:
I used a couple of odd remotes I had laying around and in fact I have two remotes coded in.
The Fruit Jam Learn Guide doesn't address coding the IR receiver, but there are other guides for getting IR signals. I started with:
I copied over the libraries and copy and pasted the code, modifying it to use the CircuitPython defined input - worked like a charm!
Except... this code is blocking, meaning that it waits to receive an IR signal before other things in the while loop can proceed. But I want my Fruit Jam to do other stuff while waiting for IR signals...
A little help here...
Here's where the power of the Adafruit CircuitPython community really shines. I posted the question looking for non-blocking sample code in the #help-with-circuitpython channel in the Adafruit Discord. Within minutes I had a response directing me to the answer:
# 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 time
import board
import pulseio
import adafruit_irremote
pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True)
decoder = adafruit_irremote.NonblockingGenericDecode(pulsein)
t0 = next_heartbeat = time.monotonic()
while True:
for message in decoder.read():
print(f"t={time.monotonic() - t0:.3} New Message")
print("Heard", len(message.pulses), "Pulses:", message.pulses)
if isinstance(message, adafruit_irremote.IRMessage):
print("Decoded:", message.code)
elif isinstance(message, adafruit_irremote.NECRepeatIRMessage):
print("NEC repeat!")
elif isinstance(message, adafruit_irremote.UnparseableIRMessage):
print("Failed to decode", message.reason)
print("----------------------------")
# This heartbeat confirms that we are not blocked somewhere above.
t = time.monotonic()
if t > next_heartbeat:
print(f"t={time.monotonic() - t0:.3} Heartbeat")
next_heartbeat = t + 0.1
I also got suggestions for other approaches, such as using asyncio - I will have to play with that as well. But this worked for now.
Here is my code:
import pulseio
import adafruit_irremote
import board
remote = { # Add tuples to map codes generated from the remote
(0, 255, 10, 245): "On/Off",
(0, 255, 16, 239): "Select",
}
ir_pin = board.IR
pulsein = pulseio.PulseIn(ir_pin, maxlen=120, idle_state=True)
decoder = adafruit_irremote.NonblockingGenericDecode(pulsein)
while True:
for message in decoder.read():
if isinstance(message, adafruit_irremote.IRMessage):
print("Decoded:", message.code) # , remote[message.code])
if message.code in remote:
print("Button:", remote[message.code])
else:
print("Unknown Button")
elif isinstance(message, adafruit_irremote.NECRepeatIRMessage):
print("NEC repeat!")
pass
elif isinstance(message, adafruit_irremote.UnparseableIRMessage):
print("Failed to decode", message.reason)
print("----------------------------")
Note that you will need to map the codes from your remote and put them into the remote dictionary - run the code, press a button, copy the tuple from the REPL and paste it into the remote dictionary. So far I have mapped two different remotes and about 50 buttons into the code.
This page (Fruit Jam Remote Control & the Power of the Community) was last updated on September 21, 2025.
Text editor powered by tinymce.