using irRemote from other library

Hi all,

Background of the project:

I want to control some lego power function devices by arduino via infrared, but I want to replace both, sender and receiver, with arduino and custom protocol to allow more accurate steering and to have more outputs available.

For better re-usability I thought of creating a receiver library which is doing the protocol handling, etc. but is implementing the library irRemote for doing the IR part.

But here comes my problem, which I do not understand: If i call irRemote from another library, i get only garbage as result from irRemote. If I call the same code from the ino the results are fine.

So, hopefully somebody can explain me where my problem is:

code which is working (using irRemote directly from ino)
ino file

#include "Arduino.h"
#include <IRremote.h>

const int RECV_PIN = A5;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  irrecv.blink13(true);
  Serial.println ("starting direct sketch");

}

void loop() {
  if (irrecv.decode(&results)) {
    if (results.decode_type == NEC) {
      Serial.print("NEC: ");
    } else if (results.decode_type == SONY) {
      Serial.print("SONY: ");
    } else if (results.decode_type == RC5) {
      Serial.print("RC5: ");
    } else if (results.decode_type == RC6) {
      Serial.print("RC6: ");
    } else if (results.decode_type == UNKNOWN) {
      Serial.print("UNKNOWN: ");
    }
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}

Here I always get the following output if I press

NEC: FFA25D

Now comes my problem:
code which is faulty using irRemote from other library

ino file

#include "Arduino.h"
#include "ReceiverLibTest.h"
//The setup function is called once at startup of the sketch




ReceiverLibTest irReceiver;


void setup()
{
// Add your initialization code here
	Serial.begin(9600);
	Serial.println("Starting lib sketch");
}

// The loop function is called in an endless loop
void loop()
{

	irReceiver.processData();

}

library cpp

// Do not remove the include below
#include "ReceiverLibTest.h"
#include "IRremote.h"



#define IR_RECEIVE_PIN A5

IRrecv irrecv(IR_RECEIVE_PIN);

decode_results results;

ReceiverLibTest::ReceiverLibTest()
{
	// instanciate the infrared library on given pin

	// start the IR Receiver
	irrecv.enableIRIn();

}


void ReceiverLibTest::processData()
{
  if (irrecv.decode(&results)) {
	if (results.decode_type == NEC) {
	  Serial.print("NEC: ");
	} else if (results.decode_type == SONY) {
	  Serial.print("SONY: ");
	} else if (results.decode_type == RC5) {
	  Serial.print("RC5: ");
	} else if (results.decode_type == RC6) {
	  Serial.print("RC6: ");
	} else if (results.decode_type == UNKNOWN) {
	  Serial.print("UNKNOWN: ");
	}
	Serial.println(results.value, HEX);
	irrecv.resume(); // Receive the next value
  }
}

Here, if i press the standby button on my remote again, i allways get random values:

UNKNOWN: E9E70E8D
UNKNOWN: CF51C16E
UNKNOWN: E1886D7F
UNKNOWN: 4BCF0C40

So, what is the problem here? Can anyone explain this behavior?

Thanks, butch

Maybe there is a device mismatch.

This may not help but might be interesting:

NEC library

.

I am still using the same remote and the same button. Somehow it cannot detect the protocol correctly if I am using it from another lib.

Make sure your remote battery is new.

.

It has something to do with the programming.

Because the remote stays constant. I can switch / upload the two sketches as often as I want. It works on version 1 and reads garbage on version 2 (called within another lib).

So it is definetly code related.

I am having a similar problem. Did anyone figure this out?

If you have a problem start your 'own' thread and describe your situation.

.