Go Down

Topic: How to use Virtual Wire Library (Read 2035 times) previous topic - next topic

RakshithNarun

I am doing a project using an analog stick
I want to transmit the processed data of the analog stick from one arduino to another using rf 433MHz modules
I would like to learn the code for the transmition and reception using this module
I am new to this.
Please help me in learning the this code
Thank You

Groove

I think I read somewhere tha VirtualWire had been superseded.
Per Arduino ad Astra

jremington

Start by learning to have two Arduinos communicate using VirtualWire and the simple examples provided.

When that works, come back with a more specific question.

RakshithNarun

Start by learning to have two Arduinos communicate using VirtualWire and the simple examples provided.

When that works, come back with a more specific question.
Well i am ready to learn so pls suggest me where i can find the examples
Thank you for your time

Groove

The examples provided by the library?

Hint: ensure that you understand the working of whichever library you chose by wiring the Arduinos together, as though the RF modules in place (i.e. use the same pins as the RF modules would use). That way, you can ensure the comms method is reliable before introducing the uncertainty of RF.
Per Arduino ad Astra

jremington

#5
Mar 05, 2017, 06:06 pm Last Edit: Mar 05, 2017, 06:14 pm by jremington
Quote
where i can find the examples
Provided with the library.

You will learn very, very slowly if you have to post a question to the forum for every tiny step along the way.

Here is a novel idea: try an internet search with "arduino virtualwire tutorial". You will be amazed at the wealth of information uncovered!

RakshithNarun

As you mentioned , I saw the example (only one) which came with the library, and also searched online for the instructions and their working

But now I would like to transmit numbers, the example which is given only sends characters

If i try to send the analog read value to print it asks for uint8_t *

So when i use it, only char can be transmitted, so the analog values are converted to wierd symbols which are being transmitted

Please help me

Groove

#7
Mar 11, 2017, 12:41 pm Last Edit: Mar 11, 2017, 12:59 pm by Groove
If you want help, you need to post the code you've written, otherwise it is all just guesswork.
You also need to post what you expect to happen with your code, and what you actually see happening.
Per Arduino ad Astra

jremington

There are many examples of transmitting numbers by VirtualWire on this forum.

RakshithNarun

As you asked
This the transmitter code
//transmitter
#include<VirtualWire.h>

void setup()
{
 Serial.begin(9600);
 Serial.println("Start");
 
 pinMode(A0,INPUT);
 
 vw_set_tx_pin(8);
 vw_set_ptt_inverted(true);
 vw_setup(2000);
}

void loop()
{
 int i=analogRead(A0);
 const char msg=i;
 Serial.print(i);
 Serial.println(msg);
 
 digitalWrite(13,HIGH);
 vw_send((uint8_t *)msg,1);
 vw_wait_tx();
 digitalWrite(13,LOW);
 delay(1000);
}

And this is the reciever code
//reciever
#include<VirtualWire.h>

void setup()
{
 Serial.begin(9600);
 Serial.println("setup");
 
 //recieving
 vw_set_rx_pin(3);
 vw_set_ptt_inverted(true);
 vw_setup(2000);
 vw_rx_start();
}

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, HIGH); // Flash a light to show received good message
// Message with a good checksum received, print it.
Serial.print("Got: ");

for (i = 0; i < buflen; i++)
{
   Serial.print(buf, HEX);
   Serial.print(' ');
}
Serial.println();
       digitalWrite(13, LOW);
   }
}

In the reciver serial monitor , I am not able to view anything being received

What i want to happen is that I have connected a potentiometer on the transmitter arduino, I want to receive it on the receiver side and alter the data to controll a motor

If the potentiometer value is less than 512, motor should rotate clockwise
If the potentiometer value is greater than 512, motor should rotate anti-clockwise

Please give me the code and explain how the code works
Thanks for your time

jremington

Please read "How to use this forum" and post your code properly.

RakshithNarun

As you asked
This the transmitter code
Code: [Select]
//transmitter
#include<VirtualWire.h>

void setup()
{
Serial.begin(9600);
Serial.println("Start");

pinMode(A0,INPUT);

vw_set_tx_pin(8);
vw_set_ptt_inverted(true);
vw_setup(2000);
}

void loop()
{
int i=analogRead(A0);
const char msg=i;
Serial.print(i);
Serial.println(msg);

digitalWrite(13,HIGH);
vw_send((uint8_t *)msg,1);
vw_wait_tx();
digitalWrite(13,LOW);
delay(1000);
}

And this is the reciever code
Code: [Select]
//reciever
#include<VirtualWire.h>

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

//recieving
vw_set_rx_pin(3);
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_rx_start();
}

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, HIGH); // Flash a light to show received good message
// Message with a good checksum received, print it.
Serial.print("Got: ");

for (i = 0; i < buflen; i++)
{
  Serial.print(buf, HEX);
  Serial.print(' ');
}
Serial.println();
      digitalWrite(13, LOW);
  }
}

In the reciver serial monitor , I am not able to view anything being received

What i want to happen is that I have connected a potentiometer on the transmitter arduino, I want to receive it on the receiver side and alter the data to controll a motor

If the potentiometer value is less than 512, motor should rotate clockwise
If the potentiometer value is greater than 512, motor should rotate anti-clockwise

Please give me the code and explain how the code works
Thanks for your time

jremington

#12
Mar 13, 2017, 06:17 pm Last Edit: Mar 13, 2017, 06:18 pm by jremington
Quote
In the reciver serial monitor , I am not able to view anything being received
Make sure that the provided examples work properly, before you make incorrect modifications to the programs.

This won't work as you expect it to:
Code: [Select]

int i=analogRead(A0);
 const char msg=i;

RakshithNarun

Then pls help me with the code for the following condition

if i have to take a data from a potentiometer at pin A0 of arduino, assign the data to a variable and send those value using transmitter, then receive the data at reciver side and reassign the obtained values to a new variable

Groove

Code: [Select]
int i=analogRead(A0);
Here, the "i" contains ten bits of information, stored in sixteen bits of RAM.

Why not send all sixteen bits? (And, it goes without saying, receive sixteen bits)
Per Arduino ad Astra

Go Up