Wireless Control Esc speed using NRF24l01

After searching a lot on the net for days unfortunately I am not able to get the code for controlling brushless motors speed with nrf and potentiometer. I am making an arduino based airplane with servos controlled using joystick and nrf for long range and cheap budget but haven't got the code for bldc control with nrf . PLEASE help

I thought you already had an answer to that question in your Thread from last May

Since then I have written this Simple nRF24L01+ Tutorial. I use code like the second example to control my model trains. If you only need one-way communication the first example should be sufficient.

Presumably your ESC is controlled using the Servo library and if so you should send the appropriate value for Servo.write() or Servo.writeMicroseconds() from one Arduino to the other.

...R

does that mean i need to modify a code that is for wireless controlling a servo with nrf24l01 for esc.

TRANSMITTER CODE
#include <SPI.h>

#include "RF24.h"

int msg[1]; //SCK -> 13//MISO -> 12//MOSI -> 11//CSN -> 7//CE -> 8

RF24 radio(8,7);

const uint64_t pipe = 0xE8E8F0F0E1LL;

int potpin = 0;

int val;

void setup(void)

{

radio.begin();

radio.openWritingPipe(pipe);

}

void loop(void)

{

val = analogRead(potpin);

val = map(val, 0, 1023, 0, 179);

msg[0] = val;

radio.write(msg, 1);

}

can this code be modified for esc

RECIEVER CODE
#include <Servo.h>

#include <SPI.h>

#include "RF24.h"

Servo myservo;

//SCK -> 13//MISO -> 12//MOSI -> 11//CSN -> 7//CE -> 8

RF24 radio(8,7);

const uint64_t pipe = 0xE8E8F0F0E1LL;

int msg[1];

void setup()

{

myservo.attach(9);

radio.begin();

radio.openReadingPipe(1,pipe);

radio.startListening();

}

void loop()

{

if (radio.available())

{

bool done = false;

while (!done)

{

done = radio.read(msg, 1);

myservo.write (msg[0]);

}

} Servo.h>}

here are some changes i made . Please check if there are errors or changes that have to be made.THANKS IN ADVANCE

TRANSMITTER CODE
#include <SPI.h>

#include "RF24.h"

int msg[1]; //SCK -> 13//MISO -> 12//MOSI -> 11//CSN -> 7//CE -> 8

RF24 radio(8,7);

const uint64_t pipe = 0xE8E8F0F0E1LL;

int throttlepin = 0;

int throttle;

void setup(void)

{

radio.begin();

radio.openWritingPipe(pipe);

}

void loop(void)

{

throttle = analogRead(throttlepin);

throttle = map(throttle, 0, 1023, 0, 179);

msg[0] = throttle;

radio.write(msg, 1);

}
RECIEVER CODE
#include <Servo.h>

#include <SPI.h>

#include "RF24.h"

Servo esc;

//SCK -> 13//MISO -> 12//MOSI -> 11//CSN -> 7//CE -> 8

RF24 radio(8,7);

const uint64_t pipe = 0xE8E8F0F0E1LL;

int msg[1];

void setup()

{

esc.attach(9);

radio.begin();

radio.openReadingPipe(1,pipe);

radio.startListening();

}

void loop()

{

if (radio.available())

{

bool done = false;

while (!done)

{

done = radio.read(msg, 1);

esc.write (msg[0]);

}

} Servo.h>}

Archut:
here are some changes i made . Please check if there are errors or changes that have to be made.T

Try it first, There is no point in me looking at it if it works. And if it does not work please report the compiler messages or the results of running the program.

The Arduino system is great for learning-by-doing

...R

If I use nrf24l01 built in antenna with nrf24l01 external antenna would the range be 1100m or would I suffer some problems cause I need to buy those before testing the code

I have only used the modules with the PCB antenna so I can't answer your question. In a test they were working fine at 110m outdoors.

Those modules are cheap so I suggest you get your code working with them and then explore the longer range with the high power modules.

...R

Do they give range of 110m or 1100m or 1km

Archut:
Do they give range of 110m or 1100m or 1km

The only information available to me is already in Reply #6

I suggest you don't worry about the difference between 1100 m and 1 km

...R

sorry for this but in that case which would be better nrf or rf433 ? Sorry again for such question

AFAIK the nRF24 would provide a very much more reliable communication link than the usual 433MHz modules - but I have never used 433MHz wireless.

AFAIK the Spectrum brand Radio Control units use Cypress 2.4GHz chips which are functionally similar to (but not compatible with) the Nordic chips in the nRF24. For all I know some of the othe RC brands use Nordic chips. Maybe you would get useful information on some of the model airplane forums.

Why not just do some tests and see how you get on. If nothing else you could provide some useful information that would help other Arduino Forum readers.

This Youtube video about nRF24 range may be of interest

...R

hey there .I m getting error in compiling reciever==>""/Users/architbubber/Documents/Arduino/reciever_servo/reciever_servo.ino: In function 'void loop()':
reciever_servo:45: error: void value not ignored as it ought to be
done = radio.read(msg, 1);
^
reciever_servo:51: error: expected unqualified-id before '.' token
} Servo.h>}
^
exit status 1
void value not ignored as it ought to be
<==""

Archut:
hey there .I m getting error in compiling

What version of the RF24 library are you using?

Post the complete program that YOU are trying to compile.

...R

RF24 1.17

#include <Servo.h>

#include <SPI.h>

#include "RF24.h"

Servo myservo;

//SCK -> 13//MISO -> 12//MOSI -> 11//CSN -> 7//CE -> 8

RF24 radio(8,7);

const uint64_t pipe = 0xE8E8F0F0E1LL;

int msg[1];

void setup()

{

myservo.attach(9);

radio.begin();

radio.openReadingPipe(1,pipe);

radio.startListening();

}

void loop()

{

if (radio.available())

{

bool done = false;

while (!done)

{

done = radio.read(msg, 1);

myservo.write (msg[0]);

}

} Servo.h>}

Archut:
RF24 1.17

That is not enough information - unfortunately the alternative libraries are not easily identified by number. Please post a link to the web page from where you downloaded it.

...R

You seem to be a man of few words. We don't charge for chat :slight_smile:

I think the problem is that your program was written for the earlier (and inferior) ManiacBug library. You need to read the library documentation carefully when you get that sort of error.

Try changing this line

done = radio.read(msg, 1);

to

radio.read(msg, 1);

...R

well i am not able to have a communication set up b/w 2 uno's with nrf . Tried a lot used 4 different arduino's (got 1 from a friend) bought 4 nrf module(one is antenna one) but all i am not able to get anything except disappointment. >:(

Robin2:
You seem to be a man of few words. We don't charge for chat :slight_smile:

I think the problem is that your program was written for the earlier (and inferior) ManiacBug library. You need to read the library documentation carefully when you get that sort of error.

Try changing this line

done = radio.read(msg, 1);

to

radio.read(msg, 1);

...R

this helped uploading the program but didn't work

Archut:
this helped uploading the program but didn't work

Still very restrained in your use of words :slight_smile:

Post the programs that YOU have uploaded to your Arduinos.
Post the output that each program produces.

...R