nRF24L01's and Mega 2560's

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

Please explain what you think

 radio.write(msg, 111);

does, or should do.

Why do you think hammering out these junk packets unmoderated (back to back) makes sense?
You are slowing it down a little by blocking on Serial, but...

if (radio.available()){

This returns true if a packet is available, not if the module is functional.
So printing 'I did not receive a packet since the last check' does nothing more than flooding Serial.

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);
  }

You will never leave that while loop and keep reading non existing packets.
Reading one byte of a two byte integer is rather strange.
What are the delays for?

You formatting is strange too, try Ctrl-T.

The radio.Write should be sending data to the receiver to tell it that the button has been pushed on the transceiver. That's my understanding anyway.

I am very new to arduino and programming so forgive me if the code or my descriptions of what this set up should do doesnt quite make sense.

I used Ctrl+T and it appears that fixed some of the formatting.

Any thoughts of why the data isnt being transmitted or not being received?

Here is a picture of what I currently have set up…

I would suggest adding a capacitor directly on the module power pins.
Sometimes it is not neccessary, most of the times it helps running these modules.
I have used values between 2,2 and 25 µF with good results.

From the header file:

 bool write( const void* buf, uint8_t len );

compare that to your usage.

radio.write(msg, 111);

The maximum packet size is 32.

The library will make it a 32 byte packet (pure luck), at least both bytes of the integer are transmitted.
Your receive reads one byte of that packet and throws away the rest, if one of the many calls to read
happens not to fail. I would call this function only if a packet is available.

I don't know whether the library writes junk to the target if no packet is available.
I have no idea what the chip does if it is mistreated like this (if the library passes the request to it).

The one element integer array that you are using saves the & in the function call, but is rather pointless apart from that.

If you are very new to the Arduino environment I would suggest that you start with more basic projects.

Learn about datatypes and their sizes.
Learn how to moderate things, without delays or blocking on Serial.
(It is not very sensible trying to send the keystate 1000+ times a second.)

Before trying to use nRFs, study the datasheet, you will probably need a couple of rounds going through it, I needed many.
Study the library you want to use, play with the examples provided.

One of the problems I have with running other projects first is that this is a task that was given to me at work. I feel like I am real close to having it working but there's few lines of code that need adjusting like you mentioned.

With regards to the packets... are you saying that I cant use the value as high as 111? And about packets being available or not... are you saying that I should turn the receive LED (red) on only when there is a packet available? I thought thats what I had written already.

Then also the

bool wrote( const void* bug, uint8_t len);

Do I use that as is, or do I need to put the pipe address in there?

tdickerson09:
I feel like I am real close to having it working

No. Your level of understanding is obviously to low to manage that task.

I will work on the task that you were given, if you pass me your wages.

I’m trying to learn this stuff at the same time of performing the task. Is there anyone else that is able to break it down and be more helpful?

I gave you a coarse roadmap to learn,
I pointed out some of the biggest errors in your code.

I feel we have a different interpretation of the word 'helpful'.

Good luck!

My interpretation of being helpful is simply answering the questions that I have without degrading my intelligence.