Use RTC DS3231 to wake up an ESP8266

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
alzzla
 
Posts: 5
Joined: Fri Oct 21, 2016 7:53 am

Use RTC DS3231 to wake up an ESP8266

Post by alzzla »

Hi,

I'm designing an alarm clock with an ESP8266 (Nodemcu) and the DS3231 RTC module. My system doesn't have any battery, it will be constantly powered through USB. I'd like to keep my ESP866 in deepsleep and waking it up at a specific time thanks to the RTC.

I first created a software alarm with the TimeAlarms library and it works fine. Now I'm trying to do the same thing directly with the hardware. My idea is that the RTC would send an impulse to the ESP8266 at a specific time set in one of the two alarms available on the DS3231 that would wake it up.

I'm using the Adafruit RTC library that works perfectly but there isn't any example of alarm setting.

Any idea ?

Thanks

Alizee

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Use RTC DS3231 to wake up an ESP8266

Post by adafruit_support_rick »

We don't have any example code for that, and the library doesn't implement alarms. You will have to write the configuration registers in your sketch.
See page 12 of the datasheet for a description of the alarm functionality
https://cdn-shop.adafruit.com/product-f ... DS3231.pdf

You will have to write the Control Register (0x0E) to enable alarms and the alarm interrupt signals.
The format of the alarm registers is shown on page 11.

You will want to do read-modify-write operations on the registers. That is, you read the contents of the register, then modify the appropriate bits, then write the register back to the chip.
To modify, first clear the necessary bits, then write the new bits.

For instance, to enable interrupts on Alarm 1, you would set the INTCN bit and the A1IE bit. First, define the bit positions (these lines would go before setup():

Code: Select all

#define CTRL_REG 0x0E  /*Control Register address */
#define INTCN 4 /*INTCN is bit 2 of Control Register*/
#define A1IE 2  /*A1IE is bit 1 of Control Register*/
#define A1IE 1  /*A1IE is bit 0 of Control Register*/
Now, write a function to enable alarm 1 interrupts:

Code: Select all

void EnableAlarm1()
{
  //read control register
  Wire.requestFrom(DS3231_Address, CTRL_REG);
  uint8_t ctrlreg = Wire.read(); 

  //modify register contents
  ctrlreg &= ~(A2IE);  //clear A2IE bit
  ctrlreg |= (INTCN | A1IE);  //set INTCN and A1IE bits

  //Write control register
  Wire.BeginTransmission(DS3231_Address);
  Wire.write(CTRL_REG);
  Wire._I2C_WRITE(ctrlreg);
  Wire.endTransmission();
}

User avatar
whmckinley
 
Posts: 15
Joined: Thu Oct 13, 2011 12:43 am

Re: Use RTC DS3231 to wake up an ESP8266

Post by whmckinley »

Further question on this thread.
Is the same process usable for the feather ds3231 with Huzzahesp32. I need to trip an interrupt every hour for a water meter project I am working on.
Brief explanation. .
Counting pulses from water meter ten pulses per gallon.
Quantify water usage per hour
quantify total usage per 24 hr period,
email report of usage.
I am counting the pulses thru an interrupt, doing the math to total gallons. That's the easy part
Populating the strings for the email, connecting to WiFi and triggering the email. All that is working
The issue I am having is whether to use a millis() function or an alarm2 interrupt, preference is for the alarm2 interrupt since it wouldn't
have any conflict with the pulse interrupt. Counting the Alarm2 interrupts to trigger the daily email.
Hardware utilized Huzzahesp32, DS3231 Precision RTC FeatherWing

Locked
Please be positive and constructive with your questions and comments.

Return to “Clock Kits (discontinued)”