Nrf24l01 arduino doesnt work

Don't post screenshots, post the generated output in code tags.

The diagnosis is included, your connection/setup of the IO is bad.

You still have not changed the post with your last sketches.

Here is what I use to communicate between two MCUs. The master is a 328P and the other is an ATtiny3217. I use the nRF24L01 Mini units. The code below allows two way communications. I use the identical basic code on each unit accept the addresses swop.

The idea is to have a master with 2 or three wireless remote controllers each talking to the master. I initially tested one way and used the char array as address. I then switched to the hex values which works fine. Since I will have multiple remotes using an array for the addresses will be easier. All works.

The code is just the nRF24L01 relevant bits from my sketches. It is almost identical to what you use apart from how I define the addresses.

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

// Create NRF24 setup and instance
#define CE_PIN   6
#define CSN_PIN  7
RF24 radio(CE_PIN, CSN_PIN);                // CE, CSN
//const byte RF24address[5] = {'0','0','0','0','1'};          // Initially used for one way comms
const uint64_t NRF24pipe1 = 0xE8E8F0F0E1LL;                 // New version of address
const uint64_t NRF24pipe2 = 0xE8E8F0F0E2LL;                 // New version of address
// Alternatively could use
//const uint64_t NRF24address[] = { 0xE8E8F0F0E1LL, 0xE8E8F0F0E2LL };    // Use array for multiple addresses

// Data structs for NRF24 communication
struct NRF24data {
  byte dataType;          // 0 = Throttle; 1 = Function; 2 = Accessories
  byte cabAddress;
  int dataValue;
};
NRF24data Throttle;

void setup() {

// Initialise the NRF24 for receive
  radio.begin();
  radio.closeReadingPipe(1);
//  radio.openReadingPipe(1, RF24address);
  radio.openWritingPipe(NRF24pipe1);                // Setting the address to which we will transmit data
  radio.openReadingPipe(1, NRF24pipe2);             // Setting the address from which we will receive data
  radio.setRetries(3,5);                            // delay, count
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();

  delay(1000);
}

void loop() {

  static uint8_t pipeNum;                      // Which unit is sending??
  if (radio.available(&pipeNum)) {
    // Read NRF24 data into Throttle struct
    radio.read(&Throttle, sizeof(Throttle));

    switch ( Throttle.dataType )  {
      .
      .
      sendNRF24()
      .
      .
    }
  }

}

void sendNRF24()  {
  
  radio.stopListening();                    // Setup for transmitting
  radio.write(&Throttle, sizeof(Throttle));
  radio.startListening();                    // Setup for listening  
}

Hope this helps with your current problems.

Willem.

Its worth mentioning that the examples in the NRF24 libraries do actually work, assuming you have the modules connected correctly.

I just noticed something.

In your loop for the transmit code you have:

if(radio.available()){

Will radio.available() be true when you are transmitting? I do not know and cannot try it right now since I do not have my modules set up. Use a Serial.print to check.

Willem.

It will only be true if there was an ack-payload which is not the case here.

The original sender was without available and the new code never formatted correctly.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.