Unlikely Solution for NRF24 problem

Hi everyone, my first post here on the forums after lurking for a long time. :)

Ive been working on radio communication with nrf24l01 modules, and initially the transmitter code wasn't working well. It would only transmit once and then fail forever. Below is the loop function of my code:

void loop() { unsigned long currentMillis = millis(); //for timing purposes if (currentMillis - previousMillis > interval) { //every interval no. of milliseconds, previousMillis = currentMillis; radio.stopListening(); //stop listening in order to be able to send data bool ok = radio.write(&v1, sizeof(int)); //send the variable v1 with data length of an integer if (ok) { //if data was sent successfully Serial.print(v1); Serial.println(" sent ok"); } else { Serial.println("send failed"); } v1 += 1; //increment v1 if (v1 > 9999) { //rollback to zero v1 = 0; } radio.startListening(); //VERY IMPORTANT, used for "resetting" the nrf24 radio so it can continue sending data } }

After messing around, I added the last line of code (radio.startListening();), then it worked flawlessly! I guess every time you need to resend something, you need to call radio.startListening then radio.stopListening. Posting it here for documentation on this unlikely fix. :)

This Simple nRF24L01+ Tutorial may be interest.

...R

simoun96: I guess every time you need to resend something, you need to call radio.startListening then radio.stopListening.

It's the other way around,

The radio starts in standby, so if you only want to send, neither startListening nor stopListeng have to be used.

If you have started listening by calling startListening, you have to call stopListening to get back to standby to be able to send again.

write switches from standby to tx mode (if using ack after the packet to rx mode) and then back to standby.

The datasheet of the NRF24L01 explains that in all details, including the involved timings.