Sensor node does not send data after sleep

Hi guys,

Trying to put sensor node to sleep and after sleep period send Atmega 328p- PU internal temperature sensor data to master.

Slave code here:

#include <RF24.h>
#include <SPI.h>
#include <nRF24l01.h>
#include <printf.h>
#include <avr/io.h>
#include "LowPower.h"
#include <avr/wdt.h>

#define CE_PIN   9
#define CSN_PIN 10

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN);

volatile char sleepCnt = 0;
char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;

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

void setup() {

    Serial.begin(9600);

    Serial.println("SimpleRxAckPayload Starting");
    radio.begin();
    radio.setDataRate(RF24_2MBPS);
    radio.openReadingPipe(1, thisSlaveAddress);

    radio.enableAckPayload();
    
    radio.startListening();
}

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

void loop() {
  system_sleep();
  getData();
  showData();
}

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

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

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

void showData() {
    if (newData == true) {
        int temperatura = GetTemp();
        int ackData[1] = {temperatura};
        Serial.print("Data received ");
        Serial.println(dataReceived);
        Serial.print(" ackPayload sent ");
        Serial.println(ackData[0]);
        newData = false;
    }
}

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

void updateReplyData() {
    int temperatura = GetTemp();
    int ackData[1] = {temperatura};
    radio.writeAckPayload(1, &ackData, sizeof(ackData)); // load the payload for the next time
}


double GetTemp(void)
{
  unsigned int wADC;
  double t;

  // The internal temperature has to be used
  // with the internal reference of 1.1V.
  // Channel 8 can not be selected with
  // the analogRead function yet.

  // Set the internal reference and mux.
  ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3));
  ADCSRA |= _BV(ADEN);  // enable the ADC

  delay(20);            // wait for voltages to become stable.

  ADCSRA |= _BV(ADSC);  // Start the ADC

  // Detect end-of-conversion
  while (bit_is_set(ADCSRA,ADSC));

  // Reading register "ADCW" takes care of how to read ADCL and ADCH.
  wADC = ADCW;

  // The offset of 324.31 could be wrong. It is just an indication.
  t = (wADC - 324.31 ) / 1.22;

  // The returned temperature is in degrees Celcius.
  return (t);
}


 void system_sleep(){
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
    Serial.println("I`m awake!");

 }

This code results like this:
results

It looks like that chip does not have enough time to do tasks after sleeping, any ideas how to modify the code to let the node do all wake routines(send data)?

You only send the data if you received anything. The problem is that the hardware doesn’t have time to receive anything as it woke up a few micros before. You should overthink the concept again. Keep in mind that the hardware cannot receive anything while the processor sleeps.

The base is pinging Slaves at 4times per second and catches every Slave that is not in the sleep mode.

res4 res5

I guess you’re missing them most of the time. If that’s OK for your project, go ahead.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.