Problem with testRPD-function of RF24 library

Hello guys,
I have a problem using the RF24 library for my nrf24l01+ 2,4 GHz Transciever.
When trying to look for free channels with the library-function "testRPD", the functions tells me all the time, that every channel is not used, even if I put another Arduino with a transciever next to my "free-channel-seeker" sending the whole time on one channel.
I tried to google the problem, but wasn't able to find an answer.

Here is a link to the class-reference: RF24: RF24 Class Reference
Here is my written sketch

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

/*
- FUNCTION: Testing on all channels for free channels

 - 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

*/

//----------------definitions----------------

#define CE_PIN 9
#define CSN_PIN 10
#define serial 1

RF24 radio(CE_PIN, CSN_PIN);  //definition of transciever

bool segmentanzeige(int segment_pins[7], int inhalt);

int num_unused=0;
int channel=0;
int PINS[7] = {2,3,4,5,6,7,8};

void setup()
{
  int k=0;
  Serial.begin(9600);
  radio.begin();
  if(radio.setDataRate(RF24_250KBPS)) Serial.println("plus model");   //proofing, if transciever is the nrf24l01+
  
  for(k=0;k<7;k++)  //defining 7-segment Pins as output
  {
    pinMode(PINS[k], OUTPUT);
  }
}


void loop()
{
  radio.setChannel(channel);    
  delay(10);  //important for true result
  if(!radio.testRPD()) num_unused++; //if no carrier = channel free
  channel++;

  if(channel==128)   //all channels tested
  {
    Serial.print(num_unused);        //Serial Output of number of unused channels
    channel=0;
    if(num_unused>99) num_unused=90;  
    if((num_unused>0)&&(num_unused<10)) num_unused=10;  //needed for 7 segment display

    segmentanzeige(PINS, (num_unused/10));    //output on 7 segment display for standalone use
    num_unused=0;
  }
}

bool segmentanzeige(int segment_pins[7], int zahl)
{
  int j;
  bool stati[70]={1,1,1,1,1,1,0, 0,0,0,1,1,0,0, 1,0,1,1,0,1,0, 0,0,1,1,1,1,1, 0,1,0,1,1,0,1, 0,1,1,0,1,1,1, 1,1,1,0,1,1,1, 0,0,1,1,1,0,0, 1,1,1,1,1,1,1, 0,1,1,1,1,1,1};
  //              0------------- 1------------- 2------------- 3------------- 4------------- 5------------- 6------------- 7------------- 8------------- 9------------
  if((zahl<0)||(zahl>9)) return false;
  for(j=0;j<7;j++)
  {
    digitalWrite(segment_pins[j], stati[((7*zahl)+j)]);    
  }
  return true;
}

The serial output is always 128, showing, that on no even a single channel there is a carrier.

Maybe I just missunderstand the function or use it in the wrong way. Do you see the problem in my code?

Thanks in advance for your help

greetings Nikolas

int PINS[7] = {2,3,4,5,6,7,8}, k=0;

Don't do this crap. ONE kind of variable per statement.

And, there is no reason for k to be a global variable.

  for(k=0;k!=10;k++)  //defining 7-segment Pins as output

The normal method of defining a for statement that iterates from 0 to 9 uses k<10, not k != 10. While that works, it looks weird.

Where do you reset i to 0? One letter names don't convey much information. Can't you come up with a name that means something?

I changend "k" to be an local variable in the fuction setup.

I always used '!=' instead of '<' for iterations, it became a habit. But I'll try to change this in the future.

You're right, i forgot to reset 'i', it shuld bei resettet in the "if(i==128)"-statement, because the rf24 library only provides 128 channels, and after the 127th channel the function shuold start angain at 0. You see, the 'i' is just a counting variable, but I now changed the name to something more clear('channel').

I updated the sketch in the first post, but the code isn't working neither.

I noticed this text in the RF24 class reference

Valid only on nRF24L01P (+) hardware. On nRF24L01, use testCarrier().

Nikko, Are you sure you have the + version ?

I also would like to use this function, there is little documentation or anything on google apart form this post !

although I also just found this....

Test whether a signal (carrier or otherwise) greater than or equal to -64dBm is present on the channel.

Valid only on nRF24L01P (+) hardware. On nRF24L01, use testCarrier().

Useful to check for interference on the current channel and channel hopping strategies.

Returns:
    true if signal => -64dBm, false if not 

Definition at line 798 of file nRF24L01P_Maniacbug.cpp.

This is one of the more advanced features, where it is usually best to refer to the datasheet.

The RF signal must be present for at least 40µs
before the RPD is set high.

6.4 Received Power Detector measurements
Received Power Detector (RPD), located in register 09, bit 0, triggers at received power levels above -64
dBm that are present in the RF channel you receive on. If the received power is less than -64 dBm,
RDP = 0.
The RPD can be read out at any time while nRF24L01+ is in receive mode. This offers a snapshot of the
current received power level in the channel. The RPD status is latched when a valid packet is received
which then indicates signal strength from your own transmitter. If no packets are received the RPD is
latched at the end of a receive period as a result of host MCU setting CE low or RX time out controlled by
Enhanced ShockBurst™.
The status of RPD is correct when RX mode is enabled and after a wait time of Tstby2a +Tdelay_AGC=
130us + 40us. The RX gain varies over temperature which means that the RPD threshold also varies over
temperature. The RPD threshold value is reduced by - 5dB at T = -40°C and increased by + 5dB at 85°C.

What this means (as far as I understand) is that either you need to delay for a set period of time after entering RX mode, or check RPD before calling radio.available(). In the case of the latter, the status of RPD would then only be valid if a payload was received.

This scanner example shows usage using a delay.

Note: The testCarrier and testRPD functions are basically the same, just the usage & meaning of the return values is different.

Thanks TMR, I use testCarrier in my application to preselect a quiet channel before my data broadcast, I understand how it works, I think I was just hoping that testRPD actually gave an analogue value of received power

I shall carry on using testCarrier for now as it is part of the channel set-up/select for my FHSS channel hopping

Cheers