0

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 .

1 Answer 1

1

Two things:

  1. nRF24L01 is only half duplex. You can't send and receive at the same time. You must send only briefly and then spend some time listening for the response. With no delays there is no time to listen. It's like it's sat there with its fingers in its ears going "la la la la la" all the time.

  2. You're spamming out a "response" all the time. The same situation occurs. You have two transmitters that rarely listen for anything. You should only send your response if you have received an original request.

5
  • I can't catch you clearly ......please explain briefly
    – nskaran
    Aug 25, 2021 at 10:21
  • i think nRF24L01 can support full duplex (two way communication)
    – nskaran
    Aug 25, 2021 at 10:23
  • Read your code and follow the flow of it logically. It's very clear.
    – Majenko
    Aug 25, 2021 at 10:23
  • 2
    It can do two way, but not "full duplex". Only "half duplex". It can transmit and it can receive, but it cannot do both at the same time.
    – Majenko
    Aug 25, 2021 at 10:23
  • @nskaran, as in like a "walkie-talkie", or marine VHF, or any number similar systems. Hence all the human protocols carried out to keep people from talking at the same time or for a long time.
    – timemage
    Aug 25, 2021 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.