Arduino pro mini - NRF24L01 - ACKPAYLOAD and Watchdog

Hello,

I want to carry on a home installation to get the values of several temperature sensors and to display these on a website.

This installation will be based on arduino pro mini coupled with an NRF24L01 + for the sensors and, in the development phase, a UNO + an NRF24L01 +.

Thanks to the examples found on the forums, I manage to use the ACKPAYLOAD functionality of NRF24L01 (https://forum.arduino.cc/index.php?topic=421081).

And it’s working.

Now I would like to switch to low power consumption for the sensors and use the Watchdog function of the arduino pro mini.

But it don’t work! I receive one data and then nothing.

However, the cookies that I put in the master TX sketch seem to indicate that “ackPayload is Available” and that the message has been sent to the slave “radio.write successful”.

On the side of the RX slave, the messages also seem to indicate that the sending of the ackPayload is well done but only once.

I do not understand where it fail.

Can you help me ?

Below are the Sketches and serial monitor outputs:

TX Master:

#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#define CE 9//UNO
#define CS 10

//#define CE D2//wemos D1
//#define CS D8//wemos D1

//NRF24L01
RF24 radio(CE, CS);                // Micro nRF24L01 (CE,CSN)
byte dataToSend = 0; //Message envoyé pour collecte datas à chaque capteur
//char dataToSend = 'm'; //Message envoyé pour collecte datas à chaque capteur
float ackData; //Réponse avec datas des capteurs
uint8_t nbrCapteurs = 0;

const uint8_t numSlaves = 13;
const uint8_t slaveAddress[numSlaves][5] = {
  {'R', 'x', 'A', 'A', 'A'},
  {'R', 'x', 'A', 'A', 'B'},
  {'R', 'x', 'A', 'A', 'C'},
  {'R', 'x', 'A', 'A', 'D'},
  {'R', 'x', 'A', 'A', 'E'},
  {'R', 'x', 'A', 'A', 'F'},
  {'R', 'x', 'A', 'A', 'G'},
  {'R', 'x', 'A', 'A', 'H'},
  {'R', 'x', 'A', 'A', 'I'},
  {'R', 'x', 'A', 'A', 'J'},
  {'R', 'x', 'A', 'A', 'K'},
  {'R', 'x', 'A', 'A', 'L'},
  {'R', 'x', 'A', 'A', 'M'}
};



void setup() {
  Serial.begin(115200);
  SPI.begin(); //Communication RF
  delay(50);
  radio.begin();
  radio.setChannel(120);
  radio.setDataRate(RF24_2MBPS);
  radio.setPALevel(RF24_PA_LOW);
  radio.enableAckPayload();
  radio.setRetries(5, 3); // delay, count
  Serial.println("Choisir le nombre de capteurs");
  while (nbrCapteurs == 0) {
    if (Serial.available()) {
      nbrCapteurs = Serial.read() - '0';
    }
  }
}

void loop() {
  for (uint8_t n = 0; n < nbrCapteurs; n++) {
    radio.openWritingPipe(slaveAddress[n]);
    dataToSend++;
    if (dataToSend > 9) {
      dataToSend = 0;
    }
    if (radio.write(&dataToSend, sizeof(dataToSend))) {
      Serial.println("radio.write successful");
      if (radio.isAckPayloadAvailable()) {
        Serial.println("ackPayloadAvailable");
        radio.read(&ackData, sizeof(ackData));
        Serial.print("capteur N°: ");
        Serial.print(n);
       // Serial.println(dataToSend);
       Serial.print(" - ");
        Serial.println(ackData);
      }
    }
  }
  delay(3000);
}

RX SlaveA :

//ref : https://forum.arduino.cc/index.php?topic=668082.0
//https://forum.arduino.cc/index.php?topic=421081
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include "cactus_io_DS18B20.h"
#include <avr/sleep.h>
#include <avr/wdt.h>

float temperature = 0.0;
int DS18B20_Pin = 3; //DS18b20 Signal pin on digital 3
DS18B20 ds(DS18B20_Pin); // on digital pin 3

#define CE_PIN 7//PCB
#define CSN_PIN 8//PCB

const uint8_t address[5] = {'R', 'x', 'A', 'A', 'A'};

RF24 radio(CE_PIN, CSN_PIN);

ISR (WDT_vect)
{
  wdt_disable(); //désactive le watchdog
}

void myWatchdogEnable(const byte interval)
{
  MCUSR = 0;                          // reset various flags
  WDTCSR |= 0b00011000;               // see docs, set WDCE, WDE
  WDTCSR =  0b01000000 | interval;    // set WDIE, and appropriate delay

  wdt_reset();
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);
  sleep_mode();            // now goes to Sleep and waits for the interrupt
}
// sleep bit patterns:
//  1 second:  0b000110
//  2 seconds: 0b000111
//  4 seconds: 0b100000
//  8 seconds: 0b100001

