Help with 433 RF project & Code check
hello all,
i working on project control multiple 32 channel receivers using manual remotes. project using rcswitch, vituralwire, existing software & 433.92 transmitter. believe on 24 bit should able run 32 devices 32 channels (1024 total). software seems set , has option different receivers on different channels, when sync receivers transmitter on different addresses , run program, on same one, giving me 32 out of possible 1024 channels. i'm new i'm hoping can check code see if might problem or if has other suggestions. - z.
i working on project control multiple 32 channel receivers using manual remotes. project using rcswitch, vituralwire, existing software & 433.92 transmitter. believe on 24 bit should able run 32 devices 32 channels (1024 total). software seems set , has option different receivers on different channels, when sync receivers transmitter on different addresses , run program, on same one, giving me 32 out of possible 1024 channels. i'm new i'm hoping can check code see if might problem or if has other suggestions. - z.
code: [select]
//---------------------------------------------------------------------------
// include 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 // 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 = 0; < 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 connected arduino pin
myswitch.enabletransmit(rf_pin);
//set pulse length.
myswitch.setpulselength(215);
myswitch.setrepeattransmit(10);
(i_=0; i_<prot_c; i_++ ) pinmode(prot_pin[i_], input); // set input on receiver select protocol jumpers
(i_=0; i_<prot_c; i_++ ) digitalwrite(prot_pin[i_], high); // include internal pull-up resistors +5 v
serial.begin(usart_usb_rate);
}
//---------------------------------------------------------------------------
void loop() {
if (serial.available() > 0) rx_decode();
}
//---------------------------------------------------------------------------
after research, possible encoding chip needed on transmitter? new auduino , thinking controller encode each signal software. software sound others have used success other sketches. i'm thinking must code. didn't write code i'm hoping here can verify it. appreciated. if more info needed please ask. need have project working in 2 weeks. in advance - steve.
Arduino Forum > Using Arduino > Project Guidance > Help with 433 RF project & Code check
arduino
Comments
Post a Comment