0

DS3231 Adafruit breakout board to cause multiple Interrupt S
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

DS3231 Adafruit breakout board to cause multiple Interrupt S

by mbobinger on Fri Aug 02, 2019 11:54 am

Dear fellow Adafruit enthusiasts,

I have programmed my ATMEGA328 standalone as well as on the Arduino UNO to wake up each minute, record some sensor values and then go back to sleep again. The interrupt is triggered by a DS3231 module:
https://learn.adafruit.com/adafruit-ds3 ... t/overview

with the library from Makuna:
https://github.com/Makuna/Rtc

To sum up, everything works fine with following code reduced for simplicity:

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <SPI.h>

#include <OneWire.h> //library for the temperature sensor
#include <LowPower.h> //rocketscream library
#include <RtcDS3231.h> //RTC library clock that sets the RTC alarm and RTC time
#include <DallasTemperature.h> //DS18 digital temperature library
RtcDS3231<TwoWire> Rtc2(Wire);
volatile boolean alarm = 1;
const byte interruptPin=3;

}

void do_send(osjob_t* j){
    alarm = false;
  RtcDateTime timestamp = Rtc2.GetDateTime();
   
}

void setup() {
    delay(5000); //delay to get the chip programmed
    Serial.begin(115200);
   
    Serial.println(F("Starting..."));
   
 

    pinMode(ECPin,INPUT);
  pinMode(ECPower,OUTPUT);//Setting pin for sourcing current
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);
 
//Section for RTCzero library that sets the internal time of the MCU and puts the MCU to sleep via standbyMode();

Rtc2.Begin();
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
Rtc2.SetDateTime(compiled);
RtcDateTime now = Rtc2.GetDateTime();
Rtc2.Enable32kHzPin(false);
Rtc2.SetSquareWavePin(DS3231SquareWavePin_ModeAlarmBoth);

RtcDateTime alarmTime = now + 88; // into the future
    DS3231AlarmOne alarm1(
            alarmTime.Day(),
            alarmTime.Hour(),
            alarmTime.Minute(),
            alarmTime.Second(),
            DS3231AlarmOneControl_HoursMinutesSecondsMatch);
  Rtc2.SetAlarmOne(alarm1);         
    DS3231AlarmTwo alarm2(
            0,
            0,
            0,
            DS3231AlarmTwoControl_OncePerMinute);
    Rtc2.SetAlarmTwo(alarm2);
    Rtc2.LatchAlarmsTriggeredFlags(); 
    sensors.begin(); 
}

void loop() {
  if (alarm == true) {
   // handleAlarm();
    os_runloop_once();
  }
 //  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
}

void handleInterrupt() {
  alarm = true;
}


I would now also like to have the functionality to call interrupts each 5 or 15 minutes or each 2 hours. How can that be achieved?

I would also like to have different Interrupt Service Routines. The one that interrupts each 1 minute should measure different sensor values than the one that interrupts each hour.

Do you have any idea how this can be realized? Please forward me links or ideas :).

Thank you!

mbobinger
 
Posts: 18
Joined: Mon Jul 15, 2019 8:10 am

Re: DS3231 Adafruit breakout board to cause multiple Interru

by adafruit_support_mike on Sat Aug 03, 2019 3:38 pm

The DS3231 only has one interrupt pin, so you won't be able to trigger multiple different interrupts.

You'll have to handle the different kinds of behavior in code, reading the DS3231's timer value and using that to decide what the microcontroller should do.

adafruit_support_mike
 
Posts: 59184
Joined: Thu Feb 11, 2010 2:51 pm

Re: DS3231 Adafruit breakout board to cause multiple Interru

by mbobinger on Sun Aug 04, 2019 12:35 pm

adafruit_support_mike wrote:The DS3231 only has one interrupt pin, so you won't be able to trigger multiple different interrupts.

You'll have to handle the different kinds of behavior in code, reading the DS3231's timer value and using that to decide what the microcontroller should do.


Dear Mike,
Thank you a lot! How can i call an interrupt each 5 minutes for example and not each minute, hour or day using the DS3231 clock?

mbobinger
 
Posts: 18
Joined: Mon Jul 15, 2019 8:10 am

Re: DS3231 Adafruit breakout board to cause multiple Interru

by adafruit_support_mike on Sun Aug 04, 2019 1:41 pm

Pretty much the same way you set it to generate alarms every minute, but with a 5-minute specifier. What code are you using now?

adafruit_support_mike
 
Posts: 59184
Joined: Thu Feb 11, 2010 2:51 pm

Re: DS3231 Adafruit breakout board to cause multiple Interru

by mbobinger on Mon Aug 05, 2019 7:37 am

adafruit_support_mike wrote:Pretty much the same way you set it to generate alarms every minute, but with a 5-minute specifier. What code are you using now?


Hi Mike, thank you a lot. Below is my code, I'm using the library of Makuna:
https://github.com/Makuna/Rtc

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <SPI.h>

#include <OneWire.h> //library for the temperature sensor
#include <LowPower.h> //rocketscream library
#include <RtcDS3231.h> //RTC library clock that sets the RTC alarm and RTC time
#include <DallasTemperature.h> //DS18 digital temperature library
RtcDS3231<TwoWire> Rtc2(Wire);
volatile boolean alarm = 1;
const byte interruptPin=3;

}

void do_send(osjob_t* j){
    alarm = false;
  RtcDateTime timestamp = Rtc2.GetDateTime();
   
}

void setup() {
    delay(5000); //delay to get the chip programmed
    Serial.begin(115200);
   
    Serial.println(F("Starting..."));
   
 

    pinMode(ECPin,INPUT);
  pinMode(ECPower,OUTPUT);//Setting pin for sourcing current
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);
 
//Section for RTCzero library that sets the internal time of the MCU and puts the MCU to sleep via standbyMode();

Rtc2.Begin();
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
Rtc2.SetDateTime(compiled);
RtcDateTime now = Rtc2.GetDateTime();
Rtc2.Enable32kHzPin(false);
Rtc2.SetSquareWavePin(DS3231SquareWavePin_ModeAlarmBoth);

RtcDateTime alarmTime = now + 88; // into the future
    DS3231AlarmOne alarm1(
            alarmTime.Day(),
            alarmTime.Hour(),
            alarmTime.Minute(),
            alarmTime.Second(),
            DS3231AlarmOneControl_HoursMinutesSecondsMatch);
  Rtc2.SetAlarmOne(alarm1);         
    DS3231AlarmTwo alarm2(
            0,
            0,
            0,
            DS3231AlarmTwoControl_OncePerMinute);
    Rtc2.SetAlarmTwo(alarm2);
    Rtc2.LatchAlarmsTriggeredFlags();
    sensors.begin();
}

void loop() {
  if (alarm == true) {
   // handleAlarm();
    os_runloop_once();
  }
 //  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
}

void handleInterrupt() {
  alarm = true;
}

mbobinger
 
Posts: 18
Joined: Mon Jul 15, 2019 8:10 am

Re: DS3231 Adafruit breakout board to cause multiple Interru

by adafruit_support_mike on Mon Aug 05, 2019 12:12 pm

I don’t know anything about that library, but it looks like this is the kine that sets the alarm time:

Code: Select all | TOGGLE FULL SIZE
RtcDateTime alarmTime = now + 88; // into the future
If you change the value added to ‘now’, it should change the alarm timing.

adafruit_support_mike
 
Posts: 59184
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.