byte dataReceived;
//char dataReceived[10]; // this must match dataToSend in the TX
float ackData; // the values to be sent to the master
bool newData = false;

int test;

void setup() {
  Serial.begin(115200);

  ds.readSensor();
  delay(3000); // allow 3 seconds for sensor to settle down
  ds.readSensor(); // read again to avoid weird values for defaults

  radio.begin();
  radio.setChannel(120);
  radio.setDataRate(RF24_2MBPS);
  radio.setPALevel(RF24_PA_LOW);
  radio.openReadingPipe(1, address);
  radio.enableAckPayload();

  radio.startListening();

  radio.writeAckPayload(1, &ackData, sizeof(ackData)); // pre-load data
}

void loop() {
  radio.powerUp(); //alimente le module nrf24l01+
  delay(3000); //attente 3 secondes avant d'effectuer une mesure du capteur
  readTemp();
  getData();
  showData();
  delay(500);
  radio.powerDown(); //arrêt de l'alimentation du module nrf24l01+
  for (int i = 0; i < 30; i++) //mise en veille pendant 240 secondes
  {
       myWatchdogEnable (0b100001);  // 8 seconds
   // myWatchdogEnable (0b000111);  // 2 seconds
  }
}

void getData() {
  if ( radio.available() ) {
    radio.read( &dataReceived, sizeof(dataReceived) );
    updateReplyData();
    newData = true;
  }
}

//================

void updateReplyData() {
  test++;
  if (test > 100) {
    test = 0;
  }
  //  sprintf(ackData, "i0/%i/%s/%s/%s", test, "01", "01", "01");
  radio.writeAckPayload(1, &ackData, sizeof(ackData)); // load the payload for the next time
}

//================

void showData() {
  if (newData == true) {
    Serial.print("Data received : ");
    Serial.println(dataReceived);
    Serial.print(" ackPayload sent : ");
    Serial.println(ackData);
    newData = false;
  }
}
//================

void readTemp() {
  ds.readSensor();
  delay(3000); // allow 3 seconds for sensor to settle down
  ds.readSensor(); // read again to avoid weird values for defaults
  temperature = ds.getTemperature_C();
  ackData = temperature;
  Serial.print(F("\tTemperature Ext : "));
  Serial.print((ackData), 2);
  Serial.println(" °C");
  delay(1000);
}

Message TX master :

Choisir le nombre de capteurs
radio.write successful
ackPayloadAvailable
capteur N°: 0 - 0.00
radio.write successful
radio.write successful
ackPayloadAvailable
capteur N°: 0 - 21.69

Message RX slave A :

RadioPowerUp
	Temperature Ext : 21.69 °C
Radio Available
Data received : 1
 ackPayload sent : 21.69
RadioPowerUp
	Temperature Ext : 21.69 °C
Radio Available
Data received : 2
 ackPayload sent : 21.69
RadioPowerUp
	Temperature Ext : 21.75 °C
Radio Available
Data received : 3
 ackPayload sent : 21.75