1

It's about the RF24 library you can find here. http://maniacbug.github.io/RF24/index.html

I transmit data from one Arduino to another using NRF24L01 radios. When I use the write-function on the transmitter arduino (joystick is an array) and after that I put in a delay higher then 10, the available function returns false.

Transmitter

radio.write( joystick, sizeof(joystick) );
delay(20);

Receiver

if(!available())
  print('No data'); // delay > 10 --> No data will be printed

Why is it working with a delay of 10 but not above? Has it something to do with timeouts which is mentioned in the docs of the library?: http://maniacbug.github.io/RF24/classRF24.html#a4cd4c198a47704db20b6b5cf0731cd58

Thank you for your answers.

mathnow
  • 21
  • 1
  • 2
  • Don't you check repeatedly to see if data becomes available later? Unless you use an interrupt from the radio to the processor, you will need to. – Chris Stratton Jan 21 '15 at 01:20
  • I check repeatedly in the sense of the standard loop. What I think is, that Arduino prints a huge amount of "No data" because of the delay. When delay is over, one single line is different, then again a huge amount of "No data" lines. I was scrolling the Serial Monitor, but this was not the case. Or maybe I scrolled not long enough? Would be interesting how many milliseconds a small loop needs to complete...But I think it's just better when I use: while(!radio.available()) {} so that only something happens when there is a payload. I will try this today. – mathnow Jan 21 '15 at 03:11
  • Yes, it's not usually useful to repeatedly log that data is not available, thiugh if you are really curious you could count the number of loops until data is obtained and print that with the data. – Chris Stratton Jan 21 '15 at 03:38
  • Nice, that's a great idea. Yes, I'm very curious about this. I will share the result after I tried. – mathnow Jan 21 '15 at 03:53
  • I consider that if statement without brackets kinda risky since it's harder to read than brackets. Apparently there's more code here; can you add that so we can see if there's another issue? I like that you tried to make it smaller, but can you please include an example with enough to compile? Thanks! (On a side note, what's this joystick variable? A class?) – Anonymous Penguin Jan 22 '15 at 14:16
  • Hey Penguin, thanks for your comment. joystick is an array and I copied the tutorial from here: http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo Just scroll down or search for "EXAMPLE ARDUINO SKETCHES" on the site. All I did was to hang on the delay after the radio.write in the YD_nRF24L01_Transmit_JoyStick example as you can see in my initial question. I am looking forward for your try :-) – mathnow Jan 23 '15 at 07:27
  • I have exactly the same issue with the same code. Joystick is an array of a few bytes. This seems to be a hardware issue. When I use the same code with nrf24l01 recently bought on Aliexpress I have this issue. With other nrf24l01 from Bangood, the same code works with 800ms delay or any other delay. There must be something different in the hardware of the new nrf24l01. –  Feb 04 '15 at 11:32
  • 2
    This is a snippet, isn't it? print('No data'); would not print "No data" because you are using the wrong quotes. It is difficult to answer such questions without the actual code being posted. – Nick Gammon Jul 08 '15 at 06:03
  • I've got the same issue and placed this issue to the Github issue tracker. hope there comes an answer: https://github.com/maniacbug/RF24/issues/68 – Greccofly Sep 06 '15 at 10:18
  • @Greccofly There will be no answer because that library has been abandoned. Please use the https://github.com/TMRh20/RF24 library. It should also be available in the builtin library manager so you don't have to worry about updating it. – Avamander Sep 29 '15 at 18:44

5 Answers5

3

In my situation the issue was with the Transmitter not continuing to transmit after a delay. I was able to resolve the issue using the powerDown (http://maniacbug.github.io/RF24/classRF24.html#aa0a51923a09ba4f3478aba9be0f8a6a1) and powerUp (http://maniacbug.github.io/RF24/classRF24.html#a5cdaf47aa0edd6dca1b9a8bb7972a1a3) functions. Here is a snipet of my code. "radioTx" is the name assigned to my transmitter.

//standard code setup for arduino uno board examples
radioTx.begin();
radioTx.setChannel(108);
radioTx.openWritingPipe(pipe);

}

void loop() {

  int dist_cm = sonar.ping_cm();


  Serial.println(dist_cm);
  radioTx.write(&dist_cm,sizeof(dist_cm));
  radioTx.powerDown();
  delay(5000);
  radioTx.powerUp();

  }
jclabonde
  • 31
  • 3
1

I had the same problem. My solution is:

First make .stopListening()

then .write(&data, sizeof(data))

and behind the write command an .startListening().

Now you can delay for longer times.

Greenonline
  • 2,938
  • 7
  • 32
  • 48
  • 1
    Welcome to Arduino SE! I'm having trouble understanding what you mean. The stopListening() command seems helpful, although can you explain how the .write(&data, sizeof(data)) would help? Thanks! – Anonymous Penguin Sep 29 '15 at 21:13
1

Try using

unsigned long t = millis();
while(millis() - t < DELAY);

instead of "delay(DELAY)"

0

Try updating your library to the new TMRh20 fork. That improves the old maniacbug's version a lot (possibly also fixing the bug). tmrh20.github.io/RF24

It's also worth noting that after you've read the message, it will print out "no data" until you receive new message.

Avamander
  • 624
  • 2
  • 11
  • 35
0

Please read this: Arduino NRF24L01+ arduino to netmf transmit issue
Although you are not using NETMF, @PhilVallone uses the library and chip together successfully, points out the samples are not asynchronous, and addresses time-out. The OP for that question is using delay(1000) and no answer has been accepted.

Jon
  • 466
  • 2
  • 5