Hi I'm new in the forum ,sorry,but need some help

hi guys, I'm new

As I was watching the forums I saw that this forum was too helpful, so i guessed i should join.
I have a project, that maybe there are many hobbyist too out there that has the same project. It's an RC plane not a quadcopter :slight_smile:

I started this project a couple of weeks from now or maybe almost a month.I learned arduino programming and tried to learn how to use arduino. Then I got better and tried to make my own sketch, it's still unoperational because I still have a problem on my receiver side, and this is where I'll need your help.
I'm sorry if there's already a thread about this.

I want to use an nRF24L01+ because it can transmit and receive data.

so my problem is I don't know how to address the data from my Arduino Uno ( the board reads it from joysticks and a potentiometer ) to an Arduino Nano. Well I came to realize that if my transmitter sends it in an array form ( I found on some tutorial ) how would my receiver recognize that the specific data that it received was for a specific output ( servos and motors )?

took me time to think and just can't take it out my mind, need some help.

thank you guys.. in advance.........

You found a tutorial. Great! Does the code from that tutorial work without modification? I know it doesn't exactly control your plane yet, but can you compile it and get the expected output from your Arduino?

That's the first step.

Then you might find other tutorials and try to incorporate those ideas into the one you started with. Make a change. Check that it outputs the results you expected.

If you have a problem understanding a particular tutorial, then post it here, using [ URL ] tags and maybe we can look at it and identify the problem.

hey man, thanks for the reply.
here’s my code

transmitter

#include <SPI.h>
#include <nRF24L01.h>           // number
#include <RF24.h>
// radio set up
#define CE_PIN 7
#define CSN_PIN 8

RF24 radio(7, 8);

const byte address[5] = {00001};

// joystick set up
#define joyY  A1          // first joystick pins
#define joyX  A2
#define joyYA  A3         // second joystick
#define pot A4             // potentiometer
// values
int sendval[4];
void setup()
{
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MAX);        // set the power amplifier level
  radio.setDataRate( RF24_250KBPS);
  radio.stopListening();                // set this module as a transmitter
}

void loop()
{
  void rudderread();
  void elevatorread();
  void aileronread();
  void throttleread();
}

void rudderread()
{
  sendval[0] = analogRead(joyY);
  sendval[0] = map(rudder, 0, 1023, 0, 179);
  radio.write(&sendval[0], sizeof(sendval[0]));
}

void elevatorread()
{
  sendval[1] = analogRead(joyX);
  sendval[1] = map(elevator, 0, 1023, 0, 179);
  radio.write(&sendval[1], sizeof(sendval[1]));
}

void aileronread()
{
  sendval[2] = analogRead(joyYA);
  sendval[2] = map(aileron, 0, 1023, 0, 179); 
  radio.write(&sendval[2], sizeof(sendval[2]) );
}

void throttleread()
{
  sendval[3] = analogRead(pot);
  sendval[3] = map(throttle, 0, 1023, 0, 179);
  radio.write(&sendval[3], sizeof(sendval[3]));
}

receiver, well this is it for now I still don’t know how

/* receive_2
 *  
 */


#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
// radio set up
RF24 radio(7, 8);           // find out if what type of pin and on which pin it is supposed to e attached

const byte address[5] = {00001}
//servo setup
Servo ruddservo;
Servo elevservo;
Servo ailserevo;

int rudder;
int elevator;
int aleron;
// the throttle set up is still missing

void setup()
{
  ruddservo.attach(A0);
  elevservo.attach(A1);
  ailservo.attach(A2);            // don't forget the throttle
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1, address);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate( Rf24_250KBPS);
  radio.startlistening();
}

void loop()
{
 void rudder()
 void elevator()
 void aileron()
 void throttle() 
}

void rudder()
{
  if(radio.available()){                
  }
}

how would my receiver recognize that the specific data that it received was for a specific output

There are basically 2 ways to do this

The first is to always send the data in the same order with the same timing and a delimiter between the channels. Something like
90,100,80,45 where 90 is the elevator value, 100 the aileron, 80 the rudder and 45 the throttle. However, should the data stream ever be interrupted then the receiver has no way of knowing which value belongs to which channel when the link is reestablished.

The second way is to add a channel identifier to the data like this
E90,A100,R80,T45
Now the receiver can parse the data and extract the required values attached to the channel identifier

It would also be a good idea to wrap the data in both start and end markers to make parsing easier and more robust

The data does not have to be sent as a single stream. It could be sent as individual values



To improve responsiveness you do not even have to send each value each time and could consider only sending values when they change.

sorry but I think this is where my skill meets the horizon, :slight_smile:

Can I ask how can I do that, or maybe you have some useful links about that? I would like to learn more.
I mean the second one...

thanks you

