adafruit / Adafruit_CircuitPython_IRRemote

CircuitPython drivers for IR remote send and receive
MIT License
28 stars 34 forks source link

Mini Remote Control: No signal sent is valid? #52

Closed eat-sleep-code closed 2 years ago

eat-sleep-code commented 3 years ago

@tannewt

I am tinkering with parts from an old AdaBox -- a Circuit Playground Express and Mini Remote Control [Product ID: 389].

I installed CircuitPython 6.3.0 on the Circuit Playground Express. I also created a lib folder on the CPE and dropped the adafruit_irremote.mpy from Bundle for Version 6.x in it.

I then placed this code into a code.py file on it:

import board
import pulseio
import adafruit_irremote

pulseIn = pulseio.PulseIn(board.IR_RX, maxlen=120, idle_state=True)
decoder = adafruit_irremote.GenericDecode()

print("start")

while True:
    pulses = decoder.read_pulses(pulseIn)
    try:
        received = decoder.decode_bits(pulses)
    except adafruit_irremote.IRNECRepeatException:
        print("Repeat Exception")
        continue
    except adafruit_irremote.IRDecodeException:
        print("Decode Exception")
        continue
    except Exception as ex:
        print("General Exception", ex)
        continue

    print("Code received", received)

When I press the UP button (shown here pressed several times), this is the output.

General Exception IRMessage(pulses=(6366, 251, 181, 241, 175, 191, 511, 249, 177, 273, 179, 214, 181, 271, 176, 2323, 175, 245, 181), reason='Pulses do not differ') General Exception IRMessage(pulses=(179, 242, 174, 247, 179, 269, 178, 299, 179), reason='Too short') General Exception IRMessage(pulses=(172,), reason='Too short') Code received None General Exception IRMessage(pulses=(178,), reason='Too short') General Exception IRMessage(pulses=(179, 240, 176, 276, 197, 253, 205, 274, 179, 272, 175, 474, 181, 270, 177, 245, 181, 297, 311, 281, 181, 269, 178, 242, 174, 280, 178, 245, 182), reason='Pulses do not differ') General Exception IRMessage(pulses=(174,), reason='Too short') General Exception IRMessage(pulses=(179, 270, 177, 299, 179, 243, 172, 222, 173, 1685, 178, 724, 181, 1114, 176, 359, 182, 831, 178, 272, 175, 840, 206, 327, 177), reason='Only mark & space handled')

Not once did I appear to receive a valid code.

I am not sure what is incorrect with my code -- for the most part it is pretty close to the example provided on the IR Test with Remote page.

eat-sleep-code commented 3 years ago

I tried simplifying, with this code...

while True: 
    decoder = adafruit_irremote.NonblockingGenericDecode(pulseIn)
    for message in decoder.read():
        if isinstance(message, adafruit_irremote.IRMessage):
            print(message.code)
        else:
            try:
                print(message, len(pulseIn))
            except:
                print(message)

And all I get is this kind of output:

IIRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 6 IRMessage(pulses=(61219,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 0 IRMessage(pulses=(65535,), reason='Too short') 3 IRMessage(pulses=(65535,), reason='Too short') 3 IRMessage(pulses=(65535,), reason='Too short') 3 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 3 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1 IRMessage(pulses=(65535,), reason='Too short') 1

I tried with not only the Adafruit Mini Remote as well as the remote of my cable box, as well as the remote for a small video projector. All three appear to have the same experience, with no pulses over 6 in length and a majority just being 1 pulse long.

Looking at the code, it is expecting a minimum of 10 pulses. Which does not appear to ever happen with any of these remotes.

eat-sleep-code commented 3 years ago

Ok, I had a second CPX that is running CircuitPython 3.x :-)

I placed this code in it...

import board
import pulseio
import adafruit_irremote

pulseIn = pulseio.PulseIn(board.IR_RX, maxlen=120, idle_state=True)
decoder = adafruit_irremote.GenericDecode()

print("start")

while True:
    pulses = decoder.read_pulses(pulseIn)
    try:
        received = decoder.decode_bits(pulses)
    except Exception as ex:
        continue

    print("Code received", received)

And I get this when pressing up, down, left, right, up, down, left, and right:

start Code received [255, 2, 95, 160] Code received [255, 2, 79, 176] Code received [255, 2, 239, 16] Code received [255, 2, 175, 80] Code received [255, 2, 95, 160] Code received [255, 2, 79, 176] Code received [255, 2, 239, 16] Code received [255, 2, 175, 80]

This is very consistent. So it appears this works on an ancient version of CircuitPython, but not the current version. It appears, that in the last 2 or 3 years some change has borked the functionality of this library.

eat-sleep-code commented 3 years ago

Tried going to CircuitPython 7.0-RC1 but that opened up a whole other problem that I will raise after getting this working in 6.x.

tannewt commented 3 years ago

Thanks for filing an issue for this! I'm going to move it to the core repo since it seems dependent on CP version.

DavePutz commented 3 years ago

I tested the last script on CP 7.0.0-rc.1 and it worked correctly - no errors.

eat-sleep-code commented 3 years ago

@DavePutz On 7.0.0-rc.1 I am getting a weird blink seqence on the Circuit Playground Express. Yellow flash of all the Neopixels and then two red flashes of all the neopixels, a pause and repeat of the red flashes.

tannewt commented 3 years ago

@eat-sleep-code Those are the new status blinks for 7. The yellow flashes are the wait for safe mode on start up. The double red flashes indicate that the code.py ended due to an exception. The exception backtrace will show on the serial output.

eat-sleep-code commented 3 years ago

@tannewt @DavePutz I ran the second two code samples on 7.0 RC-1 and see the same behavior I saw on 6.x. It does not detect valid button presses like it use to in Circuit Python 3.x

Screenshot 2021-09-09 20:46:39 boot_out.txt

dhalbert commented 3 years ago

I am moving this to the 7.x.x milestone since the bug was already present in 6.3.0.

eat-sleep-code commented 2 years ago

This is still not resolved as of 7.1.0-beta.3

dhalbert commented 2 years ago

I tried this with 3.x, 4.x, 5.x, and 6.x, and the last adafruit_irremote in each of the corresponding bundles.

The 5.x bundle adafruit_irremote (version 4.0.2 of the library) works with CircuitPython 6.3.0. The 4.1.1 version of the library fails with 6.3.0.

... AND, @lstein just fixed this yesterday with https://github.com/adafruit/Adafruit_CircuitPython_IRRemote/pull/51, which I didn't see until just now. Moving this issue back to the library.

dhalbert commented 2 years ago

@eat-sleep-code please try the latest 4.1.3 library version as of a few minutes ago: https://github.com/adafruit/Adafruit_CircuitPython_IRRemote/releases/latest

dhalbert commented 2 years ago

Are you still using the Mini Remote Control? I don't have one: I tested it with a similar inexpensive remote control I got in an Arduino clone parts kit years ago.

DavePutz commented 2 years ago

I ran the provided test script using : Adafruit CircuitPython 7.2.0 on 2022-02-24; Adafruit CircuitPlayground Express with samd21g18 and the adafruit_irremote.mpy from the adafruit-circuitpython-bundle-7.x-mpy-20220304.zip I get consistently good results - Here is the output from pressing up 3 times and down 3 times on an Adafruit Mini Remote (Product ID: 389)

start Code received (255, 2, 79, 176) Code received (255, 2, 79, 176) Code received (255, 2, 79, 176) Code received (255, 2, 95, 160) Code received (255, 2, 95, 160) Code received (255, 2, 95, 160)

@eat-sleep-code - is it possible that you have some infrared interference in your environment? I ask because when I was doing pulsein for the RP2040 I often saw stray pulses coming in; and when I moved the setup to a different room they went away.