VirtualWire: receive and transfer from 1 arduino

I am trying to send and receive data by rf-modules with the virtualwire lib.

Question:

I run vw_rx_start in setup()

in loop() i first send data by the vw_send function by the transmitter. After that i would like to receive that sended message by the receiver... But i can't get it working.

Is it possible to send and receive at the same moment by 1 arduino board? If so, how?

Regards, Thomas Lenting The Netherlands

Are you running the code described here?

http://www.open.com.au/mikem/arduino/VirtualWire.pdf

with both the transmit code in 5.1 and the receive code in 5.2 running in void loop() one after the other so it looks something like this?

#include <VirtualWire.h>
void setup()
{
  Serial.begin(9600);
  Serial.println("setup");
  vw_setup(2000); // Bits per sec
  vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
  const char *msg = "hello";
  vw_send((uint8_t *)msg, strlen(msg));
  delay(400);
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    int i;
    // Message with a good checksum received, dump HEX
    Serial.print("Got: ");
    for (i = 0; i < buflen; i++)
    {
      Serial.print(buf[i], HEX);
      Serial.print(" ");
    }
    Serial.println("");
  }
}

That compiles okay, wouldn’t have occurred to me to try as I was trying for seperation between Tx & Rx devices.

Thanks for the reply!

I tested it by sending a string like you wrote in your message; but also by putting the transmitter to high and low and trying to read the values. But it's still not working.

Do i need a special power device for the transmitter? At the trasmitter pin for input of the current there stands 12v; i connected this pin to the power pin of the arduino which is 5v. Could that be the problem?

No special power is needed. I am running my transmitter at 3.7V (Li Ion battery) and the receiver at 5V.

I have not tried running both off the same arduino, that's kind of a new use.

You don't have a 2nd arduino you can use?

Today i tried 2 new RF transceiver and transmitter modules. But still no luck.

I was reading the VirtualWire documentation at http://www.open.com.au/mikem/arduino/VirtualWire.pdf

In this tutorial is some code; ie. this ‘client’-code at paragraph 5.3:

#include <VirtualWire.h>
void setup()
{
Serial.begin(9600);// Debugging only
Serial.println("setup");
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
const char *msg = "hello";
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
Serial.println("Sent");
// Wait at most 400ms for a reply
if (vw_wait_rx_max(400))
{
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Got reply: ");
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i], HEX);
Serial.print(" ");
}
Serial.println("");
}
}
else
Serial.println("Timout");
}

The description of the code ‘Implements a simple wireless client for DR3100. Sends a message to another Arduino
running the server code below and waits for a reply.’: so the receiver will not receive it’s own message wich it send before. Or am i wrong?

Regards,
Thomas

I haven't looked into the code that makes up the VirtualWire library, but to receive while you are sending while going thru the regular interface pins (the UART is not used) it would seem to me that the send side would need to be interrupted for the receive processing.

So basically I don't know enough about this to give you an answer. I can only you that one arduino sending while a 2nd receives works great with the library. I have not done any testing to see if one arduino can send and receive from a 2nd arduino at the same time.

Oke, thanks for the reply! I will try it this evening with a nice cold beer. When i wake up in the morning i hope i have a headache from the party i will have when it works!

Regards, Thomas

Thomas,

Please-pardon-the-“-“-myspacebarisbusted.

I-wonder-if-you-found-a-way-?. “to send and receive data by rf-modules with the virtualwire lib?” off-the-same-Arduino?

John