Notifications
Clear all

Compare IR received text with a text string. Please help!

13 Posts
3 Users
1 Likes
481 Views
(@tanuki)
Member
Joined: 11 months ago
Posts: 5
Topic starter  

Hello!Β 

I am asking for some help. It is about IR signals using ESP32 and arduino as compiler.

I need to compare the received IR signal from a remote control (e.g. 1F0030) with a text (e.g. ciao). How I can do?

The received text should be in results.value and it is correctly displayed in the serial monitor. But something like:

if (results.value == ciao) { do this and that}

does not works.

Thank you in advance πŸ™‚

Β Pierluigi

void loop() {
  if (irrecv.decode(&results)) {
    serialPrintUint64(results.value, HEX);
    Serial.println("");
    irrecv.resume();  // Receive the next value
  }
  delay(100);
}

   
Quote
Topic Tags
Ron
 Ron
(@zander)
Member
Joined: 3 years ago
Posts: 5950
 

Posted by: @tanuki

Hello!Β 

I am asking for some help. It is about IR signals using ESP32 and arduino as compiler.

I need to compare the received IR signal from a remote control (e.g. 1F0030) with a text (e.g. ciao). How I can do?

The received text should be in results.value and it is correctly displayed in the serial monitor. But something like:

if (results.value == ciao) { do this and that}

does not works.

Thank you in advance πŸ™‚

Β Pierluigi

void loop() {
  if (irrecv.decode(&results)) {
    serialPrintUint64(results.value, HEX);
    Serial.println("");
    irrecv.resume();  // Receive the next value
  }
  delay(100);
}

Β 

I don't really understand your question. Are you having a problem because you do not know how to get the data, or do you not know how to do a string comparison?

Β 

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 2 years ago
Posts: 2488
 

@tanuki

First, a quick Google seems to indicate that

irrecv.decode(&results)

has been deprecated, so the example that you copied is out of date.

Second, the value will have been read in and translated to a C string (of bytes) or a String object and you'll have to do your comparison with "ciao" in such a way as to match the data type of that result. You'll need to read the instructions or check the library to determine which data type to use.

I had a psychic girlfriend but she left me before we met.


   
ReplyQuote
Ron
 Ron
(@zander)
Member
Joined: 3 years ago
Posts: 5950
 

@tanuki There are a lot of libraries for IR, unfortunately, there is no easy way to decide which to use. I used this one HERE Β  and used it to dump the IR data I was getting from a ceiling fan remote. There are 23 example sketches, hopefully, one of them will be helpful to at least become the base of what you need.

As @will said, you need to determine the data type(s) and use the applicable comparison for each type.

BTW, this is one of the best documented libraries I have ever seen. Install the usual way from a zip file using the Sketch/Include Library/Add .ZIP library

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
(@tanuki)
Member
Joined: 11 months ago
Posts: 5
Topic starter  

@zander Hi, thanks for your answer!Β 

Basically I do not know how to compare two string.

The command

serialPrintUint64(results.value, HEX);

prints on the serial monitor a text string (from an IR signal). I would like to compare that text with another text (e.g. Hello).Β 

Thank you!

Β 


   
ReplyQuote
(@tanuki)
Member
Joined: 11 months ago
Posts: 5
Topic starter  

@will Hi thanks for your answer! The text string I receive is printed in the serial monitor byΒ 

serialPrintUint64(results.value, HEX);

but I do not know how to retrieve that string and compare it with "ciao". Thanks!


   
ReplyQuote
Ron
 Ron
(@zander)
Member
Joined: 3 years ago
Posts: 5950
 

@tanuki Have you tried to google? IIRC, it's something along the lines of strcmp( stuff ) or memcmp( stuff ) or strncmp if you want to limit the length it's all documented.

It comes up in google on the first page.

Β 

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
(@tanuki)
Member
Joined: 11 months ago
Posts: 5
Topic starter  

@zander thank you! I checked the command string, however I do not know how to call

serialPrintUint64(results.value, HEX);

inside a command like strcmp. (I use to code in matlab and i m new to c++, sorry)


   
ReplyQuote
Ron
 Ron
(@zander)
Member
Joined: 3 years ago
Posts: 5950
 

@tanuki WHAT???? I don't understand anything you are saying!!!

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 2 years ago
Posts: 2488
 

@tanukiΒ 

Since you don't provide any information, we can't really help you without making a lot of wild assumptions.

Assuming that results.value is an unsigned 64 bit integers which you have loaded with a set of ASCII characters as a C string and assuming that you don't want to compare it against the contents of the variable called ciao but you actually want to compare it to the text string "ciao" you might try something like ...

char test="ciao";

if ( strcmp(test,(char*)&results.value)==0 ) { /* do something here if they match */};

I had a psychic girlfriend but she left me before we met.


   
Tanuki reacted
ReplyQuote
Ron
 Ron
(@zander)
Member
Joined: 3 years ago
Posts: 5950
 

@tanuki Unless you post your entire code we can do nothing.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
(@tanuki)
Member
Joined: 11 months ago
Posts: 5
Topic starter  

@will Thank you very much! That is the command I was looking for! It really help πŸ™‚


   
ReplyQuote
Ron
 Ron
(@zander)
Member
Joined: 3 years ago
Posts: 5950
 

@tanuki That is what I told you earlier. Also, note that @will said 'assumptions'. His example assumes several things that can trip you up so read the documentation.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote