nRF24L01 not transmitting

Hello, i think i am going insane on this one.

So, i have a nRF24L01 transmitter connected to arduino NANO like shown in the schema (not really sure about D9-13, but thats not important rn)

the problem is, that after i changed the addresses from "00001" to hex "0x7878787878LL", it stopped sending messages to other modules.
It can still receive however, without any problem.

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

#define CE_PIN 9
#define CSN_PIN 10

RF24 radio(CE_PIN, CSN_PIN);

const uint64_t rAddress[] = {0x7878787878LL, 0xB3B4B5B6F1LL, 0xB3B4B5B6CDLL, 0xB3B4B5B6A3LL, 0xB3B4B5B60FLL, 0xB3B4B5B605LL };

struct CommandPacket {
  uint16_t killCooldown;
  uint16_t sabotageCooldown;
};

struct DataPacket {
  uint8_t nodeID;
  uint8_t type;
  uint8_t uid[10];
};

struct ResetPacket {
  uint8_t type;
};

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!radio.begin()) {
    Serial.println("NRF24 not working");
    while (1);
  }

  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_1MBPS);
  radio.setAutoAck(true);

  radio.openReadingPipe(0, rAddress[0]);
  radio.openReadingPipe(1, rAddress[1]);
  radio.openReadingPipe(2, rAddress[2]);
  radio.openReadingPipe(3, rAddress[3]);
  radio.openReadingPipe(4, rAddress[4]);
  radio.openReadingPipe(5, rAddress[5]);
  radio.openWritingPipe(rAddress[0]);
  radio.startListening();

  Serial.println("MASTER ready");
}

void loop() {
  byte pipeNum;
  if (radio.available(&pipeNum)) {
    DataPacket packet;
    radio.read(&packet, sizeof(packet));

    Serial.print("Datapacket recieved from pipe ");
    Serial.print(pipeNum);
    Serial.print(" | nodeID=");
    Serial.print(packet.nodeID);
    Serial.print(" | type=");
    Serial.print(packet.type);
    Serial.print(" | UID=");
    for (int i = 0; i < 10; i++) {
      if (packet.uid[i] == 0) break;
      Serial.print(packet.uid[i], HEX);
      Serial.print(" ");
    }
    Serial.println();

    if (packet.type == 1) {
      ResetPacket rp;
      delay(1000);
      rp.type = 0xA0;
      radio.stopListening();
        bool ok = radio.write(&rp, sizeof(rp));
        Serial.print("Reset sabotage ");
        Serial.println(ok ? " OK" : " FAIL");
        delay(20);
      radio.startListening();
    }
  }

  if (Serial.available()) {
    String cmdstr = Serial.readStringUntil('\n');
    cmdstr.trim();
    if (cmdstr.startsWith("SEND")) {
      int killT, sabotageT;
      if (sscanf(cmdstr.c_str(), "SEND %d %d", &killT, &sabotageT) == 2) {
        CommandPacket cmd;
        cmd.killCooldown = killT;
        cmd.sabotageCooldown = sabotageT;
        radio.stopListening();
        delay(20);
        radio.openWritingPipe(rAddress[0]);
        bool ok = radio.write(&cmd, sizeof(cmd));
        Serial.println(ok ? " OK" : " FAIL");
        delay(20);
        bool tx_ok, tx_fail, rx_ready;
        radio.printDetails();
        radio.whatHappened(tx_ok, tx_fail, rx_ready);
        Serial.print("write() -> ");
        Serial.println(ok ? "OK" : "FAIL");
        Serial.print("  TX_OK: ");   Serial.println(tx_ok);
        Serial.print("  TX_FAIL: "); Serial.println(tx_fail);
        Serial.print("  TX_LOST: "); Serial.println(rx_ready);
        radio.startListening();
      }
    }
  }
}

The outputs of radio.whatHappened() are all 0.

The other module, that transmits the messages works as intended, so the problem lies somewhere in here, but have no idea where ...

The forum rules expect you to post the real code. All of it. Have a look at the "How to get the best out of this forum post" for the details.

1 Like

thanks, a will have a look.
I have edited the post in the meantime, so there is the whole code now. Thanks for letting me know

1 Like

Thanks for fixing the post.

Why do you care about the actual addresses? I vaguely recalling reading that with this radio, certain addresses cause problems, possibly because of conflict with message sync bits, too many consecutive zero bits, etc.

Worth a try: look around at other code examples and pick addresses that are known to work.

Edit: the pipe address is 5 bytes, not 8 (LL, uint64_t). Classic tutorial on this forum: Simple nRF24L01+ 2.4GHz transceiver demo

It's exactly because of an issue I got with the first set of address, where they weren't represented the same way, thus they weren't able to see each other.

Theese that I got are directly pulled from a sample code that someone got them working in, but it's worth a shot to try and change them up a bit

Hello explorko

Welcome to the world's best Arduino forum ever.

I have been following the topic of using this type of wireless module and the associated software functions for some time now.

For wireless projects, I recommend using the HC12 module.

What are the advantages:

  1. no external functions from a library are needed.
  2. the development of a communication protocol is in your hands
  3. the necessary development steps can be programmed and tested without using the wireless module
  4. the radio module can be easily configured for the project requirements
  5. both transmitter and receiver are contained in one radio module.

hth

Have a nice day and enjoy coding in C++.

1 Like

I agree that the HC-12 is vastly simpler to use than the NRF24L01, which is also obsolete.

Unfortunately, that's not a option for me right now. But I'll keep this in mind for the future

1 Like

All you have done is confuse the addressing formats a bit.

Either you use an array for each address, or the old format is to use a uint64_t variable. An array is the recommended standard.

See Optimized high speed nRF24L01+ driver class documentation: RF24 Class Reference

uint8_t addresses[][6] = {"Prime", "2Node", "3Node", "4Node"};

openReadingPipe(0, addresses[0]); // address used is "Prime"
openReadingPipe(1, addresses[1]); // address used is "2Node"
openReadingPipe(2, addresses[2]); // address used is "3Node"
openReadingPipe(3, addresses[3]); // address used is "4Node"

As can be seen the main parts of addresses 2,3 & 4 all share the same last bytes, with only the first byte being different. This is required by the manufacturer for addresses used on pipes 1-5.

nRF24 devices may be going out of style, but there are newer devices like the XIAO 52840 Sense or the Adafruit Feather Express 52840 that support the same protocols and can communicate with nRF24 devices. nRF24 devices aren't going away any time soon.

You also need to make sure the addresses match on transmitter and receivers

even changing addresses like you suggested, the code is still behaving the same way. Slave can send without problems, Master can read Slaves without problems, but cannot send anything to the Slaves

And sorry for my late reply, i was out of the country for few days, and coulndt reply

I dont know why i didnt try this sooner, but the issue was a faulty nRF device, which wouldnt send no matter what. I changed the nRF device, and the code now works as intended. sorry for bothering everyone, thanks for your ideas and help :smiley:

1 Like

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