hey guys, i am looing on sending data between 2 arduino's using rf modules. i am using the radio head ask library due to the type of rf module i am using. i have looked around nd cant seem to find how to send the data i want.can you help me?thnx in advance
I find it hard to believe that a library came without examples.
@suersaiyangod are you using the NRF24 modules? Here's the link that should have been included in the previous poster's comment: RadioHead: Examples
Have a browse through and see if any seem relevant to your project, read the comments in the code to get an idea of what they're doing, and if it makes sense give it a try. Also be sure to check that you are including the necessary libraries in your sketch...
There are likely more examples to look at on Instructables.com e.g. http://www.instructables.com/id/Arduino-NRF24L01-Simple-Bidirectional-Wireless-Com/
For more understanding of how packets work (the RadioHead library is designed to make packet communication simple), check out: What are Network Packets and How Do They Work? or for a more general view of internet/networked communications see: https://www.khanacademy.org/partner-content/code-org/internet-works
thnx ![]()
i am new to this library. and i dont seem to be able to understand its features. i am trying to send Valc in this code
//Define the input pins for the joystick and the variables to keep track of its state
int Vala = 0;
int Valb = 0;
int potpin = 0;
const int buttonPinf = 7;
const int buttonPinb = 6;
int Valc = 0;
int buttonStatef = 0;
int buttonStateb = 0;
const int transmit_pin = 12;
const int receive_pin = 11;
void setup()
{
Serial.begin(9600);
pinMode(buttonPinf, INPUT);
pinMode(buttonPinb, INPUT);
}
void loop()
{ //This will happen over and over and over and over again......
Valb = analogRead(potpin);
Valb = map(Valb, 0, 1023, 0, 180);
buttonStatef = digitalRead(buttonPinf);
buttonStateb = digitalRead(buttonPinb);
if(buttonStatef == HIGH && buttonStateb == HIGH)
{
Vala = 1000;
}
else if( buttonStatef == HIGH)
{
Vala = 2000;
}
else if ( buttonStateb == HIGH)
{
Vala = 3000;
}
else { Vala = 1000;}
{
Valc = Vala + Valb;
Serial.println(Valc);
}
}
and recieve the data(Valc) on this code
#include<Servo.h>
Servo myservo;
int val = 0;
int servoval = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myservo.attach(9);
myservo.write(90);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available() > 0)
{
val = Serial.read();
if(val >= 1000 && val < 4000)
{
Serial.write(val);
if(val >= 1000 && val < 2000)
{
servoval = val - 1000;
}
else if(val >= 2000 && val < 3000)
{
pinMode(7, HIGH);
servoval = val - 2000;
}
else if(val >= 3000 && val < 4000)
{
pinMode(6, HIGH);
servoval = val - 3000;
}
}
myservo.write(servoval);
}
}
im sorry if its too much trouble for you.thnx in advance
i am trying to send Valc in this code
I don't see that. Once you have computed Valc, all you do is print to the serial port.
The RadioHead library is NOT connected to the Serial port/pins.
yes but i dont know how to send and recieve messages in radiohead library. i'm using a 433mhz module so i am using the radiohead ask.will you teach me how to send the data.thnx in advance
i added the part for sending the data(Valc) through radiohead but then it is telling error that i cant convert char to int, i get it that u cant change it but then how will you do it. is there any kind of function to do that. thnx in advance
i added the part for sending the data
But didn't post the code.
but then it is telling error that i cant convert char to int
We do NOT want you paraphrasing errors. The compiler tells you EXACTLY which line it does not like. Share the EXACT message.
i'm sorry that i didnt share the code before. here is the error: "invalid conversion from 'int' to 'const char*' [-fpermissive]" and this is the line: const char *msg = Valc; .thnx in advance ![]()
//Define the input pins for the joystick and the variables to keep track of its state
#include<RH_ASK.h>
#include<SPI.h>
RH_ASK driver;
int Vala = 0;
int Valb = 0;
int potpin = 0;
const int buttonPinf = 7;
const int buttonPinb = 6;
int Valc = 0;
int buttonStatef = 0;
int buttonStateb = 0;
const int transmit_pin = 12;
const int receive_pin = 11;
void setup()
{
Serial.begin(9600);
pinMode(buttonPinf, INPUT);
pinMode(buttonPinb, INPUT);
}
void loop()
{ //This will happen over and over and over and over again......
Valb = analogRead(potpin);
Valb = map(Valb, 0, 1023, 0, 180);
buttonStatef = digitalRead(buttonPinf);
buttonStateb = digitalRead(buttonPinb);
if(buttonStatef == HIGH && buttonStateb == HIGH)
{
Vala = 1000;
}
else if( buttonStatef == HIGH)
{
Vala = 2000;
}
else if ( buttonStateb == HIGH)
{
Vala = 3000;
}
else { Vala = 1000;}
{
Valc = Vala + Valb;
const char *msg = Valc;
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
Serial.println(Valc);
}
}