I am sure i got the wiring correct for nrf 24l01 and the installed the tmrh20/nrf24 library correctly. But i couldnt communicate with them. Transmitter and Receiver code is attached along with the printDetails from the transmitter Serial Monitor. I dont know the cause for this???
I get this on my receiver serial moniter . But when i remove any cable from wiring it suddenlt print some dump values.What s wrong ???? I did the wiring perfectly fine.
#include <nRF24L01.h>
#include <printf.h>
#include <SPI.h>
#include "RF24.h"
//RF24 object (ce pin,cs pin)
RF24 radio(7,8);
byte addresses[][6] = {"1Node","2Node"};
void setup() {
Serial.begin(115200);
Serial.println("Receiver");
radio.begin();
printf_begin();
radio.printDetails();
radio.setChannel(110);
// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
radio.setPALevel(RF24_PA_MIN);
// Open a writing and reading pipe
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
radio.startListening();
}
void loop() {
unsigned char data;
if (radio.available()) {
radio.read(&data,sizeof(char));
}
radio.stopListening();
data++;
radio.write(&data,sizeof(char));
radio.startListening();
Serial.println(data);
} // Loop
Transmitter Code
#include <nRF24L01.h>
#include <printf.h>
#include <SPI.h>
#include "RF24.h"
//RF24 object (ce pin,cs pin)
RF24 radio(7,8);
byte addresses[][6] = {"1Node","2Node"};
void setup() {
Serial.begin(115200);
Serial.println("Transmitter");
radio.begin();
printf_begin();
radio.printDetails();
radio.setChannel(110);
// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
radio.setPALevel(RF24_PA_MIN);
// Open a writing and reading pipe
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[0]);
randomSeed(analogRead(A0));
}
void loop() {
unsigned char data = random(0,254);
radio.stopListening();
if (!radio.write(&data,sizeof(unsigned char))) {
Serial.println("heeeee");
}
radio.startListening();
unsigned long waittime = millis();
/****************** Pong Back Role ***************************/
if ( millis()-waittime>200 )
{
Serial.println("timeout");
return;
}
unsigned char dataRx;
radio.read(&dataRx,sizeof(unsigned char));
Serial.print(data);
Serial.print(" ");
Serial.print(dataRx);
Serial.print("\n");
delay(1000);
} // Loop
I found the solution. I used the adapters for the nrf24l01 and i powered them with 3.3 V. Then i powered it with 5V and tested with getting started example and it just worked fine (I think there is something wrong with the code i have uploaded because i tested it with 5V supply previously). By the way thanks for your advices. They were very helpful to a beginner like me