Have a look at this Simple nRF24L01+ Tutorial.

The examples do work so, as a first step, get them working without adding or subtracting anything.

If you want 2-way communication then the 2nd example (using the ackPayload technique) will probably be the simplest. I use it for controlling model trains.

...R

Have a look at the 'GettingStarted_HandlingData' example sketch and get it working. Don't worry about what data you are sending for now.

Note this bit in particular:

struct dataStruct{
  unsigned long _micros;
  float value;
}myData;

And in transmitter:

radio.write( &myData, sizeof(myData) )

And in receiver:

radio.read( &myData, sizeof(myData) )

You should see that it is defining a custom data structure in both sketches, and then sending and receiving the information is straightforward.

Once the basic sketch setup is working, you can think about modifying it for your particular application. For example, you might want to change it (in both tx and rx sketch) to:

struct dataStruct{
  int throttle;
  int aileron;
  int elevator;
  int rudder;
}myData;

This approach makes it very simple.
If you're not familar with structures, you can access their elements basically as normal

myData.throttle = analogRead(A1);
another_variable = myData.rudder;

In summary, get the basic example working and then you should be able to change it or use what you've learnt to get your application working.

hello “bms”
hope you read this, to anyone too please read

I tried to search the “gettingstrated” you post, and I saw this.
https://github.com/nRF24/RF24/blob/master/examples/GettingStarted_HandlingData/GettingStarted_HandlingData.ino

Is this it,;

Is this right.
instead of sending an array, it sends the data types that was declared above, so if the data type of an array is an integer you can only send integers, but if you use the technique at that tutorial you can send any types of variables.

and where’s the receiver side of that tutorial? can anyone show me?

@bms001, I like your approach. You and I may be the only heretics on this forum who think it's preferable to transfer data over radio links as structures, in binary. Especially when the data consists of multiple variables of different types. The libraries I have looked at all support this. And, they provide checksum (or CRC) to guard against data corruption. I just don't see the point of converting to ASCII, transmitting it (with framing or delimiters), and then parsing and converting back from ASCII at the receive side.

The only problem I've ever run into with this technique is transferring data between different processor types (AVR to ESP8266). It was easily fixed, just need to consider word size and structure packing.

gfvalvo:
@bms001, I like your approach. You and I may be the only heretics on this forum who think it's preferable to transfer data over radio links as structures, in binary. Especially when the data consists of multiple variables of different types.

I have never suggested otherwise. The examples in my Simple nRF24L01+ Tutorial can easily be adapted to deal with structs. And array is just a special form of a struct :slight_smile:

I remain convinced, however, that the first requirement with a wireless project is to get the most basic communication working reliably before trying to introduce the specific features of a project.

...R

jhave_21:
https://github.com/nRF24/RF24/blob/master/examples/GettingStarted_HandlingData/GettingStarted_HandlingData.ino

Is this it,;

Yes. It should also be in the 'Examples' folder of the RF24 library that you downloaded.

jhave_21:
Is this right.
instead of sending an array, it sends the data types that was declared above, so if the data type of an array is an integer you can only send integers, but if you use the technique at that tutorial you can send any types of variables.

Well ultimately it doesn't send any particular data types, it just sends 1s and 0s (actually I believe this is a major simplification of how radio data transmission works). The data structure just describes how to interpret the 1s and 0s. E.g. the first 16 bits are an integer, the next 32 bits are a float, the next 8 bits are an unsigned char etc.

jhave_21:
and where's the receiver side of that tutorial? can anyone show me?

It's the same sketch. Just change the line below so that one radio is 1, and the other is 0.

/****************** User Config ***************************/
/***      Set this radio as radio number 0 or 1         ***/
bool radioNumber = 1;

Robin2:
I remain convinced, however, that the first requirement with a wireless project is to get the most basic communication working reliably before trying to introduce the specific features of a project.

This is very good advice, and for the best chance of success I would suggest you do this. (I did)

gfvalvo:
And, they provide checksum (or CRC) to guard against data corruption.

I found that occasionally I received some funny data that (I'm pretty sure) I didn't send. So in the application in which I'm currently using the nRF24L01+ I have also added my own checksum to the structure. Based on my (limited) understanding of the CRC, I did not expect to have to do this, so I'm not ruling out that I've done something wrong somewhere.

This supprised me a little:

bms001:
And in receiver:

radio.read( &myData, sizeof(myData) )

The equivalent call for the RadioHead library would be:

uint8_t buf[MAX_BUFFER_SIZE], len;

if (rf69.recv(buf, &len)) {
  // We've recieved a valid packet containing 'len' bytes.
} else {
  // No packet received.
}

So, the call is not blocking and it returns the actual number of bytes in the received packet rather than me TELLING it how many bytes to look for.