VirtualWire
Macros | Functions
VirtualWire.h File Reference

VirtualWire API. More...

#include <stdint.h>
#include "VirtualWire_Config.h"

Go to the source code of this file.

Macros

#define VW_PLATFORM_ARDUINO   1
 
#define VW_PLATFORM_MSP430   2
 
#define VW_PLATFORM_STM32   3
 
#define VW_PLATFORM_GENERIC_AVR8   4
 
#define VW_PLATFORM_UNO32   5
 
#define VW_MAX_MESSAGE_LEN   80
 Maximum number of bytes in a message, counting the byte count and FCS.
 
#define VW_RX_SAMPLES_PER_BIT   8
 Number of samples per bit.
 
#define VW_MAX_PAYLOAD   VW_MAX_MESSAGE_LEN-3
 The maximum payload length.
 
#define VW_RX_RAMP_LEN   160
 The size of the receiver ramp. Ramp wraps modulo this number.
 
#define VW_RAMP_INC   (VW_RX_RAMP_LEN/VW_RX_SAMPLES_PER_BIT)
 Internal ramp adjustment parameter.
 
#define VW_RAMP_TRANSITION   VW_RX_RAMP_LEN/2
 Internal ramp adjustment parameter.
 
#define VW_RAMP_ADJUST   9
 Internal ramp adjustment parameter.
 
#define VW_RAMP_INC_RETARD   (VW_RAMP_INC-VW_RAMP_ADJUST)
 Internal ramp adjustment parameter.
 
#define VW_RAMP_INC_ADVANCE   (VW_RAMP_INC+VW_RAMP_ADJUST)
 Internal ramp adjustment parameter.
 
#define VW_HEADER_LEN   8
 

Functions

void vw_set_ptt_pin (uint8_t pin)
 
void vw_set_tx_pin (uint8_t pin)
 
void vw_set_rx_pin (uint8_t pin)
 
void vw_set_rx_inverted (uint8_t inverted)
 
void vw_set_ptt_inverted (uint8_t inverted)
 
void vw_setup (uint16_t speed)
 
void vw_rx_start ()
 
void vw_rx_stop ()
 
uint8_t vw_tx_active ()
 
void vw_wait_tx ()
 
void vw_wait_rx ()
 
uint8_t vw_wait_rx_max (unsigned long milliseconds)
 
uint8_t vw_send (uint8_t *buf, uint8_t len)
 
uint8_t vw_have_message ()
 
uint8_t vw_get_message (uint8_t *buf, uint8_t *len)
 
uint8_t vw_get_rx_good ()
 
uint8_t vw_get_rx_bad ()
 

Detailed Description

VirtualWire API.

To use the VirtualWire library, you must have

* #include <VirtualWire.h>
*

At the top of your sketch.

Macro Definition Documentation

#define VW_HEADER_LEN   8

Outgoing message bits grouped as 6-bit words 36 alternating 1/0 bits, followed by 12 bits of start symbol Followed immediately by the 4-6 bit encoded byte count, message buffer and 2 byte FCS Each byte from the byte count on is translated into 2x6-bit words Caution, each symbol is transmitted LSBit first, but each byte is transmitted high nybble first

Referenced by vw_send().

Function Documentation

uint8_t vw_get_message ( uint8_t *  buf,
uint8_t *  len 
)

If a message is available (good checksum or not), copies up to *len octets to buf.

Parameters
[in]bufPointer to location to save the read data (must be at least *len bytes.
[in,out]lenAvailable space in buf. Will be set to the actual number of octets read
Returns
true if there was a message and the checksum was good
Examples:
client.pde, receiver.pde, and server.pde.
uint8_t vw_get_rx_bad ( )

Returns the count of bad messages received, ie messages with bogus lengths, indicating corruption or lost octets. Caution,: this is an 8 bit count and can easily overflow

Returns
Count of bad messages received
uint8_t vw_get_rx_good ( )

Returns the count of good messages received Caution,: this is an 8 bit count and can easily overflow

Returns
Count of good messages received
uint8_t vw_have_message ( )

Returns true if an unread message is available

Returns
true if a message is available to read
void vw_rx_start ( )

Start the Phase Locked Loop listening to the receiver Must do this before you can receive any messages When a message is available (good checksum or not), vw_have_message(); will return true.

Examples:
client.pde, receiver.pde, and server.pde.
void vw_rx_stop ( )

Stop the Phase Locked Loop listening to the receiver No messages will be received until vw_rx_start() is called again Saves interrupt processing cycles

uint8_t vw_send ( uint8_t *  buf,
uint8_t  len 
)

Send a message with the given length. Returns almost immediately, and message will be sent at the right timing by interrupts

Parameters
[in]bufPointer to the data to transmit
[in]lenNumber of octetes to transmit
Returns
true if the message was accepted for transmission, false if the message is too long (>VW_MAX_MESSAGE_LEN - 3)
Examples:
client.pde, server.pde, and transmitter.pde.

References VW_HEADER_LEN, VW_MAX_PAYLOAD, and vw_wait_tx().

void vw_set_ptt_inverted ( uint8_t  inverted)

By default the PTT pin goes high when the transmitter is enabled. This flag forces it low when the transmitter is enabled.

Parameters
[in]invertedTrue to invert PTT
Examples:
client.pde, receiver.pde, server.pde, and transmitter.pde.
void vw_set_ptt_pin ( uint8_t  pin)

This pin will only be accessed if the transmitter is enabled

Parameters
[in]pinThe Arduino pin number to enable the transmitter. Defaults to 10.
void vw_set_rx_inverted ( uint8_t  inverted)

By default the RX pin is expected to be low when idle, and to pulse high for each data pulse. This flag forces it to be inverted. This may be necessary if your transport medium inverts the logic of your signal, such as happens with some types of A/V tramsmitter.

Parameters
[in]invertedTrue to invert sense of receiver input
void vw_set_rx_pin ( uint8_t  pin)

Set the digital IO pin to be for receive data. This pin will only be accessed if the receiver is enabled

Parameters
[in]pinThe Arduino pin number for receiving data. Defaults to 11.
void vw_set_tx_pin ( uint8_t  pin)

Set the digital IO pin to be for transmit data. This pin will only be accessed if the transmitter is enabled

Parameters
[in]pinThe Arduino pin number for transmitting data. Defaults to 12.
void vw_setup ( uint16_t  speed)

Initialise the VirtualWire software, to operate at speed bits per second Call this one in your setup() after any vw_set_* calls Must call vw_rx_start() before you will get any messages

Parameters
[in]speedDesired speed in bits per second
Examples:
client.pde, receiver.pde, server.pde, and transmitter.pde.
uint8_t vw_tx_active ( )

Returns the state of the transmitter

Returns
true if the transmitter is active else false
void vw_wait_rx ( )

Block until a message is available then returns

Examples:
server.pde.
uint8_t vw_wait_rx_max ( unsigned long  milliseconds)

Block until a message is available or for a max time

Parameters
[in]millisecondsMaximum time to wait in milliseconds.
Returns
true if a message is available, false if the wait timed out.
Examples:
client.pde.
void vw_wait_tx ( )

Block until the transmitter is idle then returns

Examples:
client.pde, and transmitter.pde.

Referenced by vw_send().