Notifications
Clear all

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

13 Posts
3 Users
1 Likes
713 Views
(@tanuki)
Member
Joined: 1 year 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)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6964
 

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?

Β 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2527
 

@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.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6964
 

@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

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@tanuki)
Member
Joined: 1 year 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: 1 year 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)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6964
 

@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.

Β 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@tanuki)
Member
Joined: 1 year 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)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6964
 

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

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2527
 

@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 */};

Anything seems possible when you don't know what you're talking about.


   
Tanuki reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6964
 

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

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@tanuki)
Member
Joined: 1 year 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)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6964
 

@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.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote