/* Demo Rx program for e-Gizmo EGRF-433A1-R UHF Rx module * * by e-Gizmo Mechatronix Central * * using VirtualWire Libraries * * This sample program dumps Rxed data to serial port. * Monitor received data by using the IDE Serial Monitor */ #include const byte rxpin=11; // DIO pin 2 for Rx const byte rxenable=7; //DIO pin 7 for Rx Enable const byte ledpin=13; // Built in LED /* EGRF-433A1-R Speed settings */ // select 9600bps or 4800bps // Make sure only one group is uncommented // Uncomment next two lines if you want to set speed to 9600baud //unsigned int spattern=0x7810; //BR_Range3 //unsigned int lpattern=0x2ee0; // bit check limit 46-56 //Uncomment next two lines for 4800 baud unsigned int spattern=0x6810; //BR_Range2 unsigned int lpattern=0x2FD8; // bit check limit for 4500-5100 bps byte bitctr=14; void setup() { pinMode(rxenable,OUTPUT); // EGRF-433A1 DIO for ENable pin ATA3741(); // setup Rx module ATA3741 chip // UART is used for this demo to allow visual display // of Rxed data via Arduino IDE Tools>Serial Monitor // Otherwise, it is freely available for other purpose Serial.begin(9600); // Apply VitualWire settings vw_setup(4800); // Bits per sec vw_set_rx_pin(rxpin); vw_rx_start(); // Start the receiver PLL running pinMode(ledpin,OUTPUT); // LED } void loop() { uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; int i; if (vw_get_message(buf, &buflen)){ // data available? digitalWrite(13, HIGH); // flash ON LED // And dump Rxed data to serial port // Rxed data are stored in buf[] memory Serial.print("Rx Data: "); for (i = 0; i < buflen; i++) { Serial.print((char)buf[i]); } Serial.println(""); digitalWrite(rxenable, LOW); // Reset EGRF-433A1-R digitalWrite(13, LOW); // Flash OFF LED indicator digitalWrite(rxenable, HIGH); //Re enable to receive next data packet } } /* EGRF-433A1-R Hardware Initialization Routines * Configure the ATA3741 chip * to start RX activity */ void ATA3741(void){ digitalWrite(rxenable,HIGH); // Initiate ATA3741 configuration mode by // forcing DATA pin low for 15ms pinMode(rxpin,OUTPUT); // Change DATA pin direction to OUTPUT digitalWrite(rxpin,LOW); delayMicroseconds(15000); digitalWrite(rxpin,HIGH); pinMode(rxpin,INPUT); digitalWrite(rxpin,LOW); // wait for t2 bitctr=14; // send 14 bits init pattern while(bitctr>0){ while(digitalRead(rxpin)==HIGH); if((spattern & 0x8000)==0) ATA3741_LO(); else ATA3741_HI(); bitctr--; spattern=spattern<<1; } delayMicroseconds(15000); // Put back ATA3741 in config mode pinMode(rxpin,OUTPUT); digitalWrite(rxpin,LOW); delayMicroseconds(1000); digitalWrite(rxpin,HIGH); pinMode(rxpin,INPUT); digitalWrite(rxpin,LOW); // Enter 14-bit bit check limits pattern bitctr=14; while(bitctr>0){ while(digitalRead(rxpin)==HIGH); if((lpattern & 0x8000)==0) ATA3741_LO(); else ATA3741_HI(); bitctr--; lpattern=lpattern<<1; } } // Output a logic low void ATA3741_LO(void){ // wait until rxpin goes hi while(digitalRead(rxpin)==LOW); delayMicroseconds(131); pinMode(rxpin,OUTPUT); // output a low delayMicroseconds(150); // for 150uS pinMode(rxpin,INPUT); delayMicroseconds(50); } // Output a logic high void ATA3741_HI(void){ // Since rxpin should be normally at logic high // just wait if necessary until rxpin goes high while(digitalRead(rxpin)==LOW); }