Home easy + virtual wire

Hi,

I tried Home easy (http://playground.arduino.cc/Code/HomeEasy) code to control an 433MHZ device with an 433MHZ TX and it works perfectly when i just have that part of the code, but then when i mix with another code I have that uses an 433MHZ RX to receive some values from another transmiter the Home Easy code doesn't work..

I tried just adding this first lines of code to the home ease code and it was enought for it to doesn't work:

vw_set_rx_pin(2);
vw_setup(4000); 
vw_rx_start();

I'm using pin 2 to the RX and pin 3 to the TX.

is there any incompability between them?

Post your code. All of it.

sorry

#include <VirtualWire.h>

int RXPin = 2;
int txPin = 3;
int value1;
int value2;
int value3;
int value4;
int value5;
int value6;
bool bit2[26]={};              // 26 bit global to store the HE device address.
char StringReceived[22]; 

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

//******* VOID LOOP**********
void loop(void)
{

  rf_receiver();
  lights_on();
  delay(1500);
} 


void rf_receiver () {
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) 
  {
    int i;
    for (i = 0; i < buflen; i++)
    {            
      StringReceived[i] = char(buf[i]);
    }
    sscanf(StringReceived, "%d,%d,%d,%d,%d,%d,", &value1, &value2, &value3, &value4, &value5, &value6); // Converts a string to an array
  }
  memset( StringReceived, 0, sizeof( StringReceived));// This line is for reset the StringReceived
}



void lights_on() {
  itob(1235487,26);            // convert device code..
  transmit(true);            // send ON
  delay(10);                 // wait (socket ignores us it appears unless we do this)
  transmit(true);   
}


void transmit(int blnOn)
{
  int i;
  // Do the latch sequence.. 
  digitalWrite(txPin, HIGH);
  delayMicroseconds(275);     // bit of radio shouting before we start. 
  digitalWrite(txPin, LOW);
  delayMicroseconds(9900);     // low for 9900 for latch 1
  digitalWrite(txPin, HIGH);   // high again 
  delayMicroseconds(275);      // wait a moment 275
  digitalWrite(txPin, LOW);    // low again for 2675 - latch 2.
  delayMicroseconds(2675);
  // End on a high 
  digitalWrite(txPin, HIGH);

  // Send HE Device Address..
  // e.g. 1000010101000110010  272946 in binary.
  for(i=0; i<26;i++)
  {
    sendPair(bit2[i]);
  }

  // Send 26th bit - group 1/0
  sendPair(false);

  // Send 27th bit - on/off 1/0
  sendPair(blnOn);

  // last 4 bits - recipient   -- button 1 on the HE300 set to 
  // slider position I in this example:

  sendPair(false);
  sendPair(false);
  sendPair(false);
  sendPair(false);

  digitalWrite(txPin, HIGH);   // high again (shut up)
  delayMicroseconds(275);      // wait a moment
  digitalWrite(txPin, LOW);    // low again for 2675 - latch 2.

}


void sendBit(boolean b) {
  if (b) {
    digitalWrite(txPin, HIGH);
    delayMicroseconds(310);   //275 orinally, but tweaked.
    digitalWrite(txPin, LOW);
    delayMicroseconds(1340);  //1225 orinally, but tweaked.
  }
  else {
    digitalWrite(txPin, HIGH);
    delayMicroseconds(310);   //275 orinally, but tweaked.
    digitalWrite(txPin, LOW);
    delayMicroseconds(310);   //275 orinally, but tweaked.
  }
}

void sendPair(boolean b) {
  // Send the Manchester Encoded data 01 or 10, never 11 or 00
  if(b)
  {
    sendBit(true);
    sendBit(false);
  }
  else
  {
    sendBit(false);
    sendBit(true);
  }
}


void itob(unsigned long integer, int length)
{  //needs bit2[length]
  // Convert long device code into binary (stores in global bit2 array.)
  for (int i=0; i<length; i++){
    if ((integer / power2(length-1-i))==1){
      integer-=power2(length-1-i);
      bit2[i]=1;
    }
    else bit2[i]=0;
  }
}

unsigned long power2(int power){    //gives 2 to the (power)
  unsigned long integer=1;          
  for (int i=0; i<power; i++){      
    integer*=2;
  }
  return integer;
}

any mistake?

if i only use the Home Easy code the code works:

#include <VirtualWire.h>

int rxpin = 2;
int txPin = 3;
int value1;
int value2;
int value3;
int value4;
int value5;
int value6;
bool bit2[26]={};              // 26 bit global to store the HE device address.
char StringReceived[22]; 

void setup(void)
{
  pinMode(txPin, OUTPUT); 
  Serial.begin(9600); 
  //vw_setup(2000);
  //vw_set_rx_pin(rxpin);  
  //vw_rx_start(); 
}

//******* VOID LOOP**********
void loop(void)
{

  lights_on();
  delay(1500);
} 


void lights_on() {
  itob(1235487,26);            // convert device code..
  transmit(true);            // send ON
  delay(10);                 // wait (socket ignores us it appears unless we do this)
  transmit(true);   
}


void transmit(int blnOn)
{
  int i;
  // Do the latch sequence.. 
  digitalWrite(txPin, HIGH);
  delayMicroseconds(275);     // bit of radio shouting before we start. 
  digitalWrite(txPin, LOW);
  delayMicroseconds(9900);     // low for 9900 for latch 1
  digitalWrite(txPin, HIGH);   // high again 
  delayMicroseconds(275);      // wait a moment 275
  digitalWrite(txPin, LOW);    // low again for 2675 - latch 2.
  delayMicroseconds(2675);
  // End on a high 
  digitalWrite(txPin, HIGH);

  // Send HE Device Address..
  // e.g. 1000010101000110010  272946 in binary.
  for(i=0; i<26;i++)
  {
    sendPair(bit2[i]);
  }

  // Send 26th bit - group 1/0
  sendPair(false);

  // Send 27th bit - on/off 1/0
  sendPair(blnOn);

  // last 4 bits - recipient   -- button 1 on the HE300 set to 
  // slider position I in this example:

  sendPair(false);
  sendPair(false);
  sendPair(false);
  sendPair(false);

  digitalWrite(txPin, HIGH);   // high again (shut up)
  delayMicroseconds(275);      // wait a moment
  digitalWrite(txPin, LOW);    // low again for 2675 - latch 2.

}


void sendBit(boolean b) {
  if (b) {
    digitalWrite(txPin, HIGH);
    delayMicroseconds(310);   //275 orinally, but tweaked.
    digitalWrite(txPin, LOW);
    delayMicroseconds(1340);  //1225 orinally, but tweaked.
  }
  else {
    digitalWrite(txPin, HIGH);
    delayMicroseconds(310);   //275 orinally, but tweaked.
    digitalWrite(txPin, LOW);
    delayMicroseconds(310);   //275 orinally, but tweaked.
  }
}

void sendPair(boolean b) {
  // Send the Manchester Encoded data 01 or 10, never 11 or 00
  if(b)
  {
    sendBit(true);
    sendBit(false);
  }
  else
  {
    sendBit(false);
    sendBit(true);
  }
}


void itob(unsigned long integer, int length)
{  //needs bit2[length]
  // Convert long device code into binary (stores in global bit2 array.)
  for (int i=0; i<length; i++){
    if ((integer / power2(length-1-i))==1){
      integer-=power2(length-1-i);
      bit2[i]=1;
    }
    else bit2[i]=0;
  }
}

unsigned long power2(int power){    //gives 2 to the (power)
  unsigned long integer=1;          
  for (int i=0; i<power; i++){      
    integer*=2;
  }
  return integer;
}

but if i just uncomment the 3 lines of the virtual wire it stops working…

vw_setup(2000);
vw_set_rx_pin(rxpin);  
vw_rx_start();

fabmsg: is there any incompability between them?

Yes.

kowalski:
Yes.

I cannot use them together? is there any way to avoid this?