Hi,
I'am making an alarm clock with Arduino UNO and DS3231 component.
Can you suggest me an update Library for DS3231 I2C to work with date/time/alarm?
Thanks in advance.
Hi,
I'am making an alarm clock with Arduino UNO and DS3231 component.
Can you suggest me an update Library for DS3231 I2C to work with date/time/alarm?
Thanks in advance.
Using the words "Library for DS3231 I2C" entered into my favortire internet engine provided me with a list of libraries to choose from. After that it is a matter of looking through the libraries for things such as last updated and methods listed. Pick a few and give them a test to see if the libraries meet your requirements.
Check out the DS3232RTC library by J Christensen.
On that page there's also a link to an 'alarm-primer' that he wrote.
Don
Thank you Floresta fou your suggested library.
The problem that I have got is: I can't disabled alarm on my DS3231.
I set the alarm1 for example.
The alarm is triggered at the right time but then I can't disabled it to prevent next triggered.
Can you suggest my something or post an example sketch please?
I haven't worked with the DS3231 alarms in a few years and when I did I didn't use a library. If you are comfortable with dealing with the clock registers directly here is some of what I found in my archives:
// ======================== DS3231 RTC related code ======================
void setAlarmRTC()
{
Wire.begin(); // enable I2C communications
clearAlarms(); // get rid of any old Alarm settings
setAlarm2EveryMinute(); // set Alarm 2
// enable interrupt from Alarm 2 and turn clock oscillator on
// enable interrupt from Alarm 2
// enable interrupts from the clock
// make sure the clock is running
/* DS3231 Control Register
0 0 0 0 0 1 1 0
| | | | | | | |_____ (A1IE) - disable Alarm 1 interrupt
| | | | | | |_______ (A2IE) - enable Alarm 2 interrupt
| | | | | |_________ (INTCN) - enable interrupts from alarms
| | | | |___________ (RS1) - 1 Hz square wave (if enabled)
| | | |_____________ (RS2) -
| | |_______________ (CONV) - do not read chip temperature
| |_________________ (BBSQW) - disable square wave output
|___________________ (EOSC) - enable oscillator (low turns clock on)
*/
Wire.beginTransmission(addr_DS3231); // access RTC
Wire.write(0x0E); // point to Control register
Wire.write(0b00000110); // write bitmap to register
Wire.endTransmission();
clearA2F(); // clear the Alarm 2 flag
}
// .......................................................................
void clearAlarms()
{
// clear Alarm 1
Wire.beginTransmission(addr_DS3231);
Wire.write(uint8_t(0x07)); // lowest Alarm 1 register
Wire.write(uint8_t(0b00000000));
Wire.write(uint8_t(0b00000000));
Wire.write(uint8_t(0b00000000));
Wire.write(uint8_t(0b00000000));
Wire.endTransmission();
// clear Alarm 2
Wire.beginTransmission(addr_DS3231);
Wire.write(uint8_t(0x0b)); // lowest Alarm 2 register
Wire.write(uint8_t(0b00000000));
Wire.write(uint8_t(0b00000000));
Wire.write(uint8_t(0b00000000));
Wire.endTransmission();
}
// .......................................................................
void setAlarm2EveryMinute()
{
// set Alarm 2 to generate an alarm (interrupt) every minute
Wire.beginTransmission(addr_DS3231);
Wire.write(uint8_t(0x0b)); // lowest Alarm 2 register
// Alarm once per minute (00 seconds of every minute)
Wire.write(uint8_t(0b10000000)); // A2M2 set --> ignore minutes bits
Wire.write(uint8_t(0b10000000)); // A2M3 set --> ignore hours bits
Wire.write(uint8_t(0b10000000)); // A2M4 set --> ignore day/date bits
Wire.endTransmission();
}
// .......................................................................
//clear A2F
void clearA2F()
{
Wire.beginTransmission(addr_DS3231);
Wire.write(0x0F); // Status register
Wire.requestFrom(addr_DS3231, 1); // get one byte
while(Wire.available())
{
byte tmp = Wire.read(); // get current status
bitClear(tmp, 1); // clear the Alarm 2 Flag
Wire.write(tmp); // write new status
}
Wire.endTransmission();
}
Don
Hello. Sorry for my intrusion, but can you explain why use this routine:
//clear A2F
void clearA2F()
{
Wire.beginTransmission(addr_DS3231);
Wire.write(0x0F); // Status register
Wire.requestFrom(addr_DS3231, 1); // get one byte
while(Wire.available())
{
byte tmp = Wire.read(); // get current status
bitClear(tmp, 1); // clear the Alarm 2 Flag
Wire.write(tmp); // write new status
}
Wire.endTransmission();
}
Couldn't be like void clearAlarms()?
void clearA2F()
{
Wire.beginTransmission(addr_DS3231);
Wire.write(uint8_t(0x0F)); // Status register
Wire.write(uint8_t(0b00000000));
Wire.endTransmission();
}
Thanks in advance!
yago4xd:
Hello. Sorry for my intrusion, but can you explain why use this routine:
. . .
Sorry - I wrote that several years ago and I really don't remember.
Actually I don't even remember what I had for breakfast yesterday - it gets worse as you get older.
Don
Hahaha don't worry. I'll see more references about.
Thanks!
There is a pair of libraries TIME and TIME ALARMS. The latter needs the former. I haven't used them for years but they seemed to do everything.