Electron, nRF24L01 and Pro Mini

I’m late to the discussion. I have many nights’ experience battling with radios.

I can confirm it works well if you follow my old nRF24L01 directions carefully in this post. You’ll easily get 20 feet range. My sample code dials down the data rate and that helps to get more range too.

(Alternatively, you can use RFM69 - modules are around $4 - and that is confirmed to work between Photon and Pro Mini. Sample code and reference in my post here.. However, @RWB provided links to other viable options too.)

To help make it easier, at the end I’m including some stripped down code to show you how the nRF24 code works on the Photon (in my case the Photon is exclusively the Receiver, except for sending acks, and I have a Pro Mini as the sender). If you find the example code from my instructions you’ll be able to figure it out.

PS: I can’t be sure about this theory. I have experienced the nRF24 radios working great for a few days to a few weeks, then would not successfully TX/RX for a few days and without inteference or restarting start to work again by itself. My theory is that WiFi routers in the area change channels that then conflict with the chosen channel (and because the system doesn’t continually broadcast the WiFi router, if it was smart enough, wouldn’t even know to avoid the channel). You can do some research on that and choose a higher number channel that puts you above most routers.

#include "particle-rf24/particle-rf24.h" //REMEMBER you need to PLUS and add the files in Web IDE or locally. 
//See https://community.particle.io/t/photon-nrf24l01-library-use-particle-rf24/21217?u=rwb&source_topic_id=32652


//RF section

/*
  PINOUTS
  http://docs.spark.io/#/firmware/communication-spi
  http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/

  PHOTON        SHIELD SHIELD    NRF24L01+
  GND           GND              1 (GND)
  3V3 (3.3V)    3.3V             2 (3V3)
  D6 (CSN)      9  (D6)          3 (CE)
  A2 (SS)       10 (SS)          4 (CSN)
  A3 (SCK)      13 (SCK)         5 (SCK)
  A5 (MOSI)     11 (MOSI)        6 (MOSI)
  A4 (MISO)     12 (MISO)        7 (MISO)

  NOTE: Also place a 10-100uF cap across the power inputs of
        the NRF24L01+.  
 */

// Set up nRF24L01 radio on SPI bus, and pins 9 (D6) & 10 (A2) on the Shield Shield
RF24 radio(D6,A2);



// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipes[2] = { 0xe7e7e7e7e7LL, 0xc2c2c2c2c2LL };

int16_t rec[1] = {99}; //for ack payload
int16_t lastmessage = 0; //for checking if a new message has arrived



//=========================SETUP===========================================
void setup(void) {
 
  radio.begin();
  delay(100);
  radio.setPALevel(RF24_PA_MAX); //RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
  radio.setDataRate(RF24_250KBPS);   //for distance change to 250kbps
  radio.setChannel(1);  
  radio.setAutoAck(true);
  radio.enableAckPayload();
  radio.enableDynamicPayloads();
//  radio.setPayloadSize(8);
  
  radio.setRetries(15, 3);


  radio.openWritingPipe(pipes[1]); // note that our pipes are the same above, but that
  radio.openReadingPipe(1, pipes[0]); // they are flipped between rx and tx sides.
  radio.startListening();
  radio.printDetails();
  Serial.println("Radio started.");

}



//=========================MAIN LOOP===========================================
void loop() {


  rec[0] = message[4]; //for next ack show prior message number received
  lastmessage = message[4];

  if ( radio.available() )
  {

    
    if (radio.available()) //handy tip change due to TMRH20 library. see https://forum.arduino.cc/index.php?topic=302380.0
    {
      
      radio.writeAckPayload( 1, rec, sizeof(int16_t) );
      radio.read( message, sizeof(message) ); // Fetch the payload, and see if this was the last one.
      PrintValues();
    }


      radio.startListening();
   
  } //end of radio logic


 

}
3 Likes