NRF24l01 how to pause transmission

Using NRF2401 Tx and Rx.

Want to stop transmission once Rx acknowledges receipt of data and only re-commencing

transmission when input data changes.

eg. Transmit Input integer (say) 123 until Rx acknowledges receipt then no transmission until input

changes to (say) 218, then basically only transmitting when new integer is input.

Also could use some advice on a sketch to transmit a 5 element integer array then

disassembling array at Rx end

Considering that an nRF24 transmission only takes a few millisecs I can't imagine why you would want to pause it.

However maybe you mean something else - but you have not posted your program.

Have a look at this Simple nRF24L01+ Tutorial. I think it should answer your questions.

...R

Thanks I have read that tutorial but it doe's not seem to answer.

I am sending data to a second Arduino which will switch on a solenoid. Once the data is

action ed by the Rx Arduino I do not want to keep receiving the original data. In a 24 hour period

I could send about 100 instructions to the Rx to turn on and off a solenoid, so once an

instruction has been received and action-ed, I do not want it repeating over and over.

I am seeking some way to send the signal from Tx to Rx and then just stop Transmitting and

pause until the next data is ready for Transmission.

Please post your code you wrote for your RX and TX.

That way we can help you code it in if possible... :slight_smile:

Farticus:
Thanks I have read that tutorial but it doe's not seem to answer.

I am sending data to a second Arduino which will switch on a solenoid. Once the data is action ed by the Rx Arduino I do not want to keep receiving the original data.

So stop sending the data ?

...R

If the repeated commands are simple switch-on or switch-off commands,

switching things on that are already on does not hurt (and could be ignored),
same holds true for switching off things that are already off.

If a command comes in that changes the state I see no good reason to ignore that command.

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

// This is just the way the RF24 library works:
// Hardware configuration: Set up nRF24L01 radio on SPI bus (pins 10, 11, 12, 13) plus pins 7 & 8
RF24 radio(7, 8);

byte addresses[][6] = {"1Node", "2Node"};

 unsigned long messageTx =0;

// -----------------------------------------------------------------------------
// SETUP   SETUP   SETUP   SETUP   SETUP   SETUP   SETUP   SETUP   SETUP
// -----------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  Serial.println("THIS IS THE TRANSMITTER CODE - YOU NEED THE OTHER ARDIUNO TO SEND BACK A RESPONSE");

  // Initiate the radio object
  radio.begin();

  // Set the transmit power to lowest available to prevent power supply related issues
  radio.setPALevel(RF24_PA_MIN);

  // Set the speed of the transmission to the quickest available
  radio.setDataRate(RF24_2MBPS);

  // Use a channel unlikely to be used by Wifi, Microwave ovens etc
  radio.setChannel(124);

  // Open a writing and reading pipe on each radio, with opposite addresses
  radio.openWritingPipe(addresses[1]);
  radio.openReadingPipe(1, addresses[0]);

  // Random number seeding (we're going to be sending a single random number)
  randomSeed(analogRead(A0));
}

// -----------------------------------------------------------------------------
// LOOP     LOOP     LOOP     LOOP     LOOP     LOOP     LOOP     LOOP     LOOP
// -----------------------------------------------------------------------------
void loop() {

  /////////////////////INTEGER INPUT//////////////////

  // Take an input from RTC
  //  eg  If RTC says Thursday 14:23 then turn on Solenoid 12.(eg) Would generate integer 120
  //  eg  If RTC says Thursday 15:23 then turn off Solenoid 12.(eg)Would generate integer 121
  // this would happen up to 100 times per day at various times for various solenoids
  
 
 messageTx = 120;  // Integer is transmitted to Rx as a command to turn on or off a certain
                   // solenoid at a certain time and once executed is nor required to be
                   // transmitted over and over.
    
  // Ensure we have stopped listening (even if we're not) or we won't be able to transmit
  radio.stopListening(); 

  // Did we manage to SUCCESSFULLY transmit that (by getting an acknowledgement back from the other Arduino)?
  // Even we didn't we'll continue with the sketch, you never know, the radio fairies may help us
  if (!radio.write( &messageTx, sizeof(unsigned char) )) {
    Serial.println("No acknowledgement of transmission - receiving radio device connected?");    
  }

  // Now listen for a response
  radio.startListening();
  
  // But we won't listen for long, 200 milliseconds is enough
  unsigned long started_waiting_at = millis();

  // Loop here until we get indication that some data is ready for us to read (or we time out)
  while ( ! radio.available() ) {

    // Oh dear, no response received within our timescale
    if (millis() - started_waiting_at > 200 ) {
      Serial.println("No response received - timeout!");
      return;
    }
  }

  // Now read the data that is waiting for us in the nRF24L01's buffer
  unsigned char messageRx;
  radio.read( &messageRx, sizeof(unsigned char) );

  // Show user what we sent and what we got back
  Serial.print("Sent: ");
  Serial.print(messageRx);
  Serial.print(", received: ");
  Serial.println(messageRx);

  // Try again 1s later
  delay(1000);
}

