Notifications
Clear all

IR remote libray inconsisties

22 Posts
4 Users
4 Reactions
4,283 Views
VE1DX
(@ve1dx)
Member
Joined: 5 years ago
Posts: 143
Topic starter  

I am working on a generic "read and use any surplus IR remote" inspired by Bill's Youtube video. It works fine with a couple of remotes, but a couple of others (an old LG one and the one that comes with the Elegoo Robot kit) are driving me insane! I finally went back to basics and tried the "problem remotes" using Bill's first simple demo:

/*
IR Receiver Demonstration 1
IR-Rcv-Demo1.ino
Demonstrates IR codes with IR Receiver
Displays results on Serial Monitor

DroneBot Workshop 2017
http://dronebotworkshop.com
*/

// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>

// Define sensor pin
const int RECV_PIN = 2;

// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;


void setup(){
// Serial Monitor @ 9600 baud
Serial.begin(9600);
// Enable the IR Receiver
irrecv.enableIRIn();
}

void loop(){
if (irrecv.decode(&results)){
// Print Code in HEX
Serial.println(results.value, HEX);
irrecv.resume();
}
}

All this does is read and display the IR code in hex. It uses the library IRremote.h by Ken Shirriff that is recommended by the demo. Here's an example of the results it gives when successively pressing the same key:

2FB2625F
FFFFFFFF
20DFA85
FFFFFFFF
20DFA857
FFFFFFFF
20DFA857
FFFFFFFF
20DFA857
FFFFFFFF
20DFA857
FFFFFFFF
20DFA857
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
20DFA857
FFFFFFFF
20DFA857
FFFFFFFF
FFFFFFFF
20DFA857
2FB2625F
FFFFFFFF
20DFA857
FFFFFFFF
2FB2625F
FFFFFFFF

As we can see, they bounce around. We can ignore the FFFFFFFF code because that's just the repeat indication if you hole the key down too long. The problem is 20DFA857, 20DFA85 and 2FB2625F with the same key. Same sort of thing with the Elegoo remote.

I am guessing that the IRremote.h library has a defect or glitch that is causing this. I say so because it's Bill's program that's pretty simple and works fine (consistent results) with a Sony remote. I think that eliminates hardware as I first felt my IR detection module might be iffy. I think the Sony remote has removed that possibility as it is always consistent. You can press it for an hour and still get the same results for each key!

Another reason to suspect the IRremote.h library is the following warnings when it compiles:

/Users/dunphyp/Documents/Arduino/libraries/IRremote/IRremote.cpp: In function 'int MATCH(int, int)':
/Users/dunphyp/Documents/Arduino/libraries/IRremote/IRremote.cpp:58:32: warning: suggest braces around empty body in an 'else' statement [-Wempty-body]
DBG_PRINTLN(F("?; FAILED"));
^
/Users/dunphyp/Documents/Arduino/libraries/IRremote/IRremote.cpp:57:3: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
else
^~~~
/Users/dunphyp/Documents/Arduino/libraries/IRremote/IRremote.cpp:59:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
return passed;
^~~~~~
/Users/dunphyp/Documents/Arduino/libraries/IRremote/IRremote.cpp: In function 'int MATCH_MARK(int, int)':
/Users/dunphyp/Documents/Arduino/libraries/IRremote/IRremote.cpp:84:32: warning: suggest braces around empty body in an 'else' statement [-Wempty-body]
DBG_PRINTLN(F("?; FAILED"));
^
/Users/dunphyp/Documents/Arduino/libraries/IRremote/IRremote.cpp:83:3: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
else
^~~~
/Users/dunphyp/Documents/Arduino/libraries/IRremote/IRremote.cpp:85:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
return passed;
^~~~~~
/Users/dunphyp/Documents/Arduino/libraries/IRremote/IRremote.cpp: In function 'int MATCH_SPACE(int, int)':
/Users/dunphyp/Documents/Arduino/libraries/IRremote/IRremote.cpp:110:32: warning: suggest braces around empty body in an 'else' statement [-Wempty-body]
DBG_PRINTLN(F("?; FAILED"));
^
/Users/dunphyp/Documents/Arduino/libraries/IRremote/IRremote.cpp:109:3: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
else
^~~~
/Users/dunphyp/Documents/Arduino/libraries/IRremote/IRremote.cpp:111:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
return passed;
^~~~~~

All this to ask, does anyone know if there is a better IR library than the one by Ken Shirriff?  I am using the latest version of the Shirriff library, 2.2.3.

I'd like to get this sorted out because I have a neat project that works well, storing the codes to EEPROM between power cycles, Arduino resets, etc. 

Paul VE1DX


   
Quote
VE1DX
(@ve1dx)
Member
Joined: 5 years ago
Posts: 143
Topic starter  

For what it's worth, this seems limited to remotes that use the NEC codes.  They are 32-bit and Sony is 12-bit.  I tried using long int and unsigned long int variables to hold the contents of results.value temporarily before printing. It doesn't seem to make any difference, so I think it's a small defect in IRremote.h..  This may be unsolvable if the library is inconsistent in handling some models, and I also only have a limited number of remotes to try.  Oh well! 😀 

Paul VE1DX


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1136
 
Posted by: @ve1dx

does anyone know if there is a better IR library

Not for the arduino, but if you want to try your project with something like an Rpi using python then the github tompreston/python-lirc may be of interest and I have used it a couple of years ago.  


   
ReplyQuote
VE1DX
(@ve1dx)
Member
Joined: 5 years ago
Posts: 143
Topic starter  

@byron thanks for the suggestion.  I hate to abandon the Arduino approach, but I seem to be out of options.  I do have a spare Pi, so that might be the best way to proceed.  IRremote.h simply doesn't work consistently with NEC code based remotes, in my view.  I shall overcome it!  Giving up is not something I usually do.

Paul VE1DX


   
ReplyQuote
VE1DX
(@ve1dx)
Member
Joined: 5 years ago
Posts: 143
Topic starter  

Problem solved! It was hardware. The IR receiver I am using is one from an Elegoo 37-part kit and not very good.  The problem was exacerbated by my spare IR remote types. The old Sony remote works fine, but the cheaper LG and such remotes don't emit such a strong signal. You have to hold them an inch or two from the receiver for consistent codes to be picked up by the Elegoo detector. If I hold them a foot or two away (or point them a bit sideways) they miss a bit or two, which changes the code that is read and sent to the Arduino.

The IRremote.h library is fine. I suspected as much as it's been around for a decade, has had many revisions and is widely used. Apologies to Ken Shirriff and all the others who added to it on GitHub.

Paul VE1DX


   
ReplyQuote
VE1DX
(@ve1dx)
Member
Joined: 5 years ago
Posts: 143
Topic starter  

Oh, the errors on the IRremote.h compile is not an issue.  They are part of an unimplemented debugging code section that seem to not get along with the Arduino compiler.  That's documented in the IRremote.h source code.

Paul VE1DX


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1136
 

@ve1dx - oh thats good news to hear your project is back on track.  Now I can earmark a one master control to rule again when you release your project to the wide world.   What with all this corona virus crashing the stock market just when I was about to liquidate a few shares to pay for some more house improvements, I will probably have to put that project on hold soon.  Bad news for the wife who wants it all finished, good news for more time to spend on the electronics, bots et al front 😀 


   
ReplyQuote
VE1DX
(@ve1dx)
Member
Joined: 5 years ago
Posts: 143
Topic starter  

   
Squish and byron reacted
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1136
 

@ve1dx

Thats a really neat design. Quite a satisfying project I should think.  I copied the code and your fritz diagram for a very handy reference.  I will get properly into my IR project once I've finished the task of completing my bathrooms that were part of a house renovation (which will be put on hold, but I do have to finish off the bits I started).    But I'm starting off right now thinking about a design for my master IR remote that I can print out with my 3d printer.  I'll be looking at what buttons I have in my parts drawer, I'm sure I have a bunch of momentary contact buttons somewhere.   Are you thinking about putting your project into an enclosure?

Thanks for sharing, it's much appreciated. 👍 


   
ReplyQuote
VE1DX
(@ve1dx)
Member
Joined: 5 years ago
Posts: 143
Topic starter  

@byron I moved this project to a NANO from a UNO and posted all the detail here:

https://create.arduino.cc/projecthub/VE1DX/repurpose-old-remote-controls-92139f?ref=user&ref_id=1069731&offset=0

This is as good as it gets.  I don't know if it of any use to anyone, but I started the discussion here and I guess we can check this one finished.

Paul VE1DX


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1136
 

@ve1dx - that appears to be a good detailed write up and example of its use, I've bookmarked the web page you link to and I will peruse it in detail in a few weeks time.  Right now the sun is shinning and the grass needs its first cut of the year, but if we are all locked down this could prove to be a nice little project to get busy with. Thanks. 👍 


   
ReplyQuote
VE1DX
(@ve1dx)
Member
Joined: 5 years ago
Posts: 143
Topic starter  

I'll up your lockdown and raise you a "state of emergency" (which we are currently under.)  Not a lot of fun.  I don't think this project is going anywhere in terms of a PCB or the like.  It's a beginner or intermediate level at the best.  I simply wanted to close this thread and move on to something else.  Working on these things helps me keep my sanity in these bothersome times. 

I also am trying to keep a beginner level on the forum, because I, for one, can't follow much of the advanced AI topics and detailed hardware/software required to build robots to the detail the expert engineers here are doing.  The best I could do was put together the Elegoo Robot Kit.  In fact, after I got that working I stumbled across Bill's video describing exactly the same thing!  That's how I ended up on the forum. Had I found his video first, the assembly of the kit would have gone easier, but I guess I learned a lot figuring it out on my own.

No sun here!  A mixture of rain and snow leaving a coating of slush over everything.  It'll be a month before I'll need to cut any grass.  We seem to go from shovelling snow to mowing grass with little "spring" or "fall" in between.  Such is life. 😀 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2045
 
Posted by: @ve1dx

@byron I moved this project to a NANO from a UNO and posted all the detail here:

https://create.arduino.cc/projecthub/VE1DX/repurpose-old-remote-controls-92139f?ref=user&ref_id=1069731&offset=0

This is as good as it gets.  I don't know if it of any use to anyone, but I started the discussion here and I guess we can check this one finished.

Paul VE1DX

Great project.  Thank you for sharing.  I have bookmarked it for future reference.

 


   
ReplyQuote
(@chucketn)
Member
Joined: 5 years ago
Posts: 25
 

@ve1dx

I checked out the arduino.cc link. Nice work. One question, the parts list does not show what IR receiver you used.

I ordered some solderable 400 point proto boards today to build this project on.

 


   
ReplyQuote
VE1DX
(@ve1dx)
Member
Joined: 5 years ago
Posts: 143
Topic starter  

Thanks for pointing out my oversight.  I thought I had everything, but I missed the sensor.  I updated that site so it's there now. I used a KY-022 37.9KHz Infrared IR Sensor Receiver.  They are available from Amazon, but there's likely a delay because I believe they are shipped from overseas.  My original one was in one of those 37-part Elegoo sensor kits (also available on Amazon.)  I suspect these things are not that rare, and there seem to be a lot of similar ones around.  I think any IR sensor with 3 pins (Signal, Vcc, and GND) would work.

Paul VE1DX


   
chucketn reacted
ReplyQuote
Page 1 / 2