Sleep mode feather m0 adalogger

I have found this example code. I want to measure every 5 minutes the humidity, between every measurement the Feather should go to sleep.

Where in the code should I place the “measurement part”?

Maybe it is an easy question, but I can not found the solution yet…

// during an alarm the INT pin of the RTC is pulled low
//
// this is handy for minimizing power consumption for sensor-like devices, 
// since they can be started up by this pin on given time intervals.


#include <Wire.h>
#include "ds3231.h"

#define BUFF_MAX 256

uint8_t sleep_period = 5;       // the sleep interval in minutes between 2 consecutive alarms

// how often to refresh the info on stdout (ms)
unsigned long prev = 5000, interval = 5000;

void set_next_alarm(void)
{
    struct ts t;
    unsigned char wakeup_min;

    DS3231_get(&t);

    // calculate the minute when the next alarm will be triggered
    wakeup_min = (t.min / sleep_period + 1) * sleep_period;
    if (wakeup_min > 59) {
        wakeup_min -= 60;
    }

    // flags define what calendar component to be checked against the current time in order
    // to trigger the alarm
    // A2M2 (minutes) (0 to enable, 1 to disable)
    // A2M3 (hour)    (0 to enable, 1 to disable) 
    // A2M4 (day)     (0 to enable, 1 to disable)
    // DY/DT          (dayofweek == 1/dayofmonth == 0)
    uint8_t flags[4] = { 0, 1, 1, 1 };

    // set Alarm2. only the minute is set since we ignore the hour and day component
    DS3231_set_a2(wakeup_min, 0, 0, flags);

    // activate Alarm2
    DS3231_set_creg(DS3231_INTCN | DS3231_A2IE);
}

void setup()
{
    Serial.begin(9600);
    Wire.begin();
    DS3231_init(DS3231_INTCN);
    DS3231_clear_a2f();
    set_next_alarm();
}

void loop()
{
    char buff[BUFF_MAX];
    unsigned long now = millis();
    struct ts t;

    // once a while show what is going on
    if ((now - prev > interval) && (Serial.available() <= 0)) {
        DS3231_get(&t);

        // display current time
        snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d", t.year,
             t.mon, t.mday, t.hour, t.min, t.sec);
        Serial.println(buff);

        // display a2 debug info
        DS3231_get_a2(&buff[0], 59);
        Serial.println(buff);

        if (DS3231_triggered_a2()) {
            Serial.println(" -> alarm2 has been triggered");
            set_next_alarm();
            // clear a2 alarm flag and let INT go into hi-z
            DS3231_clear_a2f();          
        }
        prev = now;
    }
}

The humidity sensor does not have a sleep mode, so your post title is misleading, at best.

That code is NOT putting the microcontroller to sleep. What it IS doing is setting an alarm in the RTC. When the alarm goes off, absolutely nothing happens, except that a register on the RTC is set.

Periodically, the Arduino reads that register, and sees that the alarm happened.

It is a very poor starting point for what you want to do.

Oke, i am not that good at programming…

The code beneath will let the Feather go to sleep??

#include <RTCZero.h>
#include "HX711.h"
#include <Arduino.h>
#include <Wire.h>
#include "Adafruit_SHT31.h"
#include <SPI.h>
#include <SD.h>
#include "RTClib.h"
#include "QuickStats.h"

RTCZero zerortc;

// Set how often alarm goes off here
const byte alarmSeconds = 10;
const byte alarmMinutes = 0;
const byte alarmHours = 0;


volatile bool alarmFlag = true; // Start awake

void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  delay(3000); // Wait for console
  
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

  zerortc.begin(); // Set up clocks and such
  
  resetAlarm();  // Set alarm
  zerortc.attachInterrupt(alarmMatch); // Set up a handler for the alarm
} 

void loop()
{
  if (alarmFlag == true) {
        alarmFlag = false;  // Clear flag
        digitalWrite(LED_BUILTIN, HIGH);
        Serial.println("Alarm went off - I'm awake!");
      }
  resetAlarm();  // Reset alarm before returning to sleep
  Serial.println("Alarm set, going to sleep now."); 
  // Space for measurements
  digitalWrite(LED_BUILTIN, LOW);
  zerortc.standbyMode();    // Sleep until next alarm match
}



void alarmMatch(void)
{
  alarmFlag = true; // Set flag
}

void resetAlarm(void) {
  byte seconds = 0;
  byte minutes = 0;
  byte hours = 0;
  byte day = 1;
  byte month = 1;
  byte year = 1;
  
  zerortc.setTime(hours, minutes, seconds);
  zerortc.setDate(day, month, year);

  zerortc.setAlarmTime(alarmHours, alarmMinutes, alarmSeconds);
  zerortc.enableAlarm(zerortc.MATCH_HHMMSS);
}

Thanks for your help!

The code beneath will let the Feather go to sleep??

What part of that code do you think puts the Feather to sleep? Not the RTC. The Feather.

I think this part, but not sure:

zerortc.standbyMode();

I used this link for the code:
Link

If it is not true what I am doing here, do you have some tips?

Thank you

I do not think this is right to just say: "What you are doing is wrong!!!" Then, leaves the thread hanging.
~ If you are not going to help the community or at least direct to something that is helpfull, then, do not say this is wrong. We seek for a guidance not a hard NO WALL!! PaulS.