 In the virtualwire instruction guide it give me this calculation. I would like to know what this calculation is for?

Messages of up to VW_MAX_PAYLOAD (27) bytes can be sent (Does this mean maximum 27 bits can be send using the library) Each message is transmitted as: • 36 bit training preamble consisting of 0-1 bit pairs (what does this mean?) • 12 bit start symbol 0xb38 (what does this mean?) • 1 byte of message length byte count (4 to 30), count includes byte count and FCS bytes (what does this mean?) • n message bytes, maximum n is VW_MAX_PAYLOAD (27) (what does this mean?) • 2 bytes FCS, sent low byte-hi byte (what does this mean?)

Everything after the start symbol is encoded 4 to 6 bits, Therefore a byte in the message is encoded as 2x6 bit symbols, sent hi nybble, low nybble. (what does this mean?) Each symbol is sent LSBit first.

The Arduino Diecimila clock rate is 16MHz => 62.5ns/cycle. For an RF bit rate of 2000 bps, need 500microsec bit period. (How do you know whether you need 500microsec bit period?) The ramp requires 8 samples per bit period, so need 62.5microsec per sample => interrupt tick is 62.5microsec. (what does this mean?) The maximum packet length consists of (6 + 2 + VW_MAX_MESSAGE_LEN*2) * 6 = 408 bits = 0.204 secs (at 2000 bps). (How to calculate this?) where VW_MAX_MESSAGE_LEN is VW_MAX_PAYLOAD + 3 (= 30). (How to calculate this?)

I really need someone who can explain to me this part. Which I don't understand at all except getting the period from 16MHz frequecny.

Thanks

Messages of up to VW_MAX_PAYLOAD (27) bytes can be sent (Does this mean maximum 27 bits can be send using the library)

No, it doesn’t.

• 36 bit training preamble consisting of 0-1 bit pairs (what does this mean?)

The library is going to send some stuff before your message/payload. Exactly what is irrelevant to you, but it is described. In this case, 18 pairs of 0 and 1 bits (01010101010…)

• 12 bit start symbol 0xb38 (what does this mean?)

Again, a specific implementation detail that shouldn’t matter to you. But, what it means is that that specific 12 bit bit pattern will then be sent.

• 1 byte of message length byte count (4 to 30), count includes byte count and FCS bytes (what does this mean?)

The length of the payload will then be sent.

• n message bytes, maximum n is VW_MAX_PAYLOAD (27) (what does this mean?)

You message/payload will then be sent.

The maximum packet length consists of (6 + 2 + VW_MAX_MESSAGE_LEN*2) * 6 = 408 bits = 0.204 secs (at 2000 bps). (How to calculate this?)

How to calculate what? The formula is simply explaining why the packet/payload length is what it is.

where VW_MAX_MESSAGE_LEN is VW_MAX_PAYLOAD + 3 (= 30). (How to calculate this?)/quote]
Again, there is nothing to calculate.

I really need someone who can explain to me this part. Which I don’t understand at all except getting the period from 16MHz frequecny.

Why do you need to. You don’t need to understand how a library works in order to use it.

What problem are you trying to solve?

Ok, It’s because its set to 2000 bps in the sample code, and was wondering what effect would it have if I changed it in terms of data being sent. I know bit rate would be faster. Few may questions if I may. In the guide an example was given and I would like to know what some of those lines of code do:

``````transmitter

#include <VirtualWire.h>
void setup()
{
vw_setup(2000); // Bits per sec
}
void loop()
{
const char *msg = "hello";
vw_send((uint8_t *)msg, strlen(msg));    //(What does uint8_t and strlen mean?)
delay(400);
}
``````

``````#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()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];        //(What does buf mean? And if you set bps using vw_setup() is VW_MAX_MESSAGE_LEN auto calculated?)
uint8_t buflen = VW_MAX_MESSAGE_LEN;    //(What does buflen mean?, what exactly does this line and previous line do?)
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("");
}
}
``````
``````vw_setup(2000); // Bits per sec
``````

Initializes the virtual wire library, and sets the speed.

``````vw_send((uint8_t *)msg, strlen(msg));    //(What does uint8_t and strlen mean?)
``````

uint8_t is a platform-independent sized variable. u means unsigned. int means that it is an integer type. 8 defines the number of bits in the value.

strlen() is a string function. It measures the length of the string given as an argument.

The vw_send() function sends the data in the first argument, cast as a pointer to byte. The number of bytes to send is defined by the second argument.

``````uint8_t buf[VW_MAX_MESSAGE_LEN];        //(What does buf mean? And if you set bps using vw_setup() is VW_MAX_MESSAGE_LEN auto calculated?)
``````

It's the name of an array. The array could have been called anything, but RingoStarr[] conveys little meaning, whereas buf does mean something (to me, as least, and it will to you, too, someday).

No, the maximum length is not calculated. It is a preset constant in the library.

``````uint8_t buflen = VW_MAX_MESSAGE_LEN;    //(What does buflen mean?, what exactly does this line and previous line do?)
``````

The name in capital letters is a constant. The variable buflen is assigned an initial value, but it can be changed later. The previous line is allocating an array of a specific (maximum) size.

