0

I'm trying to send a char [] through an NRF2401 but the radio.write () method always return 0. Check that msg contains the message read from str.

#define TAM 50

RF24 radio(9,10);

const uint64_t pipe = 0xE8E8F0F0E1AA;

char  msg[TAM];

void setup() {

  Serial.begin(9600);

  radio.begin();

  radio.openWritingPipe(pipe);
}

void loop() {
    if(Serial.available() > 0){
      String str = Serial.readString();
      str.toCharArray(msg,TAM);
      if(!radio.write(msg, TAM)){
        Serial.println("Message not send");
      }
      else
        Serial.println(msg);
    }
}

What am I doing wrong?

Edit1: What I have noticed, is that the first time I was allowed to send it but the others no longer.

Edit2: Remove the keyboard input by a char [] and sent it to without problems. Why can this be? Anything else happen when I make a keyboard entry?

5
  • 3
    Check the max payload size. The NRF24L01 does not allow more than max 32 bytes in total. Apr 15 '17 at 12:22
  • If you want to send a longer message you will have to split it into several messages and then merge them at the receiver. Apr 15 '17 at 12:23
  • 3
    Is there another Arduino receiving the message? The nrf24 will check if it receives an ACK message back. If it doesn't the write method will return 0
    – Gerben
    Apr 15 '17 at 12:24
  • @Gerben Yes, there is another arduino that acts as receiver. Also check and radio.write returns 0. Apr 15 '17 at 22:17
  • @MikaelPatel Yes, I have sent a single char to verify this and I continue the same thing. Apr 15 '17 at 22:46
2

I hope you resolved your issue by now, but I had the same problem with an Arduino UNO/nRF24l01+ combination and this question was one of the search results.

In my case, the write() call returned false, but the receiver received the message.

As soon as I added one of the ubiquitous Adapter Boards into the mix the write() call started returning true.

My uneducated guess is that the sending and then the switch from transmit to receive and then waiting to receive the ACK used a bit too much power or something like that.

In any case, even though everyone recommends adding a capacitor and I had the adapter boards on hand, I had thought to tough it out without one and see how far I could get.

I kicked myself for the wasted time, but I learned a lot in the process and I'm having a lot of fun with the transceiver boards now. I'm glad that I didn't just shrug and say "well the message got through so who cares?"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.