Send and Receive Values through Radio Communication

I am trying to send and receive values using two Arduino Megas and two NRF24L01 radio antennas. I can transmit a value and receive it, but cannot send a value back. How do I change the roles in order to do this?
Due to the character limit, I cannot attach the library here, but I will try to do it in the comments.
I have been stuck on this for too long and not sure what to do, so any help would be greatly appreciated.

(This is my first post, so forgive me if I did not do something correctly)

/*********************************************************************
**   SPI-compatible                                                 **
**   CE - to digital pin 9                                          **
**   CSN - to digital pin 10  (SS pin)                               **
**   SCK - to digital pin 13 (SCK pin)                              **
**   MOSI - to digital pin 11 (MOSI pin)                            **
**   MISO - to digital pin 12 (MISO pin)                            **
**   IRQ - to digital pin 8 (MISO pin)                             **
*********************************************************************/
#include "NRF24L01.h"

#define TX_ADR_WIDTH    5   // 5 unsigned chars TX(RX) address width
#define TX_PLOAD_WIDTH  4  // 32 unsigned chars TX payload
unsigned char RX_ADDRESS[TX_ADR_WIDTH]  = 
{
  0x34,0x43,0x10,0x10,0x01
};

unsigned char TX_ADDRESS[TX_ADR_WIDTH]  = 
{
    0x34,0x43,0x10,0x10,0x01
};

uint8_t rx_buf[TX_PLOAD_WIDTH] = {0};
uint8_t tx_buf[TX_PLOAD_WIDTH] = {0};

union u_tag {
   float temp_float ; 
   uint8_t temp_byte[4] ;
} u;


//set role: 0 - Transmit / 1 - Recieve
int role = 0;

void setup()  {
    Serial.begin(230400);
    NRF_Init();                        // Initialize IO     
}


void loop() {
  
/////////Transmmit/////////
    if (role == 0) {
      NRF_SeTxMode();
      
      u.temp_float = 170.687;
      tx_buf[0] = u.temp_byte[0];
      tx_buf[1] = u.temp_byte[1];
      tx_buf[2] = u.temp_byte[2];
      tx_buf[3] = u.temp_byte[3];
  
      do  { 
        NRF_Send(tx_buf);
      }
      while(!NRF_CheckAck()); 
    }

/////////Recieve/////////
   if (role == 1) {
      NRF_SetRxMode();

    if(NRF_Receive(rx_buf))
    {
        Serial.print("RX = ");
        for(int i = 0; i < 5; i++)
        {
            Serial.print(rx_buf[i]);
            u.temp_byte[i];
            Serial.print(",");
        }
        u.temp_byte[0] = rx_buf[0];
        u.temp_byte[1] = rx_buf[1];
        u.temp_byte[2] = rx_buf[2];
        u.temp_byte[3] = rx_buf[3];

        float Load_cell = u.temp_float;
//        Load_cell = 123.0825;
        Serial.print("Load cell:  ");
        Serial.print(Load_cell);
        Serial.println();


        
        for(int i = 0; i < 5; i++)
            rx_buf[i] = 0;
    }
//    delay(500);
  }
}

Have you seen Robin2's simple rf24 tutorial?

Yeah I have tried using the Simple Tx and Rx before, but there are issues when using two mega's and it will not work

I don't know what you mean by "issues when using two mega's". If you connect the radios correctly, taking into account that the SPI pins are different on a Mega, they should work the same as on Unos. See this page.

ssutherland1:
Yeah I have tried using the Simple Tx and Rx before, but there are issues when using two mega's and it will not work

There is no reason why my examples won't work with two Megas. Once you have the correct SPI connections there is no operating difference between a Mega and an Uno as far as the nRF24 is concerned. On a Mega pin 53 is the SPI equivalent of pin 10 on an Uno and should be set as OUTPUT even if it is not being used with the nRF24

I have a Mega clone that cannot provide enough 3.3v power for an nRF24. If you think that may be your problem try powering the nRF24s with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND,

