nRF24L01 Communication between Mega and Uno

Hello programmers and engineers!

I am having an issue setting up the wireless communication between my arduinos for a work related project.

I have a Mega2560 setup with multiple modules that will use its sensors to gather data when presented. The Mega then will display some information on an LCD, light up a few LEDs, sound a buzzer, and transmit some of that data to an Uno. The Uno will be setup to capture that data and write it to the serial monitor. Said data will be logged to a textile and be dumped into a database.

The wireless modules I am using are the high power nRF24L01 with external Antennas inserted within separate base modules that have a voltage regulator and bypass capacitors.

I am using the TMRh20 library that can be found here:

http://tmrh20.github.io/RF24/index.html

The minimal sketches that I ran were slightly altered version of the bare minimum examples sketches found here:

http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-ExampleSketches#bm1

Specifically, the "SimpleTransmit-01" and "SimpleReceive-01"

I cannot achieve communication using a Mega and an Uno using even a minimum sketch and trying various different channels. I have achieved it using a minimum sketch using just two Unos though, which leads me to believe that the issue is an incorrect pin layout on the Mega or a library incompatibility. I have found many different forums across the internet with many users having similar difficulties. At this point in the project, I am almost considering dropping these wifi modules and start investigating others.

If anyone has any insight or advice I would greatly appreciate it! I would greatly value your time and may consider discussing compensation for further advice and project help if anyone has any rock solid solutions.

Have a look at this Simple nRF24L01+ Tutorial. The examples will work fine with a Mega as long as you connect to the appropriate pins. On the Mega MOSI, MISO, SCK and SS are pins 51, 50, 52 and 53.

I am almost considering dropping these wifi modules

The nRF24 is not Wifi. And they work very well.

...R
PS. How far apart are your high-power nRF24s? I believe there can be problems if they are too close together. Over what distance do you want to transmit the data?

For testing purposes I just had them a few apart from each other, but the longer range will be needed for the final product.

I will try the tutorial you provided with that pin layout.

You said these devices are not wifi, to stop myself from sounding like an idiot in the future what would you call this type of communication?

Update -

I cant get your example sketch "Simple_transmit" to transmit on the Mega

Pin Layout

VCC - 3.3V
GND - GND
CN - 9
CSN - 53
MOSI - 51
MISO - 50
SCK - 52

The only modification I made to the example sketch is that I changed

#define CSN_PIN 10

to

#define CSN_PIN 53

Within the Serial Monitor, It displays the "SimpleTx Starting" message but stops there and does not display the "data sent".

BrentynHa:
what would you call this type of communication?

Wireless communication or radio communication would be fine. The nRF24s are 2.4GHz transceivers that are designed to talk to one another rather than as general wireless units so they are not compatible with WiFi or Bluetooth which also use 2.4GHz because it is not necessary to have a licence to transmit on that range of frequencies.

...R

Thank you for the clarification on the nomenclature!

While I know what this type of communication is called now, I am still struggling to get the Mega to transmit any information.

I do not mean to use this as a bump but did you see my reply under the last one you read, regarding me attempting to use your example sketches?

Make sure it's connected properly, like this....

....make sure to have spare nrf24L01+ modules, in case one of them (or more) is faulty.
....and have spare MEGA2560 boards, for similar reasons.
....and use this template code for communications tests...

// IMPORTANT!!! One arduino must be set to radioNumber = 1; while OTHER arduino must be set to radioNumber = 0;
// The ABOVE MUST be done manually!!!! So go to the line that says radioNumber = 1; or radioNumber = 0; and set accordingly!!

/*
* Getting Started example sketch for nRF24L01+ radios
* This is a very basic example of how to send data from one node to another
* Updated: Dec 2014 by TMRh20
*/

#include <SPI.h>
#include "RF24.h"

/****************** User Config ***************************/
/***      Set this radio as radio number 0 or 1         ***/
bool radioNumber = 1;

/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 9 & 53, which are CE & CSN pins  */
RF24 radio(9,53);
/**********************************************************/

byte addresses[][6] = {"1Node","2Node"};

// Used to control whether this node is sending or receiving
bool role = 0;

