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 .