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
I think I read somewhere tha VirtualWire had been superseded.
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.
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.
Well i am ready to learn so pls suggest me where i can find the examples
Thank you for your time
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.
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!
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
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.
There are many examples of transmitting numbers by VirtualWire on this forum.
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
Please read "How to use this forum" and post your code properly.
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
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:
int i=analogRead(A0);
const char msg=i;
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
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)
You lost part of the source code, by copying from one post to another.
So what is the mistake i have done in my code
Should i change my code from
vw_send((uint8_t *)msg,1);
to
vw_send((uint16_t *)msg,1);
No.
You need to send both bytes of the int variable.
pls some help to write the code for the above said example
"Both" bytes means "two"