I'm working on a project that will use two Arduini. They need to communicate wirelessly, and I've opted to use an RF Link. Here's my transmitter (RF Link Transmitter - 434MHz - WRL-10534 - SparkFun Electronics), and here's my receiver (https://www.sparkfun.com/products/10532).
Now, I currently only have one Arduino, a Duemillanove. I'm trying to test these components before getting the second one, in case they do not work.
However, I simply can't find a way to test the emitter and receiver. I've tried concatenating the sample transmit and receive code like so:
#include <VirtualWire.h>
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
const char *msg = "hello";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
delay(200);
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
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(" ");
}
Serial.println("");
digitalWrite(13, false);
}
}
Obviously, this does not work at all. There is no output on the log, probably because the transmitting code and the receiving code are not parallelized.
To conclude, how is it possible to test the library and my RF components before I buy my second Arduino ?
You cannot test those modules with a single arduino, as those modules do not have any controller with a buffer/fifo inside.
I would recommend you to opt for an nrf24l01+, or Bluetooth, etc.
pito:
You cannot test those modules with a single arduino, as those modules do not have any controller with a buffer/fifo inside.
I would recommend you to opt for an nrf24l01+, or Bluetooth, etc.
Although I can't speak to the particular problem OP is having, it should be possible to test those modules with a single Arduino. I've used them with a single Atmega168, communicating with the Atmega's UART.
Thanks for the two answers. @Yes, how did you proceed to test these specific models with one device ?
I'd look for alternatives to them, but I have one simple requirement: they need to have ~500ft range in the open.
I hooked the transmitter to the TX of the Atmega and receiver to RX, then did serial communications like normal. I would try that - just do a Serial.print or something to transmit a byte, then read in a character, check for that specific byte, and if you receive it turn an LED on.
You might want to look for alternatives though if your goal is 500 ft. I believe that's just about at the maximum range under ideal conditions for those.
Thanks for the suggestions, obiwanjacobi and Yes. I wasn't able to get the testing going with VirtualWire, but your suggestion to use plain Serial worked out great.
For people wondering, this is the code I used:
char inData[20];
char inChar;
byte index = 0;
void setup() {
Serial.begin(9600);
Serial.print("Hey, I'm working !");
}
void loop() {
while(Serial.available() > 0) {
if(index < 19) // One less than the size of the array
{
inChar = Serial.read(); // Read a character
inData[index] = inChar; // Store it
index++; // Increment where to write next
inData[index] = '\0'; // Null terminate the string
}
}
Serial.println(inData);
}
.
I got most of it from a post on this forum. In the end, the Arduino was able to print the "Hey, I'm working !" after having received it.
That works because Serial uses buffers. If you do not have buffers, like VirtualWire, you miss (part of) the message you're sending.
I meant something like this (not compiled).
#include <VirtualWire.h>
bool messageSent = false;
const char *msg = "hello";
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
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(" ");
}
Serial.println("");
digitalWrite(13, false);
}
if(!messageSent)
{
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
//vw_wait_tx(); // DONT! Wait until the whole message is gone
//delay(200); NO DELAY!
digitalWrite(13, false);
messageSent = true;
}
}