Go Down

Topic: Use 2 IR Receiver (Read 612 times) previous topic - next topic

zulirfan

Hi, i try to use 2 ir recevier in the same time with arduino, and i try to se from what ir is the signal coming.
my ir are TSOPxxxx, but the problem is in the program, i don't know how to use 2 ir  recevier on the same arduino.
i try to use JVCPanasonicSendDemo for transmitter. i try to make something like this but dont working well:

Code: [Select]
#include <IRremote.h>

int RECV_R = 12;
int RECV_L = 11;
int on = 0;

IRrecv irrecvR(RECV_R);
IRrecv irrecvL(RECV_L);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecvR.enableIRIn(); // Start the receiver
  irrecvL.enableIRIn(); // Start the receiver
  pinMode(A0, OUTPUT);// Start the receiver
  pinMode(A1, OUTPUT);// Start the receiver
  pinMode(A2, OUTPUT);// Start the receiver
  pinMode(A3, OUTPUT);
}
void dumpL(decode_results *results) {
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
  }
  else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->panasonicAddress, HEX);
    Serial.print(" Value: ");

    digitalWrite(A0, on);
    digitalWrite(A2, on);
    delay(1000);
  }
  Serial.print(results->value, HEX);
  Serial.print(" ");
  Serial.print(results->value, DEC);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");
  Serial.println("");
}

void dumpR(decode_results *results) {
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
  }
  else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->panasonicAddress, HEX);
    Serial.print(" Value: ");
    digitalWrite(A1, on);
    digitalWrite(A3, on);
    delay(1000);
  }
  Serial.print(results->value, HEX);
  Serial.print(" ");
  Serial.print(results->value, DEC);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");
  Serial.println("");
}


void loop() {
  digitalWrite(A0, 1023);
  digitalWrite(A1, 1023);
  digitalWrite(A2, 1023);
  digitalWrite(A3, 1023);
  if (irrecvR.decode(&results) && irrecvL.decode(&results)) {
    Serial.println(" TWO ");
    irrecvR.resume();
    irrecvL.resume();
  }
    else if (irrecvL.decode(&results)) {
    Serial.println(" L ");
    dumpL(&results);
    irrecvL.resume();  // Receive the next value
  }
  else if (irrecvR.decode(&results)) {
    Serial.println(" R ");
    dumpR(&results); // Receive the next value
    irrecvR.resume();
  }

 
}


How is the solution??

ieee488

It is most likely because the library for the IR uses the same timer.
I seem to recall reading something about this.

Do your research!


johnwasser

Maybe something like this?
Code: [Select]
#define DECODE_PANASONIC 1
#include <IRremote.h>

int RECV_R = 12;
int RECV_L = 11;
int on = LOW;

IRrecv irrecvR(RECV_R);
IRrecv irrecvL(RECV_L);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecvR.enableIRIn(); // Start the receiver
  irrecvL.enableIRIn(); // Start the receiver
  pinMode(A0, OUTPUT);// Start the receiver
  pinMode(A1, OUTPUT);// Start the receiver
  pinMode(A2, OUTPUT);// Start the receiver
  pinMode(A3, OUTPUT);
}

void dump(decode_results *results, int Pin1, int Pin2) {
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
  }
  else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->value, HEX);
    Serial.print(" Value: ");

    digitalWrite(Pin1, on);
    digitalWrite(Pin2, on);
    delay(1000);
  }
  Serial.print(results->value, HEX);
  Serial.print(" ");
  Serial.print(results->value, DEC);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");
  Serial.println("");
}

void loop() {
  digitalWrite(A0, HIGH);
  digitalWrite(A1, HIGH);
  digitalWrite(A2, HIGH);
  digitalWrite(A3, HIGH);

  if (irrecvL.decode(&results)) {
    Serial.println("\n\n L ");
    dump(&results, A0, A2);
    irrecvL.resume();  // Receive the next value
  }
  
  if (irrecvR.decode(&results)) {
    Serial.println("\n\n R ");
    dump(&results, A1, A3);
    irrecvR.resume(); // Receive the next value
  }
}
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

zulirfan

but the only signal received by pin 11

johnwasser

I just checked the IRremote library sources.  They only support one input at a time.  You may need to look for a different library from someone who has solved this problem before.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

zulirfan

Ok thanks for your answer mr johnwasser (y)

Go Up