I am having some issues getting the nRF24l01+ transceivers to communicate correctly. I have them set up with two Mega 2560's. My code is below and the goal is to push a button on one breadboard to make two sets of LED change from green when button not pushed to red when button is pushed. My code is listed below:
/*******transmit******/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 22;
int LEDr = 11;
int LEDg = 12;
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
pinMode(LEDg, OUTPUT);
pinMode(LEDr, OUTPUT);}
void loop(void){
if (digitalRead(SW1) == HIGH){
msg[0] = 111;
radio.write(msg, 111);
Serial.println("Button Pushed");
digitalWrite(LEDg,LOW);
digitalWrite(LEDr,HIGH);}
else{
digitalWrite(LEDg,HIGH);
digitalWrite(LEDr,LOW);}
delay(100);}
/********receive*******/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LEDr = 3;
int LEDg = 4;
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(LEDg, OUTPUT);
pinMode(LEDr, OUTPUT);}
void loop(void){
if (radio.available()){
bool done = false;
while (!done){
radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 111){delay(10);
digitalWrite(LEDg, LOW);
digitalWrite(LEDr, HIGH);}
else {
digitalWrite(LEDg, HIGH);
digitalWrite(LEDr, LOW);}
delay(10);}
}
else{Serial.println("No radio available");}}
When I open up the serial monitor on the receive all I get is the value 255 regardless of whether the button is pushed. The green lights on both boards are lit up when the button is not pushed. When the button is pushed then the red light on the transmit side only lights up.
Logic tells me, that given the receive code, and the fact that the green led is lit up then the radios are communicating but how do I get the proper message sent to the receive board to make the red light turn on.... Also one other thing is that the CE/CSN pins are connected at (8,53) physically but the code states that they should be at (9,10). If I change the code to (8,53), the communication stops and I get "No Radio Available" on the receiver.
This is driving me nuts on multiple levels. Any feedback would be fantastic
