Hi.
I have got RTC DS3231 working pretty well. I set my RTC to send interrupt signal on int.0 (pin2) every full minute. Was working great, I had the LED switch ON/OFF every minute. I assumed here that interrupts are working and I can use it as interrupt to wake an Arduino up. Well not so much.
Must mention here that I am using:
This library for low power
and
This library for DS3231.
As provided in an
example from library and
HERE I am told that I can wake up Arduino when pin is low.
What I would like to achieve is obviously to wake Arduino up on interrupt from DS3231 every minute.
Here is my code. Would appreciate any help on that.
// Using JChristensen library
#include <DS3232RTC.h>
#include <Time.h>
#include <Wire.h>
#include "LowPower.h"
tmElements_t tm;
time_t cvt_date(char const *date, char const *time)
{
char s_month[5];
int year;
tmElements_t t;
static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
sscanf(date, "%s %hhd %d", s_month, &t.Day, &year);
sscanf(time, "%2hhd %*c %2hhd %*c %2hhd", &t.Hour, &t.Minute, &t.Second);
t.Month = (strstr(month_names, s_month) - month_names) / 3 + 1;
/*
if( year > 99)
t.Year = year - 1970;
else
t.Year = year + 30;
*/
t.Year = year - 1970;
return makeTime(t);
}
int switchPin = 2;
int ledPin = 13;
boolean lastButton = LOW;
boolean ledOn = false;
void blink() {
if (digitalRead(switchPin) == HIGH && lastButton == LOW) {
ledOn = !ledOn;
lastButton = HIGH;
} else {
lastButton = digitalRead(switchPin);
}
digitalWrite(ledPin, ledOn);
}
void pin2Interrupt(void)
{
}
void setup(void) {
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
pinMode(switchPin,INPUT);
//attachInterrupt(0, pin2Interrupt, CHANGE);
Serial.println(String("__DATE__ = ") + __DATE__);
Serial.println(String("__TIME__ = ") + __TIME__);
setTime(cvt_date(__DATE__, __TIME__));
RTC.set(now());
RTC.squareWave(SQWAVE_NONE);
RTC.setAlarm(ALM2_EVERY_MINUTE,0,0,0);
RTC.alarmInterrupt(ALARM_2, true);
Serial.println(String("System date = ") + day() + "/" + month() + "/" + year() + " " + hour() + ":" + minute() + ":" + second() + "\n");
}
void loop(void) {
//digitalClockDisplay(); //print time and date
Serial.println("Entering sleep mode");
delay(1000);
attachInterrupt(0, pin2Interrupt, LOW);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
detachInterrupt(0);
}
void digitalClockDisplay(void)
{
// digital clock display of the time
RTC.read(tm);
Serial.print(tm.Day,DEC);
Serial.print('/');
Serial.print(tm.Month, DEC);
Serial.print('/');
Serial.print(tm.Year+1970, DEC);
Serial.print(" ");
Serial.print(tm.Hour, DEC);
Serial.print(':');
Serial.print(tm.Minute, DEC);
Serial.print(':');
Serial.println(tm.Second, DEC);
if (RTC.alarm(ALARM_2) ) {
Serial.println("ALARM");
}
}
I have 4.7k Ohm resistor between SQW and +5V.