I have a datalogger using the RTC DS3231 as an interrupt generator. I am able to have the interrupts work but here is my problem. I would like to take 2 separate measures from 2 different sensors (one for humidity, temperature and the other for accelerations), one every 30 min et one every hour, the thing is that because I use the same pin (only one pin from the DS3231) for both of these alarms I cannot use a simple counter in my interrupt function otherwise one measure will not be taken when both of the alarms will trigger...
For example I just did a quick test with one alarm each min when seconds are 00 and an other alarm each minute when seconds are 20. The problem as I said is that I cannot increment counters for each since I use the same interrupt function (because of the single pin). Here is my loop function and interrupt handling function :
void loop() {
delay(1000);
sleepNow();
if (alarm == true){
handleAlarm(); // reset the possibility to trigger alarm
if (counter_dtphl == COUNT_DTPHL){
take_measure_DTPHL();
counter_dtphl = 0;
}
else if (counter_accel == COUNT_ACCEL){
take_measure_ACCEL();
counter_accel = 0;
}
}
}
void wakeUpNow() {
Serial.println("In wake up now");
delay(100);
alarm = true;
//Serial.println(counter);
sleep_disable();//Disable sleep mode
byte sec = get_date(SEC);
Serial.println(sec);
if (sec == 0){
counter_dtphl +=1;
}
else if (sec == 30){
counter_accel +=1;
}
detachInterrupt(digitalPinToInterrupt(interruptPin)); //Removes the interrupt from pin 2;
}
void handleAlarm() {
alarm = false;
rtcObject.LatchAlarmsTriggeredFlags();
}
COUNT_ACCEL and COUNT_DTPHL are constant having the value of minutes corresponding to the trigger for the measure.
Has anybody an idea how to manage this situation ? For the acceleration I need to save the data for a period of 30 sec. One solution I tried is to increment the counter according to the time in second that corresponds each minute but I cannot put it in the wakeUpNow function since only fast processing should be done there (it is the function executed by the interrupt).
Thank you for your time !