Sending data with RF24 immediately (without boot up)

Hi there!

I’m using nrf24L01 with the RF24 lib.

On the sending RF24 I’ve hooked up an button on my arduino. When it is pressed, it sends a 1. All works fine, however it seems the RF24 has to ‘boot up’ or so before it sends.

I know this because when I let it sends contentiously (eg a ‘0’) and only a ‘1’ when pressed, the receiving RF24 receives the 1 immediately.

It works, but is kind of dirty to let it send zeros all of the time. What is the best way to keep the RF24 ‘awake’ or ‘ready for sending’ so it can send the ‘1’ immediately?

Sending code with delay:

#include <SPI.h>                      //the communication interface with the modem
#include "RF24.h"                     //the library which helps us to control the radio modem
int msg[1];
RF24 radio(8, 9);                    //5 and 10 are a digital pin numbers to which signals CE and CSN are connected.
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.

const int buttonPin = 6;     // the number of the pushbutton pin
const int ledPin =  5;      // the number of the LED pin
bool buttonState;
bool pressed = false;

void setup() {
  radio.begin();                      //it activates the modem.
  radio.openWritingPipe(pipe);        //sets the address of the receiver to which the program will send data.
  pinMode(ledPin, OUTPUT);
}

void loop() {
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH);
    pressed = true;
  }

  if (pressed == true) {
    for (int i = 0; i < 2; i++) {
        msg[0] =  1;
      radio.write(msg, 1);
    }
    pressed = false;
  }
  else {
    digitalWrite(ledPin, LOW);
  }

}

sending code without delay but with dirty zero

#include <SPI.h>                      //the communication interface with the modem
#include "RF24.h"                     //the library which helps us to control the radio modem
int msg[1];
RF24 radio(8, 9);                    //5 and 10 are a digital pin numbers to which signals CE and CSN are connected.
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.

const int buttonPin = 6;     // the number of the pushbutton pin
const int ledPin =  5;      // the number of the LED pin
bool buttonState;
bool pressed = false;

void setup() {
  radio.begin();                      //it activates the modem.
  radio.openWritingPipe(pipe);        //sets the address of the receiver to which the program will send data.
  pinMode(ledPin, OUTPUT);
}

void loop() {

  msg[0] =  0;
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    digitalWrite(ledPin, LOW);
    msg[0] =  1;
  }
  else {
    digitalWrite(ledPin, HIGH);
  }
  radio.write(msg, 1);

}

You could try a better library http://tmrh20.github.io/RF24/index.html.

The 1. sending code sends two packets without delay while the button is pressed, the 2. code floods the air always.

I would send one packet when a button gets pressed.

Have a look at this Simple nRF24L01+ Tutorial and note that it uses the newer TMRh20 version of the RF24 library which solves some problems from the earlier ManiacBug version. Unfortunately TMRh20 did not think to change the name for his version so it is easy to get them confused. If in doubt I suggest you delete the library completely and then download and install the TMRh20 version.

It should be able to send data without any noticeable delay you press a button.

...R

Thank you! it works like charm! And thanks Robin2 for you tutorial!

[SOLVED]