``````if (vw_get_message(buf, &buflen)) // Non-blocking
``````

This function gets the message that was sent, if it is available. It returns the number of bytes actually read, in the second argument, and returns true or false based on whether or not there was good data read.

Thank you very much. Your explanation really helped. I would like to get a feedback on how to implement a code. Suppose for example I have a code running on arduino that detects the temperature and if the temperature > 30 degrees lights up a red LED if not LED stays green. Do you think its better to do the calculation and logic making on the arduino connected to transmitter and just send the output (whether the LED should be green or red) to the receiver side arduino ?

That's certainly one way to do it. Send the Red/Green status once a second or so. The receiver could send display alternating Red/Green when no data is received after 3 seconds or something similar.

I ran these code. And I was able to receive something on the receiver side. Given below is the code and the data received. Why is it that I am unable to receive the msg and instead getting numbers. On the serial monitor I set to 9600 baud and i got the numbers. When I set to 2400 baud as mentioned in the link I get the characters.

I refered (http://letsmakerobots.com/node/12336) for the code.

Here is the datasheet for the transmitter and receiver:

``````//receiver code

#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(7);            // We will be receiving on pin 23 (Mega) ie the RX pin from the module connects to this pin.
}

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("");
}
}
``````
``````//transmitter

#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(8);                // pin 3 is used as the transmit data out into the TX Link module, change this to suit your needs.
}

void loop()
{
const char *msg = "LMR-II Rocks";       // this is your message to send

vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();                                          // Wait for message to finish
delay(200);
}
``````

767782457373328211199107115
767782457373328211199107115
767782457373328211199107115
767782457373328211199107115

!%!Õ!!%!Õ!s%!Õ!!q!Õ!?¡!¡ÿ!!%!Õ!!%!Õ!!%!Õ!!%!Õ!!%!Õ!!%!Õ!!%!Õ!!%!Õ!!%¡ÿ!!%!Õ!

Did you change

``````    Serial.begin(9600);
``````

to 2400 too? That looks like a baud rate mismatch.

Serial.print((char)buf*); // the received data is stored in buffer*
[/quote]

Thanks guys. I manage to make it work :) I would like to know the difference between the two lines of code given below. I know there are pointers used, but don't know what exactly it points to. Like whether it is pointing to the value in address or to the address itself.

``````vw_send((uint8_t *)&message, strlen(&message));

vw_send((uint8_t *)msg, strlen(msg));
``````

Thanks

I would like to know the difference between the two lines of code given below.

The difference is in how message and msg are defined. How are they defined?

I made the mentioned code. Its used to pick up the temperature using a sensor and then transmit the value to the receiver. The receiver will then print it on the serial monitor. But there is a problem the output is some characters which doesn’t make sense. I know the problem is with the code because the wireless transmission was working using the example in virtualwire guide and the temperature sensor was working on its own. So can someone please correct the error for me. Also by receiving the temperature (say for example temp = 25), how can I compare it with a threshold (say temp> 25) then turn an LED on.

``````//Temperature Wireless Transmitter Code
//Author: Yaameen Faisal

#include <VirtualWire.h>              //
int tempPin = A0; 	              // define pin A0 as temp sensor pin
int tempc = 0;                        // define and initialise temp variable
int samples;                       // define array to get more accurate temp
int i;

void setup()
{
Serial.begin(9600); 	        // setup serial communication with baud rate (bits per second) to diplay on serial monitor
vw_setup(2000);               //
vw_set_tx_pin(8);             //
pinMode(tempPin, INPUT);      // set pin A0 as input
}

void loop()
{
for(i = 0;i<=7;i++)	  // gets 8 samples of temp
{
samples[i] = ( 5.0 * analogRead(tempPin) * 100.0) / 1024.0;
tempc = tempc + samples[i];
delay(1000);
}

char tempData = tempc/8.0;       // the average temperature for better precision

vw_send((uint8_t *)&tempData, strlen(&tempData));
vw_wait_tx();

tempc = 0;
tempData = 0;

delay(500);   // delay before loop
}
``````
``````//Temperature Wireless Reciever Code
//Author: Yaameen Faisal

#include <VirtualWire.h>              //
int i;

void setup()
{
Serial.begin(9600); 	        // setup serial communication with baud rate (bits per second) to diplay on serial monitor
vw_set_rx_pin(7);
vw_setup(2000);
vw_rx_start();
}

void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];        //
uint8_t buflen = VW_MAX_MESSAGE_LEN;    //

for (i = 0; i < buflen; i++)
{
Serial.print((char)buf[i]);
Serial.print(" ");
}
}
``````

ÿ z ¼ ¯ Î ó ¨ ´ ~ Ä { ¿

``````    samples[i] = ( 5.0 * analogRead(tempPin) * 100.0) / 1024.0;
tempc = tempc + samples[i];
``````

Samples is never used again. There is no need to store the data in an array.

``````  char tempData = tempc/8.0;       // the average temperature for better precision
``````

This is not how to convert an int or float or any other variable to a string. (sprintf())

``````  vw_send((uint8_t *)&tempData, strlen(&tempData));
``````

tempData is not a string, so it should not be passed to a string function.

You need to fix the problems on the sender before anything on the receiver makes sense.