[SOLVED] NRF24L01+ Modules not working with basic example sketches

Hello All, this is my first post. I've been reading through the forum for a while as I have worked through my projects. I am, however, stumped. For the life of me I cannot get two NRF24L01+ modules working correctly and been working on it for a week which includes returning one set of modules thinking they were faulty. I got a new set and have had the same problems so it has to be me or the setup.

My setup is two arduino nanos each with a NRF24L01+ module from Addicore. I have both NRF24L01+ modules powered from a variable DC power supply set to 3.3V, I also have a 22microFarad capacitor across the terminals of the power supply. I have powered both arduinos through the USB but have also powered one of the arduinos separately on another power supply set to 9V with no change in performance. I don't believe my issue is with the power input.

The connections for both arduinos are the same and follow the example at: http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo.

GND ---- GND
VCC ---- 3.3V
CE ---- Pin 9
CSN ---- Pin 10
SCK ---- Pin 13
MOSI ---- Pin 11
MISO ---- Pin 12

The role pin for the "Ping Pair" example is connected as follows:
Transmitter: Pin 7 connected to 5V through a 10Kohm resistor (this is to be sure that pin 7 is set to digital input 1)
Receiver: Pin 7 connected to GND

I have been using the RF24 library and have uninstalled and re-installed it several times.

I have been using the "Ping Pair" example sketch and the only modification has been to change the CE and CSN pins to 9 and 10 respectively. Here is my code.

 Copyright (C) 2011 James Coliz, Jr. <maniacbug@ymail.com>

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.

 * Example RF Radio Ping Pair
 * This is an example of how to use the RF24 class.  Write this sketch to two different nodes,
 * connect the role_pin to ground on one.  The ping node sends the current time to the pong node,
 * which responds by sending the value back.  The ping node can then see how long the whole cycle
 * took.

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

// Hardware configuration

// Set up nRF24L01 radio on SPI bus plus pins 8 & 9

RF24 radio(9,10);

// sets the role of this unit in hardware.  Connect to GND to be the 'pong' receiver
// Leave open to be the 'ping' transmitter
const int role_pin = 7;

// Topology

// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

// Role management
// Set up role.  This sketch uses the same software for all the nodes
// in this system.  Doing so greatly simplifies testing.  The hardware itself specifies
// which node it is.
// This is done through the role_pin

// The various roles supported by this sketch
typedef enum { role_ping_out = 1, role_pong_back } role_e;

// The debug-friendly names of those roles
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};

// The role of the current running sketch
role_e role;

void setup(void)
  // Role

  // set up the role pin
  pinMode(role_pin, INPUT);
  delay(20); // Just to get a solid reading on the role pin

  // read the address pin, establish our role
  if ( digitalRead(role_pin) )
    role = role_ping_out;
    role = role_pong_back;

  // Print preamble

  printf("ROLE: %s\n\r",role_friendly_name[role]);

  // Setup and configure rf radio


  // optionally, increase the delay between retries & # of retries
  // radio.setRetries(15,15);

  // optionally, reduce the payload size.  seems to
  // improve reliability
  // radio.setPayloadSize(8);

  // Open pipes to other nodes for communication

  // This simple sketch opens two pipes for these two nodes to communicate
  // back and forth.
  // Open 'our' pipe for writing
  // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)

  if ( role == role_ping_out )

  // Start listening
  // if( radio.setDataRate( RF24_250KBPS ) ) {
  //   printf( "Data rate 250KBPS set!\n\r" ) ;
  // } else {
  //   printf( "Data rate 250KBPS set FAILED!!\n\r" ) ;
  // }
  // radio.setDataRate( RF24_2MBPS ) ;
  // radio.setPALevel( RF24_PA_MAX ) ;
  radio.enableDynamicPayloads() ;
  radio.setAutoAck( true ) ;
  radio.powerUp() ;

  // Dump the configuration of the rf unit for debugging


void loop(void)
  // Ping out role.  Repeatedly send the current time

  if (role == role_ping_out)
    // First, stop listening so we can talk.

    // Take the time, and send it.  This will block until complete
    unsigned long time = millis();
    printf("Now sending %lu...",time);
    radio.write( &time, sizeof(unsigned long) );

    // Now, continue listening

    // Wait here until we get a response, or timeout (250ms)
    unsigned long started_waiting_at = millis();
    bool timeout = false;
    while ( ! radio.available() && ! timeout )
      if (millis() - started_waiting_at > 249 )
        timeout = true;

    // Describe the results
    if ( timeout )
      printf("Failed, response timed out.\n\r");
      printf("Timeout duration: %d\n\r", (1+radio.getMaxTimeout()/1000) ) ;
      // Grab the response, compare, and send to debugging spew
      unsigned long got_time;
      radio.read( &got_time, sizeof(unsigned long) );

      // Spew it
      printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time);

    // Try again 1s later

  // Pong back role.  Receive each packet, dump it out, and send it back

  if ( role == role_pong_back )
    // if there is data ready
    if ( radio.available() )
      // Dump the payloads until we've gotten everything
      unsigned long got_time;
      bool done = false;
      while (!done)
        // Fetch the payload, and see if this was the last one.
        done = radio.read( &got_time, sizeof(unsigned long) );

      // First, stop listening so we can talk

      // Send the final one back. This way, we don't delay
      // the reply while we wait on serial i/o.
      radio.write( &got_time, sizeof(unsigned long) );
      printf("Sent response %lu\n\r", got_time);

      // Now, resume listening so we catch the next packets.
// vim:cin:ai:sts=2 sw=2 ft=cpp

I have also attached the serial outputs. Couldn't get copy and past to work from the serial monitor so the outputs are attached as jpegs.

I am truly stumped on what the problem is because it seems like most people can pretty much plug and play with the Ping Pair sketch... Is it possible that I am getting noise from local wifi networks. I am in a suburban area with several wifi networks nearby. Both arduinos are connected through individual header connectors so I have about 6 inch leads running from the arduinos to the NRF24L01+ modules. It should also be noted that the NRF24L01+ modules do not initialize the same way every time. So the Details() information present in the serial monitor data changes when the arduinos are manually reset with the reset button. Some times the RX and TX addresses don't match with the code, sometimes the CRC length changes, and sometimes it says it's an NRF24L01 module and drops the "+" sign. Really not sure what the cause of this is. I would be willing to bet it is one of the reasons things aren't working but I have not idea how to fix it.

Any and all input is appreciated. I have a BS in Mechanical Engineering and a Minor in Electrical Engineering. That being said, this is my first venture into the world of wireless. My goal is to design some specialty RC devices for milsim sports (paintball, airsoft ect.)



Alright, everyone I figured it out. Funny how after a week of screwing around with this I figure out my mistake after formally asking for help haha.

So the issue was needing a common ground between my separate 3.3V power source and the 5V source coming from my laptop USB. All I had to due was connect a ground from my variable DC source to the ground on each arduino. After that each NRF module initialized properly and consistently and was able to successfully run the pingpair sketch. Thanks for being there guys even though no one got a chance to comment ;).