sábado, 12 de enero de 2013

Comunicación RF

Para la comunicación RF use la siguiente librería VirtualWire-1.4.zip descargar y descomprimir en libraries en mi caso /opt/arduino-1.5.1/libraries
Nota. la librería solo funciona con la versión 0022 de Arduino

Receptor


#include <VirtualWire.h>    // you must download and install the VirtualWire.h to your hardware/libraries folder
#undef int
#undef abs
#undef double
#undef float
#undef round

void setup()
{
    Serial.begin(9600);  
    vw_set_ptt_inverted(true);    // Required for RX Link Module
    vw_setup(2000);                   // Bits per sec
    vw_set_rx_pin(4);  
    vw_rx_start();  
Serial.println("Iniciando");
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // check to see if anything has been received
    {
    int i;
     
    for (i = 0; i < buflen; i++)
    {
        Serial.print(buf[i]);                     // the received data is stored in buffer
        }
    Serial.println("");
     }
}



Emisor


#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round

void setup()
{
    vw_set_ptt_inverted(true); // Required for RF Link module
    vw_setup(2000);                 // Bits per sec
    vw_set_tx_pin(3);
}

void loop()
{
    const char *msg = "Hola blas !!!";       // this is your message to send
   vw_send((uint8_t *)msg, strlen(msg));
   vw_wait_tx();                                          // Wait for message to finish
   delay(200);
}

No hay comentarios:

Publicar un comentario