Confirm Virtualwire Receiver has Started

The following is the example receiver code for Virtualwire.

#include <VirtualWire.h>

void setup()
{
    Serial.begin(9600);	// Debugging only
    Serial.println("setup");

    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);	 // Bits per sec

    vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
    }

I would like to add a check that the receiver has been initialised.

Can I do this :

if(!vw_rx_start())  Serial.println("Receiver Error");

Ok that idea did not work :frowning:

Suggestions would be appreciated.

The code is pretty simple. The vw_setup routine just initializes the ports and programs the timer. vw_rx_start just sets a flag to enable reception. There is not much to check.

jremington:
There is not much to check.

Errr.... how do I put this - I WANT to implement a check.

If the code doesn't work, something is wrong with either the processor itself or the input data. If everything else works, the former is extremely unlikely to be a problem.

To test the latter, feed the input pin with a proper message and determine if the software responds correctly.

This is not for a test bench environment. Manual testing is not practical.

Without sending something, and getting a response, there is NO way to tell if a radio is working. Get over it.

aisc, the receiver could be broken, but VirtualWire does not check that. That is impossible.
Other receivers (transceiver modules) contain a chip, but VirtualWire uses the simple ASK receivers, with a single pin for the demodulated signal.

Tell us why you want to test it ?
It is very strange to test it. If the receiver could be damaged by lightning, then also the Arduino or the 5V regulator could be damaged. How would you test all that ?

Peter_n:
Tell us why you want to test it ?

I would like to implement a check for a receiver "similar" to what one can do with an SD Card.

The objective is to check that the receiver is correctly installed and/or not dislodged and/or not broken and stop the sketch on start up or reset if an error is detected. Error status will be displayed via an LCD.

That having been said, I do realize it is not possible with all hardware/library combinations and I am trying to figure out what hardware/library combination to use to achieve the objective.

The receiver receives noise, it could be 2kHz of noise. You could check the pin for noise. However, an open pin receives noise as well. You could analyze the noise with an analog pin, since the highest level is not 5V.
Or you can use redundancy: use three Arduino boards, each with its own receiver.

But seriously, those are not very good options. If you receive data it is okay, else it might not be okay.

@Peter_n : Noted.

Looking at the Radio Head Ask library receiver example, it does have a check viz.

// ask_receiver.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to receive messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) receiver with an Rx-B1 module

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile

RH_ASK driver;

void setup()
{
    Serial.begin(9600); // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

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

    if (driver.recv(buf, &buflen)) // Non-blocking
    {
 int i;

 // Message with a good checksum received, dump it.
 driver.printBuffer("Got:", buf, buflen);
    }
}

However, when I use this code (partial shown) with a cheap 1 data pin receiver:

if (driver.init()) {
        Serial.println(F(" done."));
        lcd.print(F("Ok"));
      }
      else {
        Serial.println(F(" failed."));
        lcd.print(F("Fail"));
      }

I can unplug the receiver and no error is detected.

Will using different hardware make a difference?

Normally a transceiver has a chip on the RF module. The chip controls the transmitting and receiving and the protocol. When software communicates with the chip, it can check if the chip is present.
I think any other RF module can do that. Only those very cheap ASK (on/off modulation) modules can not do that.

Sparkfun has a Wireless Buying Guide : Wireless Buying Guide - SparkFun Electronics
And RadioHead has a list of supported devices : RadioHead: RadioHead Packet Radio library for embedded microprocessors