RF
Como primeiro projecto RF usei os módulos RR3 e RT4 da Telecontrolli:
Módulo emissor (RT4):
Módulo receptor (RR3):
As ligações são bastantes simples:
RT4 (EMISSOR):
RR3 (RECEPTOR):
Para fazer o teste inicial de envio/recepção tentei utilizar o envio simples de informação através da porta TX do Arduino emissor e RX no receptor, como o resultado não foi o esperado, decidi assim usar a library VirtualWire que funcionou muito bem.
Código Emissor:
// RF Link using VirtualWire to Transmit messages
// simplex (one-way) receiver with a 315MHz RF Link Transmitter module
// tx => pin 2 on arduino
#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()
{
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for RF Link module
vw_setup(2000); // Bits per sec
vw_set_tx_pin(2); // pin 2 is used as the transmit data out into the TX Link module, change this to suit your needs.
}
void loop()
{
const char *msg = "GRCBYTE"; // this is your message to send
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait for message to finish
delay(200);
}
Código Receptor:
// RF Link using VirtualWire to receive messages
// simplex (one-way) receiver with a 315MHz RF Link Receiver module
#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);
// Initialise the IO and ISR
// vw_set_ptt_inverted(true); // Required for RX Link Module
vw_setup(2000); // Bits per sec
vw_set_rx_pin(3); // We will be receiving on arduino pin 3 (RX pin from the module connects to this pin)
vw_rx_start(); // Start the receiver
}
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;
// Message with a good checksum received.
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i]); // the received data is stored in buffer
}
Serial.println("");
}
}
A mensagem "Grcbyte" é assim enviada e recebida sem qualquer problema, gostei bastante do alcance destes módulos RF existindo mesmo boa recepção através de divisões/paredes.
Teste em carro-robot:
Vídeo: