Is there any Alternative of the NRF24L01 ?

Hi everyone, I am working on a project and i need to create a sensor network with NRF24L01. NRF24L01 is not working with Ardunino Due's SPI protocol, Due's spi communication voltage level is 3.3V and NRF24L01's voltage level is 5V. Is anyone can recommend me alternatives like NRF24L01?

To my knowledge, the nRF24L01 is a 3.3V (actually Vcc between 1.9V .. 3.6V) device with 5V tolerant inputs. So it should work with a Due.

I would disagree that the NRF24L01 does not work with the DUE, it works for me, so perhaps explain what happened when you tried it ?

I have several nRF24s working perfectly with bare-bones Atmega 328s powered from a pair of AA alkaline cells (3v).

...R

Hi again, I tried 2 NRF24L01 with 2 arduino mega 2560, ıt is working, but i connecting the same NRF24L01 and same code (i changed the data structer (int16) 2 bytes for, in due 4 bytes), I connected NRF24L01 to ICSP pins on due, but it is not working. And I read some documents on arduino website about SPI communication protocol, link is here SPI - Arduino Reference
Due's SPI Level is 3.3V other AVR's Comminucation voltage is 5V, If am i understand it wrong.

If i am wrong on this issue, i will be happy :slight_smile:

fatihceylan:
Due's SPI Level is 3.3V other AVR's Comminucation voltage is 5V, If am i understand it wrong.

I have no experience of the Due but your problem has absolutely nothing to do with the fact that it works at only 3.3v.

The nRF24 is a 3,3v device with its I/O pins capable of accepting 5v inputs.

...R

and same code (i changed the data structer (int16) 2 bytes for, in due 4 bytes)

Please post your code for both Mega and Due.

fatihceylan:
Due's SPI Level is 3.3V other AVR's Comminucation voltage is 5V, If am i understand it wrong.

If i am wrong on this issue, i will be happy :slight_smile:

Here is a simple program that will when run on a DUE, if connected correctly, print the the registers on a NRF24L01;

/*******************************************************************************************************
  Programs for Arduino - Copyright of the author Stuart Robinson - 05/12/20

  This program is supplied as is, it is up to the user of the program to decide if the program is
  suitable for the intended purpose and free from errors.
*******************************************************************************************************/

/*******************************************************************************************************
  Program Operation - This program is stand alone, it is not necessary to install a NRF2401 library to
  check the NRF2401 can be written to and read from over the SPI bus.

  The contents of the NRF2401 registers from 0x00 to 0x1F are read and printed to the serial monitor.
  If the connections are OK then the printout should look like this;

  NRF24L01_Is_It_There ?

  Print registers 0x00 to 0x1F
  Reg    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
  0x00  00 3F 02 03 5F 4C 27 42 00 00 E7 52 C3 C4 C5 C6
  0x10  E7 00 20 00 00 00 00 12 00 00 FF FF FF FF FF FF

  Note that this is just a 'is it there type check' the CE pin is not used or needed for this simple check.
  If the device is faulty, not present or wired incorrectly the register contents will likely be all 00s or
  FFs. The program makes no attempt to turn on the RF transmitter or receiver.

  Serial monitor baud rate is set at 9600.
*******************************************************************************************************/

#include <SPI.h>

#define CSN_PIN 10

#define NUM_REGISTERS   26
#define CMD_R_REGISTER  0x00
#define CMD_W_REGISTER  0x20


void loop()
{
  Serial.println(F("Print registers 0x00 to 0x1F"));
  printRegisters(0, 0x1F);
  Serial.println();
  delay(5000);
}


void printRegisters(uint16_t Start, uint16_t End)
{
  uint16_t Loopv1, Loopv2, RegData;

  Serial.print(F("Reg    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F"));
  Serial.println();

  for (Loopv1 = Start; Loopv1 <= End;)           //32 lines
  {
    Serial.print(F("0x"));
    if (Loopv1 < 0x10)
    {
      Serial.print(F("0"));
    }
    Serial.print((Loopv1), HEX);                 //print the register number
    Serial.print(F("  "));
    for (Loopv2 = 0; Loopv2 <= 15; Loopv2++)
    {
      RegData = readRegister(Loopv1);
      if (RegData < 0x10)
      {
        Serial.print(F("0"));
      }
      Serial.print(RegData, HEX);                //print the register number
      Serial.print(F(" "));
      Loopv1++;
    }
    Serial.println();
  }
}


uint8_t readRegister(uint8_t reg)
{
  uint8_t result = 0xFF;

  if (reg < NUM_REGISTERS) {
    digitalWrite(CSN_PIN, LOW);
    SPI.transfer(CMD_R_REGISTER | reg);
    result = SPI.transfer(0xff);
    digitalWrite(CSN_PIN, HIGH);
  }

  return result;
}


void setup()
{
  Serial.begin(9600);
  pinMode(CSN_PIN, OUTPUT);
  Serial.println();
  Serial.println(F("NRF24L01_Is_It_There ?"));
  Serial.println();
  SPI.begin();
}

The program is just an 'is it there' type test program, reading some registers on the NRF24L01, its a standalone program, no NRF24L01 library is needed.

If you dont get a similar register print out;

You have it wired wrong.
The NRF24L01 is faulty.
The DUE is faulty.
The Arduino IDE is faulty, not up to date, etc.

sterretje:
Please post your code for both Mega and Due.

Firstly i tried my code on 2 mega 2560 after it works, i run my code reciever code on Due, just i change radio pins like radio(8, 19);

This is Mega 2560 code,

Reciever(Mainboard)

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

RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
const byte address2[6] = "00002";

int16_t DeviceID = 1212;

int16_t sec;
bool sended = false;

enum REQUEST_TYPE
{
    data            = 1,
    configuration   = 2  
};

void setup() {

Serial.begin(115200);
Serial.println("Reciver Starting...");
radio.begin();
radio.openReadingPipe(1, address);//00001 Setting the address at which we will receive the data
radio.openWritingPipe(address2);//00002
radio.setPALevel(RF24_PA_MIN);       //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
radio.setDataRate(RF24_250KBPS);
radio.startListening();              //This sets the module as receiver
}
void loop()
{
    if (radio.available())              //Looking for the data.
    {
        int16_t package[4];
        radio.read(&package, sizeof(package));
        Serial.println("packet geldi");
        Serial.print("DeviceID:");
        Serial.println(package[0]);
        
        Serial.print("Sensor_0:");
        Serial.println(package[1]);

        Serial.print("Sensor_1:");
        Serial.println(package[2]);

        Serial.print("Counter:");
        Serial.println(package[3]);
    }

    if ((second() == 0 || second() == 10 || second() == 20 || second() == 30 || second() == 40 || second() == 50) && sended == false)
    {
        sec = second();
        sended = true;
        radio.stopListening();
        CreateDataPackage();
        Serial.println(second());
        radio.startListening();
        
    }

    if (sec != second())
    {
        sended = false;
    }
}

void CreateDataPackage()
{
    int16_t requestPack[2];

    requestPack[0] = DeviceID;
    requestPack[1] = 1 ;

    radio.write(&requestPack, sizeof(requestPack));
}

Transreciever (Sensor side)

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN         
const byte address[6] = "00001";//Byte of array representing the address. This is the address where we will send the data. This should be same on the receiving side.
const byte address2[6] = "00002";

int16_t counter = 0;


int16_t sensor_0;
int16_t sensor_1;
int16_t device = 6512;

void setup() 
{
    Serial.begin(115200);
    Serial.println("Transreciever Starting...");
    
    radio.begin();                  //Starting the Wireless communication
    radio.openWritingPipe(address); //00001 Setting the address where we will send the data
    radio.openReadingPipe(1, address2);//00002
    radio.setPALevel(RF24_PA_MIN);  //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
    radio.setDataRate(RF24_250KBPS);
    radio.startListening();          //This sets the module as transmitter
}

void loop()
{
  int16_t package[2];
  //Serial.println(sizeof(package));
    if (radio.available()) //Looking for the data.
    {
        
        radio.read(&package, sizeof(package));
        Serial.println("packet geldi");
        if (package[1] == 1)
        {   
             Serial.println("packet baslik ok");
             radio.stopListening();
             CreatePackage();
             delay(5);
             radio.startListening();
        } 
    }
}

void CreatePackage()
{
    int16_t package[4];
    sensor_0 = sensor_0 + 5;
    sensor_1 = sensor_1 + 10;
   
    package[0] = device;
    package[1] = sensor_0;
    package[2] = sensor_1;
    package[3] = counter;
    
    radio.write(&package, sizeof(package));
   
    counter = counter + 1;
}

srnet:
Here is a simple program that will when run on a DUE, if connected correctly, print the the registers on a NRF24L01;

/*******************************************************************************************************

Programs for Arduino - Copyright of the author Stuart Robinson - 05/12/20

This program is supplied as is, it is up to the user of the program to decide if the program is
 suitable for the intended purpose and free from errors.
*******************************************************************************************************/

/*******************************************************************************************************
 Program Operation - This program is stand alone, it is not necessary to install a NRF2401 library to
 check the NRF2401 can be written to and read from over the SPI bus.

The contents of the NRF2401 registers from 0x00 to 0x1F are read and printed to the serial monitor.
 If the connections are OK then the printout should look like this;

NRF24L01_Is_It_There ?

Print registers 0x00 to 0x1F
 Reg    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
 0x00  00 3F 02 03 5F 4C 27 42 00 00 E7 52 C3 C4 C5 C6
 0x10  E7 00 20 00 00 00 00 12 00 00 FF FF FF FF FF FF

Note that this is just a 'is it there type check' the CE pin is not used or needed for this simple check.
 If the device is faulty, not present or wired incorrectly the register contents will likely be all 00s or
 FFs. The program makes no attempt to turn on the RF transmitter or receiver.

Serial monitor baud rate is set at 9600.
*******************************************************************************************************/

#include <SPI.h>

#define CSN_PIN 10

#define NUM_REGISTERS   26
#define CMD_R_REGISTER  0x00
#define CMD_W_REGISTER  0x20

void loop()
{
 Serial.println(F("Print registers 0x00 to 0x1F"));
 printRegisters(0, 0x1F);
 Serial.println();
 delay(5000);
}

void printRegisters(uint16_t Start, uint16_t End)
{
 uint16_t Loopv1, Loopv2, RegData;

Serial.print(F("Reg    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F"));
 Serial.println();

for (Loopv1 = Start; Loopv1 <= End;)           //32 lines
 {
   Serial.print(F("0x"));
   if (Loopv1 < 0x10)
   {
     Serial.print(F("0"));
   }
   Serial.print((Loopv1), HEX);                 //print the register number
   Serial.print(F("  "));
   for (Loopv2 = 0; Loopv2 <= 15; Loopv2++)
   {
     RegData = readRegister(Loopv1);
     if (RegData < 0x10)
     {
       Serial.print(F("0"));
     }
     Serial.print(RegData, HEX);                //print the register number
     Serial.print(F(" "));
     Loopv1++;
   }
   Serial.println();
 }
}

uint8_t readRegister(uint8_t reg)
{
 uint8_t result = 0xFF;

if (reg < NUM_REGISTERS) {
   digitalWrite(CSN_PIN, LOW);
   SPI.transfer(CMD_R_REGISTER | reg);
   result = SPI.transfer(0xff);
   digitalWrite(CSN_PIN, HIGH);
 }

return result;
}

void setup()
{
 Serial.begin(9600);
 pinMode(CSN_PIN, OUTPUT);
 Serial.println();
 Serial.println(F("NRF24L01_Is_It_There ?"));
 Serial.println();
 SPI.begin();
}



The program is just an 'is it there' type test program, reading some registers on the NRF24L01, its a standalone program, no NRF24L01 library is needed. 

If you dont get a similar register print out;

You have it wired wrong. 
The NRF24L01 is faulty. 
The DUE is faulty. 
The Arduino IDE is faulty, not up to date, etc.

I tryed your code and it was printed some infos like this, I think it is not conected to the spi :frowning: I will Check the wiring again and again.

15:31:59.247 -> Print registers 0x00 to 0x1F
15:31:59.294 -> Reg    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
15:31:59.340 -> 0x00  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 
15:31:59.387 -> 0x10  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF

Note that the DUE SPI wiring must be taken from the central ISP connector.

srnet:
Note that the DUE SPI wiring must be taken from the central ISP connector.

Yes, normally, i was using D13-SCK,D12-MISO,D11-MOSI pins but it is not working, when moved the wires to the centeral SPI pins (They are near the Deu's chip and writing SPI), It is starting to communication with NRF24L01 and it is started to read registers and printed this,
Print registers 0x00 to 0x1F
16:12:40.684 -> Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
16:12:40.778 -> 0x00 08 3F 03 03 03 02 0F 0E 00 00 E7 C2 C3 C4 C5 C6
16:12:40.825 -> 0x10 E7 00 00 00 00 00 00 11 00 00 FF FF FF FF FF FF

Communication is ok now and my package starting to reach the reciever (DUE), Thank your very much for help to everyone, Speacial thanks to SRNET for sharing NRF24L01 register reader CODE. It was survived me :slight_smile:

fatihceylan:
Yes, normally, i was using D13-SCK,D12-MISO,D11-MOSI pins but it is not working

Hardly surprising, check the wiring diagram for DUE and Mega, those are not SPI pins .....................

I was using Arduino Due's datasheet from the site and it shows D13-SCK,D12-MISO,D11-MOSI pins (I am using clone Due maybe it is different than orginal) https://content.arduino.cc/assets/Pinout-Due_latest.pdf

I was using the SPI pins on Arduino Mega 2560 D52-SCK, D51-MOSI, D50-MISO pins, it is working, this is the PDF link https://content.arduino.cc/assets/Pinout-Mega2560rev3_latest.pdf

Thanks again, I am wring this details for other users when someone have same issue, they can solve it before lose their mind :slight_smile: Thanks again.

fatihceylan:
I was using Arduino Due's datasheet from the site and it shows D13-SCK,D12-MISO,D11-MOSI pins (I am using clone Due maybe it is different than orginal) https://content.arduino.cc/assets/Pinout-Due_latest.pdf

Thats interesting, the Schematic and PCB here;

Do not agree with the pinout diagram shown.

The Schematic and PCB design (dated 28\01\19) show that D13,D12,D11 are not connected to the ISP connector in the middle, which is clearly marked 'SPI' in the picture.

Looks like the 'Official' pinout diagram for the DUE has been updated, it now does not show the SPI pins on 13,12,11.

I had reported the apparent mistake to Arduino.