About nRF24L01 program issues

I'm new to nrf24l01 . I have a two nrf24l01 they both works very well ,I tested them with a simple LED blinking program. Now I write a program for both transmitter and receiver to just send message and get a response for the message. Both the transmitter and receiver programs are given bellow (program works but not as I'm expected)

Transmitter

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

const byte CEpin=9;
const byte CSNpin=10;
RF24 radio(CEpin,CSNpin);
const byte address[][6]={"000001","000002"};
char ack[30],buf[]="hi....How are you?";
bool x;



void setup() {
  
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(address[1]);
  radio.openReadingPipe(1,address[0]);
  radio.setPayloadSize(30);
  radio.setChannel(83);
  radio.setDataRate(RF24_1MBPS);
  radio.setPALevel(RF24_PA_HIGH);
  
}

void loop() {
  delay(4);
  
  radio.stopListening(); 
  
  if(radio.write(buf,sizeof(buf)))
      Serial.println("MSG sent successfully");
  
  delay(6);
  
 radio.startListening();

 if(radio.available())
 {
  radio.read(ack,sizeof(ack));
  Serial.println(ack);
 }
  
 }
 

Receiver


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

const byte cepin=9;
const byte cspin=10;
RF24 mynrf(cepin,cspin);
const byte address[][6]={"000001","000002"};
char buf[50];
char response[]={"I'm fine"};


void setup() {
  
Serial.begin(9600);
mynrf.begin();
mynrf.openReadingPipe(1,address[0]);
mynrf.openWritingPipe(address[1]);
mynrf.setPayloadSize(30);
mynrf.setChannel(83);  

}

void loop() {
  
  delay(4);
  
  mynrf.startListening();
  
  if(mynrf.available())
  {
      mynrf.read(buf,sizeof(buf));
      Serial.println(buf); 
  } 

  delay(6);
      
  mynrf.stopListening();
      
  if(mynrf.write(response,sizeof(response)))
      Serial.println("response sent successfully\n\n\n");
      
}

I faced a lot of troubles

1.Without delay() [delay(4);delay(6);] it doesn't work

2.With setPayloadSize() and setChannel() it doesn't work

3.I can't set data rate at 250Kbps and 2Mbps which means setDataRate(RF24_1MBPS) only works

4.setPALevel(RF24_PA_HIGH) and setPALevel(RF24_PA_LOW) only works

5.It also doesn't give output as I'm expected. I attached a screenshot of my output bellow ( COM5 is Transmitter and COM4 is Receiver)

Transmitter and Receiver serial monitor output

These are the issues what I'm faced. Can any one explain it .

Please any one can suggest me a best tutorials and examples for nrf24lo1 .

These addresses are the same (only the first 5 byte count) and so you are misconfiguring the NRF.
It is not allowed to have two pipes opened on the same address.

Your try to sequence the transmissions and listening/sending states via delay is abysmal
and prone to fail.

You should listen all the time, unless you want to transmit something,
then switch to transmit, send the packet, and switch back to receiving directly after that.
No delay needed, any responses will be received.

now I corrected the address like

const byte address[][6]={"00001","00002"};

still now it doesn't works .

I don't want to put delay() in this program , I tried a lot without delay() it doesn't works.
Once I saw a program at https://howtomechatronics.com/tutorials/arduino/arduino-wireless-communication-nrf24l01-tutorial/ here they used a delay of 5milliseconds ( delay(5) ) after that it works but not fine....I'm not ok with the output response

No wonder, see above.

ok i will check it . What about other questions ?

still it doesn't works. Can you change the code and send it please.

It also does not work with them, or does it?

Default is a fixed payload size of 32, so I doubt your reasoning here.
I always use dynamic payloads.
The default channel could be too noisy, used, or whatever.

That sound fishy. You should be able to use all three on a NRF24L01+.

That's strange too, but could be caused by interference.

That is a problem of your expectation.
I'm astonished that the transmitter receives something at all.

Robin2 has a tutorial for the NRF24L01+ chips which works.

Which type of Arduino and NRF modules are you using, and how are the NRFs powered?

i am using Arduino Uno and nRF24L01 (not nRF24L01+) .nrf is powered by Arduino's 3.3v port

it works and gives a serial monitor out put like in the picture (what i posted)

I don't know how to use dynamic payloads. tell me how to use it

This seems contradictory.

https://nrf24.github.io/RF24/classRF24.html#a443888504975d7441d6452a09d09a8fa

Thank You

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.