nRF24L01 communication back and forth

so i started today to study about nRF24l01 full time meaning im gonna read codes and learn how to
use it till i learn everything about it,

installed nRF24 lib. and started reading the code step by step and got a interesting question that
i didn't knew..

 // First, stop listening so we can talk.
    radio.stopListening();

    // Take the time, and send it.  This will block until complete
    unsigned long time = millis();
    printf("Now sending %lu...",time);
    bool ok = radio.write( &time, sizeof(unsigned long) );
    
    if (ok)
      printf("ok...");
    else
      printf("failed.\n\r");

    // Now, continue listening
    radio.startListening();

    // Wait here until we get a response, or timeout (250ms)
    unsigned long started_waiting_at = millis();

I got at this point and my question is..
every time i apply the stop and start listening code that means i can make my nRF
communication back and forth like 2 way communication? if yes what will happen if i don't apply a
(over) messsage at the end of each message so the other arduino/nRF will know that i stopped
transmitting and now im receiveing.

Other question:
Can i send and receive messages at the same time without stopping and starting my communication?

Tell us which library you used. There is a whole stack of these out there of varying degrees of quality.
The library (almost certainly) came with examples including simulated 2 way communication.

Domino60:
so i started today to study about nRF24l01 full time meaning im gonna read codes and learn how to
use it till i learn everything about it

You should start by reading the chips documentation nRF24L01P_Product_Specification_1_0.pdf full-time.

Try to understand it, if you don't get it on the first round, read it again, until you do.
It took me quite a couple of rounds, but all needed information is there.

You should start by reading the chips documentation nRF24L01P_Product_Specification_1_0.pdf full-time.

Try to understand it, if you don't get it on the first round, read it again, until you do.
It took me quite a couple of rounds, but all needed information is there.

It's a nice file but i don't see the point of reading it and learning it 100%

What i need is arduino code and examples.

Domino60:
It's a nice file but i don't see the point of reading it and learning it 100%

Too bad. Your starting posts questions are answered there.

It's a nice file but i don't see the point of reading it and learning it 100%

Just learn it to 80%. You can always go back and check details.

Domino60:
It's a nice file but i don't see the point of reading it and learning it 100%
. . .

But didn't you say this in your OP ?

Domino60:
so i started today to study about nRF24l01 full time meaning im gonna read codes and learn how to
use it till i learn everything about it
. . .

Yes i want to learn about nrf24l01 more and more but for start i'd like to play with the
NRF24 lib, i want to understand the simple communication 1st, after that make some beginner coding
and learn step by step, yes that pdf is usefull a lot and i saved it in my nrf24 file/project.

To learn something you need to start with something and make small steps as start.

Now my latest update, few min ago, i tested this code with Arduino uno and a atmena on board with crystal, resistors..etc

Transmiter:

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

 
void setup(void){
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);}
 
void loop(void){
  
  for (int x=0;x<255;x++){
  msg[0] = x;
  radio.write(msg, 1);
  }
}

Receiver:

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>

int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int red = 3;
int green = 5;
int redNeg = 4;
int greenNeg = 6;
int lastmsg = 1;
 
void setup(void){
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(redNeg, OUTPUT);
  pinMode(greenNeg, OUTPUT);
  digitalWrite(greenNeg, LOW);
  digitalWrite(redNeg, LOW);
  Serial.println("start");
}
 
void loop(void){
  if (radio.available()){
    bool done = false;  
      
    while (!done){
      done = radio.read(msg, 2); 
      if (msg[0] != lastmsg +1){
        digitalWrite(red, HIGH);
        digitalWrite(green,LOW);
        }    
      else {
       digitalWrite(red,LOW);
       digitalWrite(green,HIGH); 
        }
      lastmsg = msg[0];
      Serial.println(msg[0]);
     }
    }
    else {
      digitalWrite(red, HIGH);
      digitalWrite(green,LOW);
    }
}

i don't remember where i got this, i start testing many codes to see if my nrf's are working, as start u thought it's lib errors or something from code and after 1 hour of testing many codes i start re-checking
the wire pins and found out that i missplaced a pin :smiley:

sry for bad writing i cut today my index finger and it's hard to write with (left) middle finger while you are fast
typping person without looking the keyboard :smiley:

I got my nRF24s working with this Tutorial

I suggest you use the TMRh20 version of the RF24 library - it solves some problems from the ManiacBug version

The pair of programs in this link operate a simple back-and-forth communication. By using ackPayload there is no need for either of the nRF24s to switch roles.

...R

I got the same tutorial, i saw they changed and added few informations from their last update.

Why is there any bugs in the nRF24 lib right now?

I'm gonna take a look of your post back-forth com. That's exactly what I need a transciver communication
without any big delays, I need to control a device with complex tasks and I need a feed back of the device to see the real time data, if you know what I need.

Have anyone tested the nRF24L01 PA? in a long range field? I read that they support 1km (1000m) range
at 250kbps is that true?

Domino60:
Why is there any bugs in the nRF24 lib right now?

Use the TMRh20 version.

Unfortunately when he improved the ManiacBug library he used the same library name as ManiacBug. On my own PC i have given TMRh20's version a different name to avoid confusion.

...R

Robin2 I start reading your code from your post and I'd like to ask what exactly (bool rslt;) is for?

 bool rslt;
    rslt = radio.write( dataToSend, sizeof(dataToSend) );

I understant that you send the size of array data [0] and [1] at the same time (one after the other)
but what exactly rslt is for? I know it's true/false but why radio.write need that?

Domino60:
I understant that you send the size of array data [0] and [1] at the same time (one after the other)
but what exactly rslt is for? I know it's true/false but why radio.write need that?

RTFM

"Returns
True if the payload was delivered successfully false if not "

...R

ow so it's some kind of library function that determine that:

"Returns
True if the payload was delivered successfully false if not "

so every time if we send from 1st device the 2nd device send back a package and tells if the payload was
successfully delivered?

that means the

radio.setRetries(3,5); // delay, count

and

bool rslt;

are somehow connected together, I'm I right?

but it's really necessary to have that in the code? I mean one reason to not have that is because
we need to send a lot of data every 100ms for example, if we ask back for verification if the payload
was delivered or not we will waste a lot of time.

Let me give an example:
We have a RC car and we need to control the direction servo and the thrust of the motor, we don't need
a verification all the time if the payload was delivered, but for example only in the beginning, if the payload
was received from the car then start communication.

btw I asked in my last commend about the range of the nRF24L01 PA 2db antenna,
have you ever tested the range, above 200m on a open field?

Domino60:
btw I asked in my last commend about the range of the nRF24L01 PA 2db antenna,
have you ever tested the range, above 200m on a open field?

Have look at the Ultimate nRF24L01 range comparison.

I've seen his videos as well, it's pretty amazing about the range, of curse the there is a problem
with the angle of the antenna ..etc but I made the question here because I want some confirmation
that more people tested it :smiley:

You know what they say, if you head something just from a single person you can't believe what
he said till you head the same thing from others and confirm after that by yourself that it's true.

I'll try nowadays to make a perfect code to test in a open area to make a demonstration and
prove to myself + others that it's really working.

Domino60:
I'll try nowadays to make a perfect code to test in a open area to make a demonstration and prove to myself + others that it's really working.

Without knowing the datasheet by heart? Amusing.

Without knowing the datasheet by heart? Amusing.

what exactly you want to say? I got 2x perfect (tested) nRF's I'm gonna make a simple code
at 250kbps with the packets I need and test if the range it's working as I need.

What exactly should I know about the datasheet that maybe I'll need?
I already know the basics how to set up pins/ code channels, speed, send packets so gonna make
a simple code for range testing. I'm a beginner with nRF so I'll start with beginner stuffs.

Domino60:
I mean one reason to not have that is because we need to send a lot of data every 100ms for example,

Get real. 100ms is FOREVER.

If you want to understand the device you need to read the Library documentation and the nRF24L01+ datasheet carefully.

...R

Get real. 100ms is FOREVER.

what do you mean by that?

If you want to understand the device you need to read the Library documentation and the nRF24L01+ datasheet carefully.

Ok i'll start reading the datasheet Whandall gave me