Hello all,
I am working on a project to control multiple 32 channel receivers that are currently using manual remotes. The project is using RCSwitch, VituralWire, existing software & a 433.92 transmitter. I believe on 24 bit I should be able to run 32 devices with 32 channels (1024 total). The software seems to be set up for this and has an option for different receivers to be on different channels, however when I sync the receivers to the transmitter on different addresses and run the program, they are all on the same one, giving me only 32 out of the possible 1024 channels. I'm new to all this so I'm hoping someone can check the code to see if this might be the problem or if anyone has any other suggestions. Thanks much - Z.
//---------------------------------------------------------------------------
// include the library code:
#include <VirtualWire.h>
#include <RCSwitch.h>
//---------------------------------------------------------------------------
//The declaration of constants
#define Max_Adress 30
#define Max_CH 32
#define CH_In_Bank 8
#define Max_Bank 4 //(Max_CH/CH_In_Bank )
#define RC_Begin_Code 5327920
#define time_Bat_test 1000 //
#define time_Key_ask 10 //
#define USART_USB_RATE 9600 //
#define USART_BYTE_RS_Usec 11000000/USART_USB_RATE //
#define TX_RX_pin 13 //
#define RF_pin 12 //
unsigned char Adress = 1; //
unsigned char Bank = 0; //
unsigned char Units = 0;
unsigned char rx_bayt = 0;
unsigned char rx_count= 0;
unsigned char CH_rx = 0;
unsigned char Adress_rx=1;
unsigned char CRC8 = 0;
unsigned char CRC = 0;
unsigned char F_Key = 0;
char i_ = 0;
unsigned long msNow = 0;
unsigned long RC_Code =0;
unsigned char Protocol = 0;
uint8_t RF_TX_Buf[3]; // Buffer RF 433.92 –ú–ì—Ü.
#define Prot_C 5 // The number of protocol bits
unsigned char Prot_pin [Prot_C] = { 14, 15, 16, 17, 18};
RCSwitch mySwitch = RCSwitch();
//---------------------------------------------------------------------------
void CRC_8(unsigned char b);
void Fire();
void Rx_Decode();
void RF_Send(unsigned char rf_ch);
//---------------------------------------------------------------------------
void RF_Send(unsigned char rf_ch){
RC_Code = RC_Begin_Code+rf_ch+((Adress-1)*16);
mySwitch.send(RC_Code,24);
}
//---------------------------------------------------------------------------
void Rx_Decode(){ //
rx_bayt = Serial.read();
// CRC8 PyroIgnitorControl
if (rx_bayt == 0xFF && rx_count ==0){
CRC8=0;
rx_count++;
}
else if (rx_count == 1){
CRC_8(rx_bayt);
Adress_rx = rx_bayt;
rx_count++;
}
else if (rx_count == 2){
CRC_8(rx_bayt);
CH_rx = rx_bayt;
rx_count++;
}
else if (rx_count == 3){
if (CRC8 == rx_bayt ) Fire();
rx_count=0;
}
}
//---------------------------------------------------------------------------
void Fire(){
if (CH_rx > Max_CH) return;
digitalWrite(TX_RX_pin, HIGH) ;
if (digitalRead(Prot_pin[0]) == 0) Protocol =0;
else if (digitalRead(Prot_pin[1]) == 0) Protocol =1;
else Protocol =2;
switch (Protocol){
case 0:
mySwitch.setRepeatTransmit(10);
if (CH_rx<=12) RF_Send(CH_rx);
break;
case 1:
Bank = (CH_rx-1) / CH_In_Bank;
Units = CH_rx - Bank*CH_In_Bank;
mySwitch.setRepeatTransmit(6);
RF_Send(Bank+9);
delay(50);
mySwitch.setRepeatTransmit(4);
RF_Send(Units);
delay(50);
break;
case 2:
vw_send((uint8_t *)RF_TX_Buf, sizeof(RF_TX_Buf));
vw_wait_tx();
break;
}
digitalWrite(TX_RX_pin, LOW) ;
}
//---------------------------------------------------------------------------
void CRC_8(unsigned char b){
for(char i = 0; i < 8; b = b >> 1, i++){
if((b ^ CRC8) & 1) CRC8 = ((CRC8 ^ 0x18) >> 1) | 0x80;
else CRC8 = (CRC8 >> 1) & ~0x80;
}
}
//---------------------------------------------------------------------------
void setup() {
pinMode(TX_RX_pin, OUTPUT); //
digitalWrite(TX_RX_pin, LOW) ; //
//Wirtual wire setup
vw_set_tx_pin(RF_pin);
vw_set_rx_pin(-1);
vw_set_ptt_pin(-1);
vw_setup(3000); // Bits per sec
vw_rx_stop();
// Transmitter is connected to Arduino Pin
mySwitch.enableTransmit(RF_pin);
//Set pulse length.
mySwitch.setPulseLength(215);
mySwitch.setRepeatTransmit(10);
for (i_=0; i_<Prot_C; i_++ ) pinMode(Prot_pin[i_], INPUT); // Set up the input on the receiver to select the protocol jumpers
for (i_=0; i_<Prot_C; i_++ ) digitalWrite(Prot_pin[i_], HIGH); // Include internal pull-up resistors to +5 V
Serial.begin(USART_USB_RATE);
}
//---------------------------------------------------------------------------
void loop() {
if (Serial.available() > 0) Rx_Decode();
}
//---------------------------------------------------------------------------