What I would like to do is Tx the integer until Rx acknowledges receipt then just stop the transmission

until the RTC triggers the next integer to be Transmitted and the process starts all over again.

I am not sure how to do this.

??? radio.stop ???

??? pause ???

??? radio.listen ???

Robin2 suggests “stop sending data” which is exactly my question . How??

I know this is probably a silly question but I am not sure how best to do this.

Thanks for your responses

You stop any process by not continuing to perform it.

If you don't send packets, there is no usage of the medium or any resource.

Farticus:
What I would like to do is Tx the integer until Rx acknowledges receipt then just stop the transmission

something like this maybe (not tested) … its got a Rx timout to stop Tx if Rx is not received within that time. it should also stop Tx if Rx something withing that timeout.

hope that helps…

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

/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(7, 8);
/**********************************************************/

byte addresses[][6] = {"1Node", "2Node"};

// Used to control whether this node is sending or receiving
bool RTC_trig = false;

void setup() {
  Serial.begin(115200);
  Serial.println(F("RF24/examples/GettingStarted"));
  Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));

  radio.begin();

  // Set the PA Level low to prevent power supply related issues since this is a
  // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
  radio.setPALevel(RF24_PA_LOW);

  // Open a writing and reading pipe on each radio, with opposite addresses
  radio.openWritingPipe(addresses[1]);
  radio.openReadingPipe(1, addresses[0]);

  // Start the radio listening for data
  radio.startListening();
}

void loop() {

  // Take an input from RTC
  //  eg  If RTC says Thursday 14:23 then turn on Solenoid 12.(eg) Would generate integer 120
  //  eg  If RTC says Thursday 15:23 then turn off Solenoid 12.(eg)Would generate integer 121
  // this would happen up to 100 times per day at various times for various solenoids
  //  RTC_trig=true; <------ SET TO TRUE IF it is time to do something

  uint8_t messageTx = 120;  // Integer is transmitted to Rx as a command to turn on or off a certain
  // solenoid at a certain time and once executed is nor required to be
  // transmitted over and over.

  if (RTC_trig)  {

    send_msg(&messageTx);

    unsigned long started_waiting_at = millis();               // Set up a timeout period, get the current microseconds
    boolean timeout = false;                                   // Set up a variable to indicate if a response was received or not
    uint8_t timeout_cnt = 0;

    while ( ! radio.available() ) {                            // While nothing is received
      if (millis() - started_waiting_at > 20 ) {           // If waited longer than 20ms, re-transmit message.
        send_msg(&messageTx);
        started_waiting_at = millis();
        ++timeout_cnt;
      }
      else if (timeout_cnt > 10) {                        // If waited longer than 200ms (20ms *10), indicate timeout and exit while loop
        timeout = true;
      }
    }

    if ( timeout ) {                                            // Describe the results
      Serial.println(F("Failed, response timed out."));
      RTC_trig = false;
    }
    else {
      uint8_t got_reply;                                 // Grab the response and compare for check
      radio.read( &got_reply, sizeof(uint8_t) );

      // Spew it
      Serial.print(F("Sent "));
      Serial.print(messageTx);
      Serial.print(F(", Got response "));
      Serial.print(got_reply);
      RTC_trig = false;
    }
  }

} // Loop

void send_msg(uint8_t *messageTx) {
  
  radio.stopListening();                                    // First, stop listening so we can talk.

  Serial.println(F("Now sending"));

  if (!radio.write( messageTx, sizeof(uint8_t) )) { // Take the time, and send it.  This will block until complete
    Serial.println(F("failed"));
  }

  radio.startListening();                                    // Now, continue listening
}

I am still not clear why you want to stop the transmission. Why not do the "has the transmitted value changed" test on the Rx end ?

Farticus:
Robin2 suggests "stop sending data" which is exactly my question . How??

Radio.write() sends a single message. Just do it once whenever you need it.

Have you studied the first example in my Tutorial. It sends a message once per second. You could change the interval to anything you like. The acknowledgement is automatic.

...R

hello , i also want to implement the same code for pausing my data transmission once it has transmiisted the data and recieved an acknowlegement but the above code is not working

I really don't see what the mental roadblock here is. Once you've sent the data and received the acknowledgement, just don't send it again. Instead wait until you want to send data again (probably because the data has changed). Then, send that new data.

samarthasnani:
hello , i also want to implement the same code for pausing my data transmission once it has transmiisted the data and recieved an acknowlegement but the above code is not working

Have you read and acted upon the second sentence in Reply #10 ?

If not, why did you post your question right after it?

...R