Hello
I assembled a data logger to read sensor values .
An acquisition every 3600 seconds after he goes to sleep .
Before 10 seconds , using interrupts of Ds3231 RTC you should wake up , and make the acquisition .
But sometimes I wake up before, and I can not understand why.
In any case it performs the reading correctly to the predetermined time .
I use library time.h, and DS3232RTC GitHub - JChristensen/DS3232RTC: Arduino Library for Maxim Integrated DS3232 and DS3231 Real-Time Clocks
More, the interrupt function to wake up does not work with FALLING
The code
Many thanks
#include <DS3232RTC.h>
#include <Time.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include "DHT.h"
#include <Adafruit_ADS1015.h>
#include <avr/sleep.h>
#include <avr/power.h>
........
int Pin2 = 2; //connected at ds3231 rtc INT
int Pin3 = 3; //connected at switch for manual wake up
pinMode(Pin2, INPUT_PULLUP);
void pin2Interrupt(void) {
tipoint="int2";
}
void pin3Interrupt(void) {
tipoint="int3";
}
//tmobbie predetermination time
void enterSleep(void){
String riga;
tm=now();
riga=p2d(day())+"/"+p2d(month())+"/"+year()+" "+p2d(hour())+":"+p2d(minute())+":"+p2d(second())+" Sleep";
File dataFile = SD.open(nomef, FILE_WRITE);
if (dataFile) {
dataFile.println(riga);// log into file when go to sleep
dataFile.flush();
dataFile.close();
}
if (tmobbie<tm+15){return;}
RTC.squareWave(SQWAVE_NONE);
RTC.setAlarm(ALM1_MATCH_DATE,second(tmobbie-10),minute(tmobbie-10), hour(tmobbie-10),day(tmobbie-10)); //setting wake up time
RTC.alarm(ALARM_1); clear flag
RTC.alarm(ALARM_2); clear flag
RTC.alarmInterrupt(ALARM_1,true); //setting up alarm
RTC.alarmInterrupt(ALARM_2,false);
delay(500);
SpegniLCD();
lcd.setCursor(0,0);
lcd.clear();
lcd.print("Sleep");
attachInterrupt(digitalPinToInterrupt(2), pin2Interrupt,LOW); // -> FALLING does not work no wake up
attachInterrupt(digitalPinToInterrupt(3), pin3Interrupt, LOW);// -> FALLING does not work no wake up
delay(200);
sleep_enable();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_cpu();
detachInterrupt(0);
detachInterrupt(1);
setSyncProvider(RTC.get); // the function to get the time from the RTC
sleep_disable();
CambiaScenario=true;
riga=p2d(day())+"/"+p2d(month())+"/"+year()+" "+p2d(hour())+":"+p2d(minute())+":"+p2d(second())+" Wakeup"+tipoint;
dataFile = SD.open(nomef, FILE_WRITE);
if (dataFile) {
dataFile.println(riga);// log into file when wakeup
dataFile.flush();
dataFile.close();
}
}