Hi I have an arduino uno, an arduino nano, two nrf24l01, one pot and a servo.
I want to control the servo wireless via pot and nrf24l01 but something is wrong with my code. Please help me..
Thanks
Transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
#define JOYSTICK_X A0
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int joystick[1];
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
}
void loop()
{
joystick[0] = analogRead(JOYSTICK_X);
radio.write( joystick, sizeof(joystick) );
}
Receiver:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#define CE_PIN 9
#define CSN_PIN 10
int val;
Servo myservo;
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int joystick[1];
void setup()
{
myservo.attach(2);
Serial.begin(9600);
delay(1000);
Serial.println("Nrf24L01 Receiver Starting");
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();;
}
void loop()
{
if ( radio.available() )
{
bool done = false;
while (!done)
{
done = radio.read( joystick, sizeof(joystick) );
Serial.print("X = ");
Serial.print(joystick[0]);
Serial.print("\n");
val = joystick[0];
val = map(val, 0, 1023, 0, 179);
myservo.write(val);
}
}
else
{
Serial.println("NO radio available");
}
}
What is wrong with your code?
Code is right but I had arduino nano as receiver and servo need lot of mah as a resalt it lags
thanks for your reply
Use a separate power supply for the servo and connect the grounds together.
i'v been trying this but the receiver wont compile, (expected ')' before ';' token)
not sure what to do the line thats hightlighted says "done= radio.read( joystick, sizeof(joystick);
its about the 15th line from the bottom
anyone have any idea what i need to put in front, any help much appriectiated
cheers
That line needs another parenthesis on the end.
yip got that one, thanks mate.. still not working so i recopied the receiver code again, and now it says "void value not ignored as ought to be"
damn i was hoping it would work, any suggestions on that??
I'v been at this one for hours tried heaps of stuff still stuck on 1 line
MarkT
April 5, 2017, 11:19am
9
If you don't post the code and errors you will have to figure them out for yourself!
Tip: ignore all errors except the first, fix that and compile again - sometimes an error triggers more
errors which can be confusing, so deal with the first one first.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#define CE_PIN 9
#define CSN_PIN 10
int val;
Servo myservo;
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int joystick[1];
void setup()
{
myservo.attach(2);
Serial.begin(9600);
delay(1000);
Serial.println("Nrf24L01 Receiver Starting");
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();;
}
void loop()
{
if ( radio.available() )
{
bool done = false;
while (!done)
{
done = radio.read( joystick, sizeof(joystick) );
Serial.print("X = ");
Serial.print(joystick[0]);
Serial.print("\n");
val = joystick[0];
val = map(val, 0, 1023, 0, 179);
myservo.write(val);
}
}
else
{
Serial.println("NO radio available");
}
}
done = radio.read( joystick, sizeof(joystick) );
about the 14th line from the bottom i get this error message when trying to compile
"void value not ignored as ought to be"
any ideas on that
matty700:
done = radio.read( joystick, sizeof(joystick) );
about the 14th line from the bottom i get this error message when trying to compile
"void value not ignored as ought to be"
any ideas on that
Yes, shure.
Don't try use the return value of a function that does not have one.
(like the code you copied from somewhere, that uses an old libraries interface)
so how much of this do i have to change for it to work
I can only repeat:
Whandall:
Don't try use the return value of a function that does not have one.
matty700:
so how much of this do i have to change for it to work
Changing all those mishandlings could make your code compile, whether it will "work" is a totally different story.
i'v been on this for weeks now and still having problems with it.