If you still have a problem, start with the Simple Tx and RX from my Tutorial and post the two programs that YOU have uploaded to your two Megas and also post a sample of the output from each Mega.

...R

I believe the issue is, like Robin said, that either one or both of the boards are Mega clones and cannot provide enough power.
This is how I have it hooked up now:
** CE - to digital pin 9
** CSN - to digital pin 10 (SS pin)
** SCK - to digital pin 13 (SCK pin)
** MOSI - to digital pin 11 (MOSI pin)
** MISO - to digital pin 12 (MISO pin)
** IRQ - to digital pin 8 (MISO pin)

Robin2:
try powering the nRF24s with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND

I will try this, but I have to get AA batteries first.
Is it possible to switch the CE pin on and off in order to switch roles?

Are you using the Megas? If so, the radios will not work with hardware SPI if that is how they are wired.

groundFungus:
Are you using the Megas? If so, the radios will not work with hardware SPI if that is how they are wired.

What do you mean the radios will not work? I am using two megas and can transmit numbers through the radio using this code
Master

#include "NRF24L01.h"

#define TX_ADR_WIDTH    5   // 5 unsigned chars TX(RX) address width
#define TX_PLOAD_WIDTH  4  // 32 unsigned chars TX payload
unsigned char RX_ADDRESS[TX_ADR_WIDTH]  = 
{
  0x34,0x43,0x10,0x10,0x01
};
uint8_t rx_buf[TX_PLOAD_WIDTH] = {0};
uint8_t tx_buf[TX_PLOAD_WIDTH] = {0};

union u_tag {
   float temp_float ; 
   uint8_t temp_byte[4] ;
} u;

void setup()
{
    Serial.begin(230400);
    NRF_Init();                        // Initialize IO     
    NRF_SetRxMode();
    Serial.println("RX_Mode start...");
}

void loop()
{
    NRF_SetRxMode();
    if(NRF_Receive(rx_buf))
    {
        Serial.print("RX = ");
        for(int i = 0; i < 4; i++)
        {
            Serial.print(rx_buf[i]);
            u.temp_byte[i];
            Serial.print(",");
        }
        u.temp_byte[0] = rx_buf[0];
        u.temp_byte[1] = rx_buf[1];
        u.temp_byte[2] = rx_buf[2];
        u.temp_byte[3] = rx_buf[3];
        float Load_cell = u.temp_float;
//        Load_cell = 123.0825;
        Serial.print("         ");
        Serial.print(Load_cell);
        Serial.println();
        for(int i = 0; i < 4; i++)
            rx_buf[i] = 0;
    }
//    delay(500);
}

Node

#include "NRF24L01.h"

#define TX_ADR_WIDTH    5   // 5 unsigned chars TX(RX) address width
#define TX_PLOAD_WIDTH  4   // 3 unsigned chars TX payload
unsigned char TX_ADDRESS[TX_ADR_WIDTH]  = 
{
    0x34,0x43,0x10,0x10,0x01
}; 
uint8_t rx_buf[TX_PLOAD_WIDTH] = {0}; // initialize value
uint8_t tx_buf[TX_PLOAD_WIDTH] = {0};

union u_tag {
   float temp_float ; 
   uint8_t temp_byte[4] ;
} u;


void setup()
{
    Serial.begin(9600);
    u.temp_float = 374.5868;
    tx_buf[0] = u.temp_byte[0];
    tx_buf[1] = u.temp_byte[1];
    tx_buf[2] = u.temp_byte[2];
    tx_buf[3] = u.temp_byte[3];

    NRF_Init();                        // Initialize IO port
    Serial.println("TX_Mode Start");    
}

void loop()
{
    NRF_SeTxMode();
    do
    { 
        NRF_Send(tx_buf);
    }
 while(!NRF_CheckAck());
}

ssutherland1:
Is it possible to switch the CE pin on and off in order to switch roles?

One of the examples in my Tutorial shows how to switch roles - basically change the device that does the listening.

CE is used to tell the nRF24 to transmit - it is normally handled transparently by the library.

...R