Go Down

Topic: Combining VirtualWire and IRLib fails (Read 760 times) previous topic - next topic

FloStar3000

Hello everyone,

i am building on a "universal remote" that is supposed to use an Arduino to send IR signals to the individual devices (Projector, HiFi/BluRay, SAT Receiver) in our Home Cinema while it receives the input from another Arduino (the actual Remote) with those RF Links, because you cannot use 2 IR Receivers/Transmitters in the same room and the IRLib does not support sending and receiving at the same time either.
Now i have no problem using the RF Link/VirtualWire or the IR system individually, but combining them doesn't seem to work as intended. What am I doing wrong?

Much thanks for any advice

Code: [Select]

//TRANSMITTER (UNO)

#include <VirtualWire.h>


const int ledPin = 13;
const int txPin = 7;
const int button1Pin = 6;
const int button2Pin = 5;

boolean button1State = false;
boolean button2State = false;


void setup() {
  vw_set_tx_pin(txPin);
  vw_setup(2000);
  pinMode(ledPin, OUTPUT);
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
}

void loop() {
  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);

  if(button1State == HIGH){
    digitalWrite(ledPin, HIGH);
    vw_send((uint8_t *)"]", 1);
    delay(500);

  }

  else if(button2State == HIGH){
    digitalWrite(ledPin, HIGH);
    vw_send((uint8_t *)"2", 1);
    delay(500);
  }
      digitalWrite(ledPin, LOW);
}


Code: [Select]

//RECEIVER (MEGA)


#include <IRLib.h>
#include <VirtualWire.h>

const int RxPin = 11;
const int ledPin = 13;

IRsend MySender;




void setup() {
  vw_set_rx_pin(RxPin);
  vw_setup(2000);
  vw_rx_start();
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {

  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  uint8_t buf[buflen];

  if(vw_get_message (buf, &buflen)){
    for(int i = 0; i < buflen; i++){
      Serial.print(buf[i]);
    }
    Serial.println();

    delay(200);
    MySender.send(NEC, 0x8b7fa05, 32);
  }
 
}

jremington

Check the documentation for timer usage. There may be a conflict with Timer1.

INTP

Pause- "because you cannot use 2 IR Receivers/Transmitters in the same room "

If your project is based on this false premise and becomes needlessly more convoluted, I'd recommend resolving this misunderstanding and reconsider the setup.

FloStar3000

Pause- "because you cannot use 2 IR Receivers/Transmitters in the same room "

If your project is based on this false premise and becomes needlessly more convoluted, I'd recommend resolving this misunderstanding and reconsider the setup.
Sorry that was a false statement. It's just that the IRLib didn't allow me to send and receive in the same sketch and my assumption that RF works better in my case why i chose to use the RF links. It's also me wanting to get involved more with the use of the RF links and VW library.

Check the documentation for timer usage. There may be a conflict with Timer1.
I already tried the the timers 2 (default) and 3 but it didn't work as well.

DrAzzy

When you say "it doesn't work as intended" what does that mean?
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

FloStar3000

When you say "it doesn't work as intended" what does that mean?
I thought i could easily combine the 2 sketches i made earlier to test either the IRLib and VW functionality but it didn't work out or what do you mean?

jremington

Quote
it didn't work out
This phrase means nothing to us, and we can't help.

INTP

Pins 5 and 6: controlled by Timer0
Pins 9 and 10: controlled by Timer1
Pins 11 and 3: controlled by Timer2
*Not sure if Mega is the same.

I had also found Pin 11 to be no bueno for RF usage with the VirtualWire because of its interrupt usage of Timer2

Changing pins around is probably worth a shot.

jremington

Quote
VirtualWire because of its interrupt usage of Timer2
By default, VirtualWire uses Timer1.

FloStar3000

When you say "it doesn't work as intended" what does that mean?
This phrase means nothing to us, and we can't help.
Sorry for any comprehensibility issues. I'm from germany. What I did before to test the code is incidental.
It's just the code i posted which i thought would work but doesn't. And i'm asking you why.

INTP

Is your IR LED on pin 13?

That's a problem. It needs to be on a PWM pin.

FloStar3000

from the IRLibTimer.h:
Code: [Select]

/* Arduino Mega */
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
 //#define IR_SEND_TIMER1 11
 #define IR_SEND_TIMER2 9
 //#define IR_SEND_TIMER3 5
 //#define IR_SEND_TIMER4 6
 //#define IR_SEND_TIMER5 46



Now the compiler shows an error with my code even though i wrote the code again entirely. The universe hates me. I'll try it again tomorrow. Thanks guys.

Is your IR LED on pin 13?

PS:
That's a problem. It needs to be on a PWM pin.
On Mega pins 2-13 are PWM. But I don't use pin 13 anyway

INTP

Oh, okay. I don't have a Mega and haven't used that IR library you're using. I used IRremote.

Can you give any useful information about where it is failing? Is the IR LED transmitting anything? Look at the LED through your phone cam and see if it lights up.

FloStar3000

I know that the RF message is received and the IR Led lights up. The IR Code sent is correct as well, because the demo sketch works with it.

INTP

So you're saying it works as intended but your devices aren't responding to the IR output?

Go Up