CPX, CircuitPython, and IR Remote Glitchiness

Play with it! Please tell us which board you're using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
gallaugher
 
Posts: 267
Joined: Tue Aug 14, 2018 12:42 pm

CPX, CircuitPython, and IR Remote Glitchiness

Post by gallaugher »

Hi,
I've been able to build a two-wheeled bot using an Adafruit chassis, CPX, Crickit, and CircuitPython (3.0.3 - crickit version of circuit python installed + latest libraries), and I've been able to use a tiny Elegoo remote that I had lying around (similar form factor to NEC mini that Adafruit sells, but with different key codes).
I was able to use Adafruit tutorials to map out the codes for the buttons on my remote, and I was able to link responses of these button presses with CircuitPython motor code so that I have a working forward, backward, right, left, and stop.
It seems that during normal presses on my IR remote I'm getting several errors (pasted below - oddly the repeated codes show up when I have NOT pressed the same button again). It doesn't seem to be related to distance or line-of-sight issues. So the bot works, but it often times seems to require multiple presses before a successful button registers without a Repeated Code Error or Memory Error (I have print statements in my code to show when these occur, although, curiously the repeated code errors are not showing the actual key pressed).
The modified code I'm using is at:
https://github.com/gallaugher/CPX_Crick ... er/code.py

Advice is appreciated. Thanks!
John
---
Decoded: [255, 0, 157, 98]
NEC Infrared code received: [255, 0, 157, 98]
Go Forward!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 157, 98]
Go Forward!
Decoded: [255, 0, 253, 2]
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Decoded: [255, 0, 87, 168]
NEC Infrared code received: [255, 0, 87, 168]
Go Backward!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 87, 168]
Go Backward!
Decoded: [255, 0, 253, 2]
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Failed to decode: ('10 pulses minimum',)
Decoded: [255, 0, 61, 194]
NEC Infrared code received: [255, 0, 61, 194]
Turn Right!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 61, 194]
Turn Right!
Failed to decode: ('Both even/odd pulses differ',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 61, 194]
Turn Right!
Decoded: [255, 0, 253, 2]
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Decoded: [255, 0, 221, 34]
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Decoded: [255, 0, 253, 2]
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Memory error: ('memory allocation failed, allocating 256 bytes',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Memory error: ('memory allocation failed, allocating 256 bytes',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Decoded: [255, 0, 61, 194]
NEC Infrared code received: [255, 0, 61, 194]
Turn Right!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 61, 194]
Turn Right!
Decoded: [255, 0, 253, 2]
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Memory error: ('memory allocation failed, allocating 256 bytes',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Memory error: ('memory allocation failed, allocating 256 bytes',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Decoded: [255, 0, 221, 34]
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Memory error: ('memory allocation failed, allocating 256 bytes',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Memory error: ('memory allocation failed, allocating 256 bytes',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Memory error: ('memory allocation failed, allocating 256 bytes',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Memory error: ('memory allocation failed, allocating 256 bytes',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Memory error: ('memory allocation failed, allocating 256 bytes',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Memory error: ('memory allocation failed, allocating 256 bytes',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Memory error: ('memory allocation failed, allocating 256 bytes',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Memory error: ('memory allocation failed, allocating 256 bytes',)
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 221, 34]
Turn Left!
Decoded: [255, 0, 253, 2]
NEC Infrared code received: [255, 0, 253, 2]
Stop!
Repeated Code Error: ()
NEC Infrared code received: [255, 0, 253, 2]
Stop!

User avatar
kevinjwalters
 
Posts: 1025
Joined: Sun Oct 01, 2017 3:15 pm

Re: CPX, CircuitPython, and IR Remote Glitchiness

Post by kevinjwalters »

I noticed an issue with multiple presses when decoding some IR on CPX in CircuitPython, I noted it in #16, have a look and comment on that if it's the same problem. I worked around it with my own implementation, see my_read_pulses() in ir-decode-to-python.py.

Re-reading my code it looks like I had memory issues too with learning a full set of remote IR codes so I experimented with deleting variables and removing some string concatentation.

User avatar
gallaugher
 
Posts: 267
Joined: Tue Aug 14, 2018 12:42 pm

Re: CPX, CircuitPython, and IR Remote Glitchiness

Post by gallaugher »

Hi Kevin,
Thanks for the reply. Your code might solve my problem. I've had to table the robot project for a few days, but hope to get back to it in a week. I'll be sure to let you know if this solves things. Very kind of you to share.
Cheers,
John

User avatar
kevinjwalters
 
Posts: 1025
Joined: Sun Oct 01, 2017 3:15 pm

Re: CPX, CircuitPython, and IR Remote Glitchiness

Post by kevinjwalters »

At line 60 you can add del pulses to allow the memory used by that to be reclaimed. You could also achieve same thing with variable scope by placing the python code to get the command,received_code in a function.

User avatar
mpc823
 
Posts: 66
Joined: Thu May 05, 2016 9:10 am

Re: CPX, CircuitPython, and IR Remote Glitchiness

Post by mpc823 »

Kevin,

Just wanted to say thanks for the pointer to your modified IR code. I was having the same issues with the IR hanging and needing a timeout. For controlling a robot, I need to have a non-blocking IR detection and was getting stuck looking for pulses, just as you were. Your timeout helped. Hope some kind of update happens to the main library to fix this issue.

Daniel

User avatar
kevinjwalters
 
Posts: 1025
Joined: Sun Oct 01, 2017 3:15 pm

Re: CPX, CircuitPython, and IR Remote Glitchiness

Post by kevinjwalters »

That's good news, it took me a while to work out what was going on so I'm glad the investment has paid off.

On the memory front, there's an interesting discussion going on over at viewtopic.php?f=48&t=141158&start=15#p700923 about "frozen" libraries and how a user can use more memory by unintentionally duplicating them.

User avatar
kevinjwalters
 
Posts: 1025
Joined: Sun Oct 01, 2017 3:15 pm

Re: CPX, CircuitPython, and IR Remote Glitchiness

Post by kevinjwalters »

I've not had time to look at the changes but it's possible this is fixed by improve read_pulses/blocking reliability #18.

User avatar
gallaugher
 
Posts: 267
Joined: Tue Aug 14, 2018 12:42 pm

Re: CPX, CircuitPython, and IR Remote Glitchiness

Post by gallaugher »

Thanks - it seems updating the libraries mostly fixed the problem. It behaves a lot more reliably now.
I've updated my code at:
https://github.com/gallaugher/CPX_Crick ... er/code.py

Feel free to suggest if there are problems or issues that should be polished. If not, I'll likely update some things & post as a tutorial. Thanks for offering the fixes!
John

Locked
Please be positive and constructive with your questions and comments.

Return to “Circuit Playground Classic, Circuit Playground Express, Circuit Playground Bluefruit”