Electronique/Hardware/Communication/433MHz/Arduino - Virtualwire

Test

Emetteur

#include<VirtualWire.h>voidsetup(){Serial.begin(115200);// Debugging onlySerial.println("setup");// Initialise the IO and ISRvw_set_ptt_inverted(true);// Required for DR3100vw_setup(2000);// Bits per sec//vw_set_tx_pin (12); // pin 12 by default}voidloop(){constchar*msg="hello";digitalWrite(13,true);// Flash a light to show transmittingvw_send((uint8_t*)msg,strlen(msg));vw_wait_tx();// Wait until the whole message is gonedigitalWrite(13,false);delay(200);}

Récepteur

#include<VirtualWire.h>voidsetup(){Serial.begin(115200);// Debugging onlySerial.println("setup");// Initialise the IO and ISRvw_set_ptt_inverted(true);// Required for DR3100vw_setup(2000);// Bits per secvw_rx_start();// Start the receiver PLL running//vw_set_rx_pin (11); // pin 11 by default}voidloop(){uint8_tbuf[VW_MAX_MESSAGE_LEN];uint8_tbuflen=VW_MAX_MESSAGE_LEN;if(vw_get_message(buf,&buflen)){// Non-blockinginti;digitalWrite(13,true);// Flash a light to show received good message// Message with a good checksum received, dump it.Serial.print("Got: ");for(i=0;i<buflen;i++){Serial.print(buf[i],HEX);Serial.print(" ");}for(i=0;i<buflen;i++){Serial.print(buf[i]);}Serial.println("");digitalWrite(13,false);}}