0

I have built and coded a low power NRF24L01 transmitter and receiver, for purposes of transmitting the temperature of the transmitter's environment. I have used an Atmega328P chip for the project. The project itself works well, but after some time, around 10 days or so, the transmitter goes silent. During my initial troubleshooting, I have concluded that the system hangs up during NRF transmission, and since it's stuck in the transmission phase, it eats up all the battery and dies. For this, I'm also transmitting battery usage, and I have added watchdog timers in my temperature sensing and transmission phases. This has not solved my problem, and I'm stuck as of now.

Some bits of code: My low power cycle:

 while (1) {
  wdt_reset();  //watchdog timer added for 8S. See the beginning of loop func for timer settings.
  Serial.print("Loop Start ");
  delay(50);
    //Blink only at every wakeup
    digitalWrite(redLed, HIGH);
    setTime = millis() + ( 1 );
    while ( millis() <= setTime ) {
    }
    digitalWrite(redLed, LOW);
    //Blink only at every wakeup

    Serial.println("Powerdown begins");
      delay(50);
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
    sleepCounter++; 
    Serial.println("Powerdown over");
      delay(50);
     wdt_enable(WDTO_4S);     // enable the watchdog
  //Reenabling radio for test purposes

//end of radio edit
         Serial.print("Slept for ");
         Serial.println(sleepCounter);
    if ( sleepCounter >= postPeriod || sleepCounter == -1 || interruptState == true ){       ///|| true ) {
      sleepCounter = 0;
      interruptState = false;

      break;


    }

  }

  //Serial.println(micros());
  //Serial.println("DEBUG nRf Test");

  radio.begin();
//  radio.powerUp(); //power up the nRF24

  digitalWrite(redLed, HIGH);

  Set_nRFTX_Data (1);

  nRF_Send ();

In the Set_nRFTX_Data() function, I'm writing my temperature value to the buffer, as such :

   nRF_BufferTX [23] = b1;             // 24th byte the first byte of a two-byte value for precision (msb)
    nRF_BufferTX [24] = b2;              // 25th byte the second byte of a two-byte value for precision (lsb)

And in the nRF_Send() function, I'm sending it over NRF:

void nRF_Send () {

  radio.closeReadingPipe(address);
  radio.openWritingPipe(address);
  radio.stopListening();

  bool isDataTransfer;
  radio.write(nRF_BufferTX, 32);

  radio.openReadingPipe(1, address);
  radio.startListening();
}

If anyone's interested, I may share circuit specifications as well.

  • is setTime unsigned long? – Juraj Dec 11 '19 at 10:37
  • @Juraj Yes, I define it as unsigned long setTime = 0; – bassumex Dec 11 '19 at 11:31
  • 1
    There is a known common problem with some cheap chinese clones of the nRF24L01+ whereby they get stuck in TX mode waiting for an auto-ACK that never arrives. The only way out of it is to reset the nRF24L01+ board through the power-down/up commands. – Majenko Dec 11 '19 at 12:42
  • @Majenko is correct. I have not used nRF24L01+ for a period of 10 days like the OP, but this solution fixes short-term hangups occurring after a few minutes/hours. – MichaelT Dec 11 '19 at 13:12
  • what is the purpose of while ( millis() <= setTime )? – Juraj Dec 11 '19 at 15:57

Your Answer

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

Browse other questions tagged or ask your own question.