[Request - Answered] nRF24L01+ library

How much did you save by ordering from China?

I paid $17.62 and got them in 7 days from overseas via Amazon from : http://www.amazon.com/gp/product/B00FGJBGNU/ref=oh_details_o00_s00_i00?ie=UTF8&psc=1

For those high powered versions, I got (3) for $20 shipped … and in the process I’m trying out a new online vendor that’s not through ebay. Next time I’ll ask for and expedited shipping quote. Free expedited shipping on orders over $200 supposedly.

Where you every able to publish this nRF24l01 library for the Spark Core. I have my project completed on the Arduino and I’m ready to transfer it to the Core but just realized 3rd party libraries need a port. :frowning:

@hart7ae what do you mean by ā€œpublishingā€? It’s already published on GitHub at https://github.com/technobly/SparkCore-RF24

maniacbug no longer works on the RF24 library does he? the best fork seems to be the one from TMRh20, which i’ve used on arduino and raspberry pi. the RF24Network version is great, but he’s also working on true mesh support and even IP: https://github.com/TMRh20

Hi, please could you tell me what I need to do to use your library to enable comms between a 5v Arduino Pro Mini and a spark core. I have written my own library for this but I’d like to try yours out. I tried running the Getting started code written by manicbug for arduino on the Arduino and your code on the spark but they did not talk, I also tried copying your lib into the Arduino IDE but have all manner of compile errors. It would be really great if you could point me in the right direction, Thanks, Rick.

This is a port of the ManiacBug’s library so it won’t compile on Arduino and it does work in allowing communication between Arduino and Spark: I have it working myself.

My advices are:

  1. check the Arduino side is working properly by using the printDetails function and checking the addresses match what you have set in the Arduino sketch
  2. check the Spark side is working in the same way, connecting your Spark serial and checking the output of the printDetails function
  3. ensure power stability on both sides by adding a capacitor (anything in the 1uF to 100uF will do) between VCC and GND very close to the nRF24 modules (this is the most common source of troubles in my experience)
  4. check the send address on one side matches the receiving address on the other side and vice versa

On top of this all please consider the nRF24 chip (and consequently most of the cheap modules sold on eBay) are 5V tolerant on the signal pins but it requires 3.3V on the VCC pin: powering it with 5V is going to damage the chip.

1 Like

Hello Sir,
I’m using nrf24l01 sensor and want to make network topology that is master should send and receive the perticular data from more no. of node.
in attached code i’m using 2 nodes.please find if anything wrong in code.

one node sending 333
other 222
master sending 123 and receiving 222 and 333 from both nodes

// master
//pipes[0]
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
RF24 radio(9,10);
const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL, 0xF0F0F0F0D3LL};
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 = role_ping_out;
void setup(void)
{
  Serial.begin(57600);
  printf_begin();
  printf("\n\rRF24/examples/GettingStarted/\n\r");
  printf("ROLE: %s\n\r",role_friendly_name[role]);
  radio.begin();
  radio.setRetries(15,15);
  // optionally, reduce the payload size.  seems to
  // improve reliability
  //radio.setPayloadSize(8);
  // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
    role_e role = role_ping_out;    //as a transmitter
    radio.openWritingPipe(pipes[0]);//master pipe address
  }

void loop(void)
{
 if (role == role_ping_out)
  {
    radio.stopListening();
    unsigned long broadcast_data = 123;
    printf("Now sending %lu...",broadcast_data);
    bool ok = radio.write( &broadcast_data, sizeof(unsigned long) );
    if (ok)
      printf("ok...");
    else
      printf("failed.\n\r");
    radio.openReadingPipe(1,pipes[1]);
    radio.startListening();
    // 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 > 200 )
        timeout = true;
    if ( timeout )
    {
      printf("Failed, response timed out.\n\r");
    }
    else
    {
      unsigned long got_time;
      radio.read( &got_time, sizeof(unsigned long) );
      printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time);
    }
    radio.stopListening();
    delay(200);
    radio.openReadingPipe(2,pipes[2]);
    radio.startListening();
    unsigned long started_waiting_at1 = millis();
    bool timeout1 = false;
    while ( ! radio.available() && ! timeout )
      if (millis() - started_waiting_at1 > 200 )
        timeout = true;

    // Describe the results
    if ( timeout )
    {
      printf("Failed, response timed out.\n\r");
    }
    else
    {
      unsigned long got_time;
      radio.read( &got_time, sizeof(unsigned long) );
      printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time);
    }
    radio.stopListening();
    delay(1000);
  }
}

slave1

// RXand tx
//222
//pipes[1]
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
RF24 radio(9,10);
const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL, 0xF0F0F0F0D3LL };
typedef enum { role_ping_out = 1, role_pong_back } role_e;
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};
role_e role = role_pong_back;
void setup(void)
{
  Serial.begin(57600);
  printf_begin();
  printf("\n\rRF24/examples/GettingStarted/\n\r");
  printf("ROLE: %s\n\r",role_friendly_name[role]);
  radio.begin();
  radio.setRetries(15,15);
  role_e role = role_pong_back;

    radio.openWritingPipe(pipes[1]);
    radio.openReadingPipe(1,pipes[0]);
  
  // Start listening
 radio.startListening();
 //radio.printDetails();
}

void loop(void)
{
  
  if ( role == role_pong_back )
  {
    if ( radio.available() )
    {
      unsigned long read_frm_master;
      bool done = false;
      while (!done)
      {
        done = radio.read( &read_frm_master, sizeof(unsigned long) );
        printf("Got payload %lu...",read_frm_master);
	delay(20);
      }
      radio.stopListening();
      unsigned int node_data_sent=222;
      radio.write( &node_data_sent, sizeof(unsigned int) );
      printf("Sent response.\n\r");
      radio.startListening();
    }
  }

}
slave 2

// RXand tx
//333
//pipes[2]
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
RF24 radio(9,10);
const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL, 0xF0F0F0F0D3LL };
typedef enum { role_ping_out = 1, role_pong_back } role_e;
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};
role_e role = role_pong_back;
void setup(void)
{
  Serial.begin(57600);
  printf_begin();
  printf("\n\rRF24/examples/GettingStarted/\n\r");
  printf("ROLE: %s\n\r",role_friendly_name[role]);
  radio.begin();
  radio.setRetries(15,15);
  role_e role = role_pong_back;

    radio.openWritingPipe(pipes[2]);
    radio.openReadingPipe(2,pipes[0]);
  // Start listening
 radio.startListening();
 //radio.printDetails();
}

void loop(void)
{
  
  if ( role == role_pong_back )
  {
    if ( radio.available() )
    {
      unsigned long read_frm_master;
      bool done = false;
      while (!done)
      {
        done = radio.read( &read_frm_master, sizeof(unsigned long) );
        printf("Got payload %lu...",read_frm_master);
	delay(20);
      }
      radio.stopListening();
      unsigned int node_data_sent=333;
      radio.write( &node_data_sent, sizeof(unsigned int) );
      printf("Sent response.\n\r");
      radio.startListening();
    }
  }
}

Sir,but hae u tried one master and two or more slaves.if u know how to do this then please help me

I believe you didn’t understand the nRF24 networking capabilities.

It seems to me you are trying to modify the ping-pong example to have one master replying to two slaves, but you are trying to wait for one slave first and only when you receive from the first one you then try listening for the second one.
The issue is not in the library, but in your approach to do multiple things at the same time.

My suggestion is to scavenge the web searching for approaches to perform multiple activities with one thread, the Arduino world is full of these examples. One I found quite simple to understand is http://forum.arduino.cc/index.php?topic=223286.0.

Generally speaking your mistake is trying to copy paste the code relative to one slave: this will never work. When you want to deal with two slaves you have to do it completely different. To make it even simpler, having twice while ( ! radio.available() && ! timeout ) is the wrong approach: the second gets a change to run only after the first one has completed its cycling.

Hope this helps.

I have an even more complex network topology and it works nicely: 2 hubs (master in your terminology) and 16+ leafs (slaves in your wording). And they are mixed Arduino Pro Mini (clones) and Spark.

Please note nRF24 is not as bluetooth which has a master role and a slave role: all nodes are equals in terms of protocol, the difference is in the network topology you decide to use.

@rlogiacco, any chance you can share some code or code elements for the Community? :grinning:

1 Like

I’ll try to post something on my blog during Easter :wink:

1 Like

Does anyone have a good working example hardware BOM for a small Arduino with RF24L01 radio and a OneWire sensor, battery operated and that talking to a Photon/Core with the same RF module of course? Or suggestions as to what you would build if that was your goal.

http://www.mysensors.org does just that, if I’m not mistaken. Battery powered, NRF Arduino. Since it’s the same radio, there’s no reason it shouldn’t work with Particle :smile:

I have an Arduino pro micro using nRF24L01P with a DHT22, one of those Nokia LCD screens, a photoresistor and a barometric sensor (BMP something) talking to a :particle: Core with another nRF2401P which, in turn, publishes the colelcted data over the internet for logging and graphing.
The same :particle: Core receives data from other pro micros collecting other data (mostly soil moisture, air temperature and light)

None of the sensors above uses OneWire if I remember correctly.

Would you be interested in doing a write-up on this? Sounds like a very neat project, especially for low power applications. I think quite a lot of people could benefit from this, should you be willing to share.
Thanks in advance!

1 Like

What do you mean by doing a write up?
This is a quite extended project, which involves many software components, some residing on a cloud hosted server…

Here are a few pictures of my prototypes:

  • meteo station front

    and rear

  • :particle: Core dispatcher

  • one of the plant sensors on a breadboard

  • plant sensor prototype (battery disconnected)

Sensors aside could you post your code for the micro to core RF piece? It appears you have built a network of sensors and I would love to be able to recreate that for my particular sensor needs. Thanks.

That looks good!
Personally, I’d be most interested in the communication parts. Hooking up sensors depends on personal preference, but the infrastructure to communicate over the NRFs is interesting. What libraries are you using (I’m assuming the one from this topic, obviously), what differences are there with the arduinos?
A ā€˜mini-tutorial’ would be awesome. Something along the lines of:ā€œhook a sensor of choice up to an Arduino. Then use this and this code [Arduino example] to communicate with a Particle device, on which you’ve got this and this code running [Particle example]ā€.
Basically, ā€œpush a button on an Arduino -> light up D7 on a Particleā€, using the NRFs. If possible, through multiple NRFs, if you’ve got that working (star/tree configuration?)