void setup() {
  Serial.begin(115200);
  Serial.println(F("RF24/examples/GettingStarted"));
  Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));
  
  radio.begin();

  // 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_LOW);
  
  // Open a writing and reading pipe on each radio, with opposite addresses
  if(radioNumber){
    radio.openWritingPipe(addresses[1]);
    radio.openReadingPipe(1,addresses[0]);
  }else{
    radio.openWritingPipe(addresses[0]);
    radio.openReadingPipe(1,addresses[1]);
  }
  
  // Start the radio listening for data
  radio.startListening();
}

void loop() {
  
  
/****************** Ping Out Role ***************************/  
if (role == 1)  {
    
    radio.stopListening();                                    // First, stop listening so we can talk.
    
    
    Serial.println(F("Now sending"));

    unsigned long time = micros();                             // Take the time, and send it.  This will block until complete
     if (!radio.write( &time, sizeof(unsigned long) )){
       Serial.println(F("failed"));
     }
        
    radio.startListening();                                    // Now, continue listening
    
    unsigned long started_waiting_at = micros();               // Set up a timeout period, get the current microseconds
    boolean timeout = false;                                   // Set up a variable to indicate if a response was received or not
    
    while ( ! radio.available() ){                             // While nothing is received
      if (micros() - started_waiting_at > 200000 ){            // If waited longer than 200ms, indicate timeout and exit while loop
          timeout = true;
          break;
      }      
    }
        
    if ( timeout ){                                             // Describe the results
        Serial.println(F("Failed, response timed out."));
    }else{
        unsigned long got_time;                                 // Grab the response, compare, and send to debugging spew
        radio.read( &got_time, sizeof(unsigned long) );
        unsigned long time = micros();
        
        // Spew it
        Serial.print(F("Sent "));
        Serial.print(time);
        Serial.print(F(", Got response "));
        Serial.print(got_time);
        Serial.print(F(", Round-trip delay "));
        Serial.print(time-got_time);
        Serial.println(F(" microseconds"));
    }

    // Try again 1s later
    delay(1000);
  }



/****************** Pong Back Role ***************************/

  if ( role == 0 )
  {
    unsigned long got_time;
    
    if( radio.available()){
                                                                    // Variable for the received timestamp
      while (radio.available()) {                                   // While there is data ready
        radio.read( &got_time, sizeof(unsigned long) );             // Get the payload
      }
     
      radio.stopListening();                                        // First, stop listening so we can talk   
      radio.write( &got_time, sizeof(unsigned long) );              // Send the final one back.      
      radio.startListening();                                       // Now, resume listening so we catch the next packets.     
      Serial.print(F("Sent response "));
      Serial.println(got_time);  
   }
 }




/****************** Change Roles via Serial Commands ***************************/

  if ( Serial.available() )
  {
    char c = toupper(Serial.read());
    if ( c == 'T' && role == 0 ){      
      Serial.println(F("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
      role = 1;                  // Become the primary transmitter (ping out)
    
   }else
    if ( c == 'R' && role == 1 ){
      Serial.println(F("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));      
       role = 0;                // Become the primary receiver (pong back)
       radio.startListening();
       
    }
  }


} // Loop

I just hooked up an Uno and Mega2560 with nrf24L01+ radios and they were able to communicate. In my case I used the RF24 library with the led_remote example and referenced the Arduino SPI Library page for pin numbers.

The fact that the two radios are communicating sure makes it look like the problem is between the radio and the Mega.

BrentynHa:
I do not mean to use this as a bump but did you see my reply under the last one you read, regarding me attempting to use your example sketches?

In this case a BUMP is fine because I had missed your Reply #3.

Please post the complete programs that YOU have uploaded to your two Arduinos and post some samples of the output.

Sometimes it is necessary to disconnect the Arduinos from the power to get the nRF24 to reset. The Arduino reset process does not reset the nRF24.

The high powered nRF24s almost certainly need an external 3.3v power supply because the Arduino 3.3v pin cannot provide enough current. Make sure that the 3.3v power has its GND connected to the Arduino GND.

...R

PS, for debugging purposes I think I have the last three paragraphs in the wrong order - start at the bottom :wink:

....make sure to have spare nrf24L01+ modules, in case one of them (or more) is faulty.
....and have spare MEGA2560 boards, for similar reasons.
....and use this template code for communications tests...

@Southpark I hadnt even considered that the Mega being faulty, im going to switch it out to see if that makes it any better, but I do not suspect it is the nrf24L01 boards because I have used the same exact modules to achieve Uno to Uno communication, which makes me suspect like Blue Eyes that the issue is somewhere between the nrf24L01 and the Mega.

@BlueEyes , thank you for confirming that you actually achieved communication, im going to buckle down and see what issue is causing this.

Please post the complete programs that YOU have uploaded to your two Arduinos and post some samples of the output.

Sometimes it is necessary to disconnect the Arduinos from the power to get the nRF24 to reset. The Arduino reset process does not reset the nRF24.

The high powered nRF24s almost certainly need an external 3.3v power supply because the Arduino 3.3v pin cannot provide enough current. Make sure that the 3.3v power has its GND connected to the Arduino GND.

...R

PS, for debugging purposes I think I have the last three paragraphs in the wrong order - start at the bottom :wink:

Im gonna run up that list and post my results, thank you for your time Robin it is very much appreciated! If I still cannot get this to work after this, you are probably gonna find nice little offer in your inbox.

Would the two separate units require their own designated power supplies?

Im going to order two of these and just use some female to male jumper cable to wire them to the 3.3v of the nfl2401 module and the GND of the arduinos unless one of you guys can recommend a better power supply.

That is the right sort of thing - but it seems expensive compared to the price of the core component - the LM317. You can also get dedicated 3.3v regulator chips - LD1117 or LD33

...R

SOLVED

Interestingly enough, once I provided the base modules I had with 5.5v power instead of the 3.3v, the Mega began transmitting data.

This is interesting because everything I read absolutely stated that these communication modules should never receive more than 3.3v or they'll likely be destroyed, yet it appears with the base modules that a stronger current is needed to give sufficient supply.

@Robin2

Ill likely have more questions throughout this project, would it be acceptable to PM you in the future with any problems I have? Im more than happy to offer compensation for a mentor.

BrentynHa:
Ill likely have more questions throughout this project, would it be acceptable to PM you in the future with any problems I have? Im more than happy to offer compensation for a mentor.

If you make a Post that I don't appear to have seen you may send me a PM with a link to the Post and a request to look at it. I don't give advice privately. When you ask your question in the public Forum other experienced people can also give advice and other beginners can learn along with you.

I am not interested in providing paid advice.

...R

Very humble of you, but I think I can understand why. Much appreciation for all the help, ill post all future questions in a new forum.

BrentynHa:
, ill post all future questions in a new forum.

If the information in this Thread is relevant to any further questions then just continue with this Thread. It is much easier to help when all the info for a problem is in one place.

…R

BrentynHa:
SOLVED

Interestingly enough, once I provided the base modules I had with 5.5v power instead of the 3.3v, the Mega began transmitting data.

Nicely done. Also, if you go back to the 3.3V (later). Could...if you wanted to....see what happens if you put a electrolytic capacitor across the supply pin of the NRF module and its ground. Eg.... 10 microFarad.
Also, additionally some people report that a 100 nF ceramic capacitor (in addition to the parallel 10 microFarad electrolytic) can help.

@ Southpark

Ive seen reports of that too and honestly I hoped to avoid soldering capacitors onto my chips as I have very little experience soldering at all and feared destroying my modules.

Yet I very well might do it anyway if I start detecting any hiccups with my current setup and ill report the results back here if I do.

Thank you for the suggestions and advice, very appreciated!

BrentynHa:
SOLVED

Interestingly enough, once I provided the base modules I had with 5.5v power instead of the 3.3v, the Mega began transmitting data.

This is interesting because everything I read absolutely stated that these communication modules should never receive more than 3.3v or they'll likely be destroyed, yet it appears with the base modules that a stronger current is needed to give sufficient supply.

@Robin2

Ill likely have more questions throughout this project, would it be acceptable to PM you in the future with any problems I have? Im more than happy to offer compensation for a mentor.

THANK YOU SO MUCH

I am so grateful