RTC alarm with deep sleep
What this example shows
Wake Inkplate from deep sleep with the RTC alarm. On each start the sketch shows the current time and date, sets the alarm 60 seconds ahead and goes back to deep sleep, so the board wakes about once a minute, refreshes the screen and sleeps again. If the RTC has not been set yet, the sketch first sets it to 13:30:00 on 20 July 2026.
This example also uses esp_sleep_enable_ext0_wakeup() and esp_deep_sleep_start(), which come with the ESP32 board package and are not part of the Inkplate library.
Example code
#include "Inkplate.h" //Include inkplate library to the sketch
#include "driver/rtc_io.h" //Include ESP32 library for RTC pin I/O (needed for rtc_gpio_isolate() function)
#include <rom/rtc.h> //Include ESP32 library for RTF (needed for rtc_get_reset_reason() function)
Inkplate inkplate; //Create an object on Inkplate library
void setup() {
inkplate.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
inkplate.rtc.clearAlarmFlag(); // Clear alarm flag from any previous alarm
if(!inkplate.rtc.isSet()) // Check if RTC is already is set. If ts not, set time and date
{
// display.setTime(hour, minute, sec);
inkplate.rtc.setTime(13,30,00); // 24H mode, ex. 13:30:00
// display.setDate(weekday, day, month, yr);
inkplate.rtc.setDate(1,20,7,2026); // 0 for Monday, ex. Saturday, 5.12.2022.
// display.rtc.setEpoch(1589610300); // Or use epoch for setting the time and date
}
printCurrentTime(); // Display current time and date
inkplate.display();
inkplate.rtc.setAlarmEpoch(inkplate.rtc.getEpoch() + 60, RTC_ALARM_MATCH_DHHMMSS); // Set RTC alarm 60 seconds from now
// Enable wakup from deep sleep on gpio 2 where RTC interrupt is connected
esp_sleep_enable_ext0_wakeup(GPIO_NUM_2, 0);
// Start deep sleep (this function does not return). Program stops here.
esp_deep_sleep_start();
}
void loop() {
// put your main code here, to run repeatedly:
}
void printCurrentTime(){
inkplate.setCursor(50,250);
inkplate.setTextSize(2);
inkplate.setTextColor(INKPLATE_BLUE, INKPLATE_WHITE); // Set text color and background
inkplate.rtc.getRtcData();
switch (inkplate.rtc.getWeekday())
{
case 0:
inkplate.print("Sunday , ");
break;
case 1:
inkplate.print("Monday , ");
break;
case 2:
inkplate.print("Tuesday , ");
break;
case 3:
inkplate.print("Wednesday , ");
break;
case 4:
inkplate.print("Thursday , ");
break;
case 5:
inkplate.print("Friday , ");
break;
case 6:
inkplate.print("Saturday , ");
break;
}
inkplate.print(inkplate.rtc.getDay());
inkplate.print(".");
inkplate.print(inkplate.rtc.getMonth());
inkplate.print(".");
inkplate.print(inkplate.rtc.getYear());
inkplate.print(". ");
print2Digits(inkplate.rtc.getHour());
inkplate.print(':');
print2Digits(inkplate.rtc.getMinute());
inkplate.print(':');
print2Digits(inkplate.rtc.getSecond());
}
void print2Digits(uint8_t _d)
{
if (_d < 10)
inkplate.print('0');
inkplate.print(_d, DEC);
}
The comment next to setDate() says 0 is Monday, but the weekday names the sketch prints use 0 for Sunday, so the weekday 1 in the call shows as Monday.
Functions used
Inkplate()returns NoneCreates the Inkplate object. Inkplate 7SPECTRA has a single six-color mode, so the constructor takes no mode argument.
ReturnsConstructor; no return value.
inkplate.begin()returns voidInitializes the library, the peripherals and the frame buffer. Call it once in setup().
ReturnsNothing.
inkplate.rtc.clearAlarmFlag()returns voidClears the alarm flag left from an earlier alarm.
ReturnsNothing.
inkplate.rtc.isSet()returns boolReports whether the RTC's time and date have already been set. The sketch sets them only when it returns false, so the time survives deep sleep.
Returnstrue if the RTC is set.
inkplate.rtc.setTime(uint8_t hour, uint8_t minute, uint8_t sec, bool isPM = false)returns voidWrites the time to the RTC. isPM is only used in 12-hour mode.
ReturnsNothing.
inkplate.rtc.setDate(uint8_t weekday, uint8_t day, uint8_t month, uint16_t yr)returns voidWrites the date to the RTC. yr is the full year, here 2026.
ReturnsNothing.
inkplate.rtc.getEpoch()returns uint32_tReturns the RTC time as an epoch value.
ReturnsEpoch time.
inkplate.rtc.setAlarmEpoch(uint32_t _epoch, uint8_t _match)returns voidSets the alarm to the time in _epoch. _match says which parts of the time must match: the sketch passes RTC_ALARM_MATCH_DHHMMSS (day, hours, minutes and seconds). The other values are RTC_ALARM_MATCH_SS, RTC_ALARM_MATCH_MMSS, RTC_ALARM_MATCH_HHMMSS and RTC_ALARM_MATCH_WHHMMSS.
ReturnsNothing.
esp_sleep_enable_ext0_wakeup(GPIO_NUM_2, 0)returns esp_err_tESP32 board package function: wakes the board from deep sleep when the given pin reaches the given level. The sketch uses GPIO 2, which its comment says is where the RTC interrupt is connected, and level 0.
ReturnsESP_OK on success.
esp_deep_sleep_start()returns voidESP32 board package function: starts deep sleep. It does not return; the board restarts from setup() when it wakes.
ReturnsDoes not return.
inkplate.display(bool _leaveOn = 0)returns voidSends the whole frame buffer to the panel and refreshes it.
ReturnsNothing.
inkplate.setCursor(int16_t x, int16_t y)returns voidSets where the next printed text starts.
ReturnsNothing.
inkplate.setTextSize(uint8_t s)returns voidSets the text magnification, here 2.
ReturnsNothing.
inkplate.setTextColor(uint16_t c, uint16_t bg)returns voidSets the text color and the background color drawn behind each character, here blue on white.
ReturnsNothing.
inkplate.rtc.getRtcData()returns voidReads the time and date from the RTC; the get functions below return the values it read.
ReturnsNothing.
inkplate.rtc.getWeekday()returns uint8_tReturns the day of the week, 0 (Sunday) to 6.
ReturnsDay of the week.
inkplate.rtc.getDay()returns uint8_tReturns the day of the month.
ReturnsDay of the month.
inkplate.rtc.getMonth()returns uint8_tReturns the month.
ReturnsMonth, 1 to 12.
inkplate.rtc.getYear()returns uint16_tReturns the year: the value stored in the RTC plus 2000.
ReturnsFull year.
inkplate.rtc.getHour()returns uint8_tReturns the hours.
ReturnsHours.
inkplate.rtc.getMinute()returns uint8_tReturns the minutes.
ReturnsMinutes.
inkplate.rtc.getSecond()returns uint8_tReturns the seconds.
ReturnsSeconds.
inkplate.print(value, format)returns size_tPrints text, a character or a number into the frame buffer, like Serial.print(). DEC prints a number in decimal.
ReturnsNumber of bytes printed.
What to expect
On the first start the screen shows the time and date in blue, in the form Monday , 20.7.2026. 13:30:00. The board then sleeps; about a minute later the alarm wakes it, and the screen refreshes with the new time, such as Monday , 20.7.2026. 13:31:00. This repeats until you power the board off. The sketch prints nothing to the Serial Monitor.
🔗Open the complete example
examples/Inkplate7SPECTRA/Advanced/DeepSleep/Inkplate7SPECTRA_RTC_Alarm_With_Deep_Sleep