Unable to Reduce Payload Size - Arduino + NRF24L01+

Hello,

I have been working with 2 NRF24 modules I created and have been seeing relative success; however, I have one issue that has been giving me some trouble. Right now, I am writing two simple programs for two NRF24 devices to get the core functionality correct; a receiver program and a transmitter program. I can successfully get the two to communicate, but I have not been able to reduce the payload size lower than 32 bytes. I would like to optimize communications by sending payloads only as long as the messages.

The message is a 1 element byte array that cycles from 17 to 35. These values are sent to the receiver and used to drive the PWM duty cycle for a servo motor.

The "setPayloadSize" function accepts values from 1 -32 (bytes), corresponding to the payload length needed to deliver the message. By my understanding, I am only sending 1 byte, so I should be able to set the payload size to as little as 1 byte in order to transmit correctly. However, I am unable to send messages unless the payload size is not specified (I believe the default payload length is 32) or is set to 32.

Any thoughts or suggestions on this subject would be greatly appreciated. Thanks!

Transmitter - Using ManiacBug's NRF24 Library
Loaded onto Arduino Uno Rev 3

//CMK 
//Wireless Serial Servo Command (Transmitter)


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


//declare 8 bit variable pwm (0 - 255)
byte pwm[1];

//Declare an instance of RF24 library (device is tx)
RF24 tx(9,10);                  

//Declare the device address
const uint64_t pipe = 0xE8E8F0F0E1LL;


void setup(void) {

  //Begin Serial Communications at 9600 baud rate 
  Serial.begin(9600);
  
  //Enable NRF24 Chip
  tx.begin();

  //Use the address "pipe" when transmitting
  tx.openWritingPipe(pipe);
  tx.setPALevel(RF24_PA_HIGH);
  tx.setDataRate(RF24_250KBPS);

  //Transmit does not work when size of payload is reduced - PROBLEM IS HERE
  tx.setPayloadSize(32);
  
  //initalize pwm to servo center position
  pwm[0] =  26;

}

void loop(void) {

  //send the pwm DC, $ points to pwm as a variable 
  tx.write(pwm, 1);


  //Cycle Through PWM values of 17 - 35
  if (pwm[0] < 35){

    pwm[0] = pwm[0] + 1;
  }
  else {

    pwm[0] = 17;
  }

  //Needed; otherwise delay messes with transmit
  tx.powerDown();
  delay (100);
  tx.powerUp();
  
}

Receiver Code - Using ManicBug's NRF24 Library
Loaded onto Arduino Rev3

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

//Declare a radio
RF24 rx(9,10);

//receive messages from only this addrice
const uint64_t pipe = 0xE8E8F0F0E1LL;

//Define receiving me
byte pwm[1];


void setup(void) {

//Setup serial comms at 2400 baud rate
Serial.begin(2400);

TCCR0B = TCCR0B & B11111000 | B00000101;    // set timer 0 divisor to  1024 for PWM frequency of    61.04 Hz

//Initialize receiver
rx.begin();
rx.openReadingPipe(1,pipe);
rx.startListening();
rx.setDataRate(RF24_250KBPS);


//Unable to set lower than 32 bytes - PROBLEM IS HERE
rx.setPayloadSize(32);

}

void loop(void) {

if (rx.available()){

  bool done = false;

  while (!done){

    done = rx.read(pwm,1);

    Serial.println(pwm[0]);
 
  }  
  
}
else {

  Serial.println("No radio available");
}

  rx.powerDown();

analogWrite(5,pwm[0]);

  rx.powerUp();

}

Have a look at this Simple nRF24L01+ Tutorial. I use the newer TMRh20 version of the RF24 library which solves some problems from the earlier ManiacBug version.

If you need to send more than 32 bytes then just send it as two (or more) separate messages.

But your Tx program seems to be sending a single byte in each message?

...R

Robin, Thank you for your response.

I will try using the new RF24 library that you mention and see if that fixes the problem. From everything I see, what I am trying to do should be as simple as calling the setPayloadSize function and it should work, especially if I have already had successful communications with 32 byte payloads.

As for the message; Yes, I am sending a single byte (1 element byte array). So from what I understand, I should be able to reduce the payload size to a singe byte.

kundingerc:
As for the message; Yes, I am sending a single byte (1 element byte array). So from what I understand, I should be able to reduce the payload size to a singe byte.

Don't worry about what size the nRF24 thinks the payload is. Just send your byte. Try my examples.

Based on your title I thought you were struggling to send a big message with more than 32 bytes.

...R

Thank you, I will try your examples and the updated library.

Perhaps I could have chosen a different subject line, but I am just trying to optimize the payload size for a short message. Sending 31 bytes of blank information every time I send a 1 byte message seems very inefficient and I have heard it has a noticeable effect on range.

The TMRh20 library has very good documentation.

If you choose the dynamic payload option it will figure out the size itself.

...R

Added the new library and that seems to have fixed my issue. Maybe this issue is a bug in the original library.

Thank you for your help!