I have tried several projects with the NRF24L01, and none have been successful. I tested them with Arduino, and the test showed that the devices themselves work. The connections are all good, but I cannot say without a shadow of a doubt it isn't the circuit. I recently replaced the "RF24" library that was installed with the TMRh20 one off GitHub. The code to one of the projects is below. It is a simple circuit to turn on a LED, that i got off Instructables. The transmitter circuit is on an Arduino Mega, and the receiver circuit is on an Arduino Uno. Hoping someone can point me in the right direction to figure out what and where the problem is.
Here is the transmitter code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define buttonPin1 3
int buttonState1 = 0;
RF24 radio(9, 8); // CE, CSN
const byte address[6] = "00002";
void setup() {
pinMode(buttonPin1, INPUT_PULLUP);
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
if (buttonState1 == 1)
{
buttonState1 = 1;
}
else if (buttonState1 == 0)
{
buttonState1 = 0;
}
Serial.print(buttonState1);
radio.write(&buttonState1, sizeof(buttonState1));
}
And the receiver code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define led1 3
int buttonState = 0;
RF24 radio(9, 8); // CE, CSN
const byte address[6] = "00002";
void setup() {
Serial.begin(9600);
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
delay(100);
}
void loop() {
radio.startListening();
while (!radio.available());
radio.read(&buttonState, sizeof(buttonState));
Serial.println(buttonState);
delay (100);
if (buttonState == 1) {
digitalWrite(led1, LOW);
}
else if (buttonState == 0) {
digitalWrite(led1, HIGH);
}
}