NRF24L01 simple example?

Hello people!

I have 2 Arduino Unos and 2 NRF24L01.

The NRF2401 is probably an older or a close, but a far away relative, of the NRF24L01 (or is it not?) , but, for the NRF2401, i could find a simple example, that for a beginner, such as me, makes understanding the process of transmitting characters or numbers, from transmitter to receiver, just as simple as it is with the Arduino bluetooth examples.

Here is the page, where the simple examples are, for the NRF2401:

http://playground.arduino.cc/InterfacingWithHardware/Nrf2401

My question is this:

I have been looking for many hours, for a simple example of an NRF24L01 Arduino IDE code, of a transmitter and a receiver to send chars and ints, but all i could find were tutorials, that go way too deep into the ocean, for my level of experience, dealing with hardcore C communication programming, with pointer calling and protocols and what not.

Does anyone know of a simple script and examples for the NRF24L01, just as there is for the NRF2401? Just a little 'L' difference in the name and such a big gap for the newbies?

Would be much obliged, for a good link with beginners level reference!
Thanks!

Turns out, I decided to do a project with this radio tonight. They work great, so far.

This is the specific device I am working with: http://www.ebay.com/itm/161193948590

The project is based on the tutorial information and source code here: http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

This is a great tutorial and leaves very little to be imagined. I changed it to simply send a series of ones and zeros from my transmitter to my receiver as my first proof of concept and toggle an LED based on the incoming int.

Sender code (based on the tutorial and source code):

/* 

 RadioSend
 
 - CONNECTIONS: nRF24L01 Modules See:
 
 http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
   1 - GND
   2 - VCC 3.3V !!! NOT 5V
   3 - CE to Arduino pin 9
   4 - CSN to Arduino pin 10
   5 - SCK to Arduino pin 13
   6 - MOSI to Arduino pin 11
   7 - MISO to Arduino pin 12
   8 - UNUSED

 Send a series of zeros and ones to the receiver radio.
 
*/

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

#define CE_PIN   9
#define CSN_PIN 10

// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

int high[1];
int low[1];

void setup()
{
  radio.begin();
  radio.openWritingPipe(pipe);

  high[0] = 1;
  low[0] = 0;
}

void loop()
{
  radio.write(high, sizeof(high));

  delay(1000);  
  
  radio.write(low, sizeof(low));

  delay(1000);  
}

Receiver code (based on the tutorial and source code):

/* 

 RadioReceive
 
 - CONNECTIONS: nRF24L01 Modules See:
 
 http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
   1 - GND
   2 - VCC 3.3V !!! NOT 5V
   3 - CE to Arduino pin 9
   4 - CSN to Arduino pin 10
   5 - SCK to Arduino pin 13
   6 - MOSI to Arduino pin 11
   7 - MISO to Arduino pin 12
   8 - UNUSED

 Receive a series of zeros and ones to the sender radio.
 
*/

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

#define CE_PIN   9
#define CSN_PIN 10

// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

int received[1];

void setup()   /****** SETUP: RUNS ONCE ******/
{
  pinMode(8, OUTPUT); 
  
  delay(1000);

  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();;
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  if ( radio.available() )
  {
    // Read the data payload until we've received everything
    bool done = false;
    while (!done)
    {
      // Fetch the data payload
      done = radio.read( received, sizeof(received) );
 
      if (received[0]==0)
        digitalWrite(8, LOW);
      else
        digitalWrite(8, HIGH);
    }
  }
}

The devices (wired based on the pins selected in the tutorial. Don't let the fact that these use bare chips fool you, they use the exact same Arduino "pins" that the tutorial suggests using):

Click for detail

Hi JoeN !
Would you be so kind and try to help me with my Project ?
Its using the same NRF24L01 Chip..

Any help would be apreciated ! :slight_smile:

Kind regards
Frank

I got my nRF24s working with this Tutorial

I suggest you use the TMRh20 version of the RF24 library - it solves some problems from the ManiacBug version

The pair of programs in this link may be useful.

...R

Thanks for putting this simple example. Was finally able to make it work.
Being new to Arduino world, may be I am doing something wrong but I dont see consistent results from the nrf24l chip. The output is not consistent ie. sometime the same code (which ran successfully last time) does not work again adding more frustation. I have used the base board to avoid voltage problem but still not able to understand why the out is not consistent.
Please advise on how to troubleshoot the root cause of the issue.

Thanks
Sachin

Place a 10uF cap on the 3.3v power pin in the nrf24l01 break out board that normally cures missing bits of data issues

vermasachin:
Please advise on how to troubleshoot the root cause of the issue.

If the suggestion by @StevoiBoy does not solve the problem please post the pair of programs that YOU have uploaded to your Arduinos.

Also post some examples of the faulty output so we know exactly what you mean.

I have not found it necessary to use 10µF capacitors with my genuine Arduinos but they have been essential on my breadboard Atmega 328s.

...R

Just a quick question: in the above source code JoeN posted, he has

"const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe"

Does this mean that both the sender and the recipent have a virtual private conversation? In other words, other devices can hear what they transmit between each other but ignore it since they are not "0xE8E8F0F0E1LL" Is my understanding correct? Thank you.

"const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe"

Does this mean that both the sender and the recipent have a virtual private conversation? In other words, other devices can hear what they transmit between each other but ignore it since they are not "0xE8E8F0F0E1LL" Is my understanding correct?

First, it will be easier to understand if you think of that number as the address of the receiver. Pipes are a different thing altogether - they allow a receiver to accept messages for up to 6 different addresses and keep them segregated. Like receiving mail for the residents in an apartment block.

And, yes, your understanding is basically correct. An nRF24 listening on a particular channel will hear every transmission on that channel but will ignore anything that is not addressed to it.

This more recent Simple nRF24L01+ Tutorial may be helpful. I deliberately made it as simple as possible. And the examples do work.

...R

SamBrownADK:
Does this mean that both the sender and the recipent have a virtual private conversation? In other words, other devices can hear what they transmit between each other but ignore it since they are not "0xE8E8F0F0E1LL"

The conversation is by no means private.

Any node that listens to 0xE8E8F0F0E1LL can read the messages and will be undetectable if it disables autoack (global or for this specific address).

Thank you! I will read up on it before I try to experiment with it.

Whandall:
The conversation is by no means private.

Any node that listens to 0xE8E8F0F0E1LL can read the messages and will be undetectable if it disables autoack (global or for this specific address).

Very good point. I had overlooked that.

@SamBrownADK, if you choose your own addresses carefully it is unlikely that someone will be able to guess them as there are about 2555 options.

...R

Robin2:
if you choose your own addresses carefully it is unlikely that someone will be able to guess them as there are about 2555 options.

Well, you do not have to guess much.

You can program the NRF to ignore crc and use 2 byte addresses, then make the MSB of this address the preamble byte (there are only two of them and the selection is ruled by the highest bit of the first address byte).

So a brute force attack only has 256 possibilities left, six of them can be tested at once.

The captured packet allows access to the original 5 byte address used.

More here: http://travisgoodspeed.blogspot.de/2011/02/promiscuity-is-nrf24l01s-duty.html
or here: http://samy.pl/keysweeper/

Whandall:
Well, you do not have to guess much.

So why did they bother to provide for 5 byte addresses.

(By the way, that is meant as a comment, not a question).

...R

Any wireless communication is prone to eavesdropping.

NRF's are more secure than standard WiFi, because there is no builtin promiscuous mode.

If you want to have secure communication, you will have to use encryption.

Whandall:
Any wireless communication is prone to eavesdropping.

Sure. But from what you say the Nordic folks have made it ridiculously easy - while giving an illusion of security.

Nothing that I want to do myself requires any security against a hacker.

...R

Ethernet chips have a builtin promiscuous mode, the NRF24L01 has to be misused to come close to that.
Using the two byte address 'feature' is running the chip with reserved settings, so it is kind of a hack.

The expertise needed to manipulate even unencoded NRF communications is above script-kid level.
If you want to protect the data in the packets, a pre-shared key encryption would give more than enough security,
but thats only my humble opinion.