Trying to understand SimpleReceiverForHashCodes.ino

I am using the SimpleReceiverForHashCodes.ino code with older IR controllers. Tivo to be specific.

I am trying to assign a value to a variable from IrReceiver.decodedIRData.decodedRawData.

What data type will IrReceiver.decodedIRData.decodedRawData return?


#include <Arduino.h>
#define DECODE_HASH             // special decoder for all protocols
#define RAW_BUFFER_LENGTH 1000  // Especially useful for unknown and probably long protocols
//#define DEBUG                 // Activate this for lots of lovely debug output from the decoders.

#include "PinDefinitionsAndMore.h"
#include <IRremote.hpp>  // include the library

void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;  // Wait for Serial to become available. Is optimized away for some cores.

  // Just to know which program is running on my Arduino
  Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

  // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);

  Serial.println(F("Ready to receive unknown IR signals at pin " STR(IR_RECEIVE_PIN) " and decode it with hash decoder."));
}
unsigned long data;
void loop() {
  /*
     * Check if received data is available and if yes, try to decode it.
     * Decoded hash result is in IrReceiver.decodedIRData.decodedRawData
     */
  if (IrReceiver.available()) {
    IrReceiver.initDecodedIRData();  // is required, if we do not call decode();
    IrReceiver.decodeHash();
    /*
         * Print a summary of received data
         */
    // We have an unknown protocol here, print extended info
    IrReceiver.printIRResultRawFormatted(&Serial, true);
    IrReceiver.resume();  // Early enable receiving of the next IR frame

    IrReceiver.printIRResultShort(&Serial);
    Serial.println();

    
    data = IrReceiver.decodedIRData.decodedRawData;
    Serial.println(" * * * ");
    Serial.println(data);
    if (IrReceiver.decodedIRData.decodedRawData == 0x4F7BE2FB) {
      // do something
    } else if (IrReceiver.decodedIRData.decodedRawData == 0x97483BFB) {
      // do something else
    }
  }
}

A glance at the code suggests that a 32 bit unsigned integer would be suitable.

Check the library code for a definitive answer.

1 Like

Thank you jremington

This code worked:

data = IrReceiver.decodedIRData.decodedRawData;
    Serial.print(" * * * ");
    Serial.println(data);
    Serial.println(" * * * ");
    // UP 33556 RIGHT 47070  LEFT 55916  DOWN 24860
    if (data == 33556)Serial.print(" UP ");
     if (data == 24860)Serial.print(" DOWN ");
      if (data == 47070 )Serial.print(" RIGHT ");
       if (data == 55916 )Serial.print(" LEFT ");

In case someone later has the same question, please post all the code, so that they can see how you have declared the variable named "data".

1 Like

Here is the full code. I use SimpleReceiverForHashCodes.ino to debug the IR controller then the following to implement my application. I plan on building an IR controlled robot and some IR controlled decorations. I've only assigned logic for 4 buttons.

// used tsop38238 chip
#include <Arduino.h>

#define DECODE_HASH             // special decoder for all protocols
#define RAW_BUFFER_LENGTH 1000  // Especially useful for unknown and probably long protocols
//#define DEBUG                 // Activate this for lots of lovely debug output from the decoders.

#include "PinDefinitionsAndMore.h"
#include <IRremote.hpp>  // include the library

void setup() {
  Serial.begin(115200);
  while (!Serial)
  Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
// IR_RECEIVE_PIN defaults to PIN 2
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
  Serial.println(F("Ready to receive unknown IR signals at pin " STR(IR_RECEIVE_PIN) " and decode it with hash decoder."));
}
unsigned int data;
void loop() {
  if (IrReceiver.available()) {
    IrReceiver.initDecodedIRData();  // is required, if we do not call decode();
    IrReceiver.decodeHash();
    //IrReceiver.printIRResultRawFormatted(&Serial, true);
    IrReceiver.resume();  // Early enable receiving of the next IR frame

    //IrReceiver.printIRResultShort(&Serial);
    //Serial.println();

    /*
         * Finally, check the received data and perform actions according to the received command
         */
    
    data = IrReceiver.decodedIRData.decodedRawData;
    //Serial.print(" * * * ");
    //Serial.println(data);
    //Serial.println(" * * * ");
    // UP 33556 RIGHT 47070  LEFT 55916  DOWN 24860
    if (data == 33556)Serial.print(" UP ");
     if (data == 24860)Serial.print(" DOWN ");
      if (data == 47070 )Serial.print(" RIGHT ");
       if (data == 55916 )Serial.print(" LEFT ");
   // if (IrReceiver.decodedIRData.decodedRawData == 0x4F7BE2FB) {
      // do something
   // } else if (IrReceiver.decodedIRData.decodedRawData == 0x97483BFB) {
      // do something else
   // }
  }
}