Skip to content

Commit 537f3a2

Browse files
committed
RTC Examples
1 parent 03240e2 commit 537f3a2

File tree

6 files changed

+927
-1
lines changed

6 files changed

+927
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vscode/
22
build/
3+
Build/
34
examples/.DS_Store
45
.DS_Store
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
Inkplate_RTC_Alarm_Interrupt_Sleep_Example example for e-radionica Inkplate 6PLUS
3+
For this example you will need only USB cable and Inkplate 6PLUS
4+
Select "Inkplate 6PLUS(ESP32)" from Tools -> Board menu.
5+
Don't have "Inkplate 6PLUS(ESP32)" option? Follow our tutorial and add it:
6+
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
7+
8+
This example will show you how to use RTC alarm interrupt and sleep.
9+
You can use this example to wake up your ESP32 from deep sleep.
10+
Inkplate features RTC chip with interrupt for alarm connected to GPIO39
11+
12+
Want to learn more about Inkplate? Visit www.inkplate.io
13+
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
14+
19 August 2021 by e-radionica.com
15+
*/
16+
17+
#ifndef ARDUINO_INKPLATE6PLUS
18+
#error "Wrong board selection for this example, please select Inkplate 6PLUS in the boards menu."
19+
#endif
20+
21+
#include "Inkplate.h" // Include Inkplate library to the sketch
22+
#include "driver/rtc_io.h" // Include ESP32 library for RTC pin I/O (needed for rtc_gpio_isolate() function)
23+
#include <rom/rtc.h> // Include ESP32 library for RTC (needed for rtc_get_reset_reason() function)
24+
25+
#define uS_TO_S_FACTOR 1000000 // Conversion factor for micro seconds to seconds
26+
#define TIME_TO_SLEEP 10 // Time how long ESP32 will be in deep sleep (in seconds). In this case 10 seconds.
27+
28+
Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1-bit mode (BW)
29+
30+
void setup()
31+
{
32+
Serial.begin(115200);
33+
display.begin();
34+
35+
// setTime(hour, minute, sec);
36+
display.rtcSetTime(6, 54, 00); // 24H mode, ex. 6:54:00
37+
// setDate(weekday, day, month, yr);
38+
display.rtcSetDate(6, 16, 5, 2020); // 0 for Sunday, ex. Saturday, 16.5.2020.
39+
// setAlarm(alarm_second, alarm_minute, alarm_hour, alarm_day, alarm_weekday);
40+
display.rtcSetAlarm(15, 54, 99, 99, 99); // use 99 if no alarm
41+
checkAlarm();
42+
}
43+
44+
void loop()
45+
{
46+
display.setCursor(100, 100);
47+
display.setTextSize(3);
48+
49+
display.println("Now is:");
50+
printCurrentTime();
51+
52+
display.display();
53+
54+
display.println("Entering sleep mode in 1 second");
55+
display.partialUpdate();
56+
57+
delay(1000);
58+
59+
sleepNow(); // sleep function called here
60+
}
61+
62+
void printCurrentTime()
63+
{
64+
display.setCursor(100, display.getCursorY());
65+
display.setTextSize(3);
66+
67+
switch (display.rtcGetWeekday())
68+
{
69+
case 0:
70+
display.print("Sunday , ");
71+
break;
72+
case 1:
73+
display.print("Monday , ");
74+
break;
75+
case 2:
76+
display.print("Tuesday , ");
77+
break;
78+
case 3:
79+
display.print("Wednesday , ");
80+
break;
81+
case 4:
82+
display.print("Thursday , ");
83+
break;
84+
case 5:
85+
display.print("Friday , ");
86+
break;
87+
case 6:
88+
display.print("Saturday , ");
89+
break;
90+
}
91+
92+
display.print(display.rtcGetDay());
93+
display.print(".");
94+
display.print(display.rtcGetMonth());
95+
display.print(".");
96+
display.print(display.rtcGetYear());
97+
display.print(". ");
98+
display.print(display.rtcGetHour());
99+
display.print(":");
100+
display.print(display.rtcGetMinute());
101+
display.print(":");
102+
display.println(display.rtcGetSecond());
103+
}
104+
105+
void checkAlarm()
106+
{
107+
display.setCursor(100, 400);
108+
display.setTextSize(3);
109+
display.print("Alarm is set to match: ");
110+
switch (display.rtcGetAlarmWeekday())
111+
{
112+
case 0:
113+
display.print("Sunday , ");
114+
break;
115+
case 1:
116+
display.print("Monday , ");
117+
break;
118+
case 2:
119+
display.print("Tuesday , ");
120+
break;
121+
case 3:
122+
display.print("Wednesday , ");
123+
break;
124+
case 4:
125+
display.print("Thursday , ");
126+
break;
127+
case 5:
128+
display.print("Friday , ");
129+
break;
130+
case 6:
131+
display.print("Saturday , ");
132+
break;
133+
default:
134+
break; // for getAlarmWeekday=99 alarm is not set for a weekday, do not print
135+
}
136+
137+
if (display.rtcGetAlarmDay() != 99)
138+
{
139+
display.print("Date: ");
140+
display.print(display.rtcGetAlarmDay());
141+
}
142+
if (display.rtcGetAlarmHour() != 99)
143+
{
144+
display.print(" hour: ");
145+
display.print(display.rtcGetAlarmHour());
146+
}
147+
if (display.rtcGetAlarmMinute() != 99)
148+
{
149+
display.print(" minute: ");
150+
display.print(display.rtcGetAlarmMinute());
151+
}
152+
if (display.rtcGetAlarmSecond() != 99)
153+
{
154+
display.print(" second: ");
155+
display.print(display.rtcGetAlarmSecond());
156+
}
157+
158+
display.println("");
159+
}
160+
161+
void sleepNow()
162+
{
163+
// Enable wakup from deep sleep on gpio 39 where RTC interrupt is connected
164+
esp_sleep_enable_ext0_wakeup(GPIO_NUM_39, 0);
165+
166+
// Go to sleep
167+
esp_deep_sleep_start();
168+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Inkplate_RTC_Basic_Example example for e-radionica Inkplate 6PLUS
3+
For this example you will need only USB cable and Inkplate 6PLUS
4+
Select "Inkplate 6PLUS(ESP32)" from Tools -> Board menu.
5+
Don't have "Inkplate 6PLUS(ESP32)" option? Follow our tutorial and add it:
6+
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
7+
8+
This example shows you basic usage of Inkplate RTC.
9+
10+
Want to learn more about Inkplate? Visit www.inkplate.io
11+
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
12+
19 August 2021 by e-radionica.com
13+
*/
14+
15+
#ifndef ARDUINO_INKPLATE6PLUS
16+
#error "Wrong board selection for this example, please select Inkplate 6PLUS in the boards menu."
17+
#endif
18+
19+
#include "Inkplate.h" // Include Inkplate library to the sketch
20+
#include "driver/rtc_io.h" // Include ESP32 library for RTC pin I/O (needed for rtc_gpio_isolate() function)
21+
#include <rom/rtc.h> // Include ESP32 library for RTC (needed for rtc_get_reset_reason() function)
22+
23+
#define uS_TO_S_FACTOR 1000000 // Conversion factor for micro seconds to seconds
24+
#define TIME_TO_SLEEP 10 // Time how long ESP32 will be in deep sleep (in seconds). In this case 10 seconds.
25+
26+
Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1-bit mode (BW)
27+
28+
29+
void setup()
30+
{
31+
Serial.begin(115200);
32+
display.begin();
33+
34+
35+
display.rtcSetTime(6, 54, 00); // 24H mode, ex. 6:54:00
36+
display.rtcSetDate(6, 16, 5, 2020); // 0 for Sunday, ex. Saturday, 16.5.2020.
37+
}
38+
39+
void loop()
40+
{
41+
printCurrentTime();
42+
delay(5000);
43+
}
44+
45+
void printCurrentTime()
46+
{
47+
display.clearDisplay();
48+
display.setCursor(100, 100);
49+
display.setTextSize(4);
50+
51+
switch (display.rtcGetWeekday())
52+
{
53+
case 0:
54+
display.print("Sunday , ");
55+
break;
56+
case 1:
57+
display.print("Monday , ");
58+
break;
59+
case 2:
60+
display.print("Tuesday , ");
61+
break;
62+
case 3:
63+
display.print("Wednesday , ");
64+
break;
65+
case 4:
66+
display.print("Thursday , ");
67+
break;
68+
case 5:
69+
display.print("Friday , ");
70+
break;
71+
case 6:
72+
display.print("Saturday , ");
73+
break;
74+
}
75+
76+
display.print(display.rtcGetDay());
77+
display.print(".");
78+
display.print(display.rtcGetMonth());
79+
display.print(".");
80+
display.print(display.rtcGetYear());
81+
display.print(". ");
82+
display.print(display.rtcGetHour());
83+
display.print(":");
84+
display.print(display.rtcGetMinute());
85+
display.print(":");
86+
display.println(display.rtcGetSecond());
87+
88+
display.display();
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
Inkplate_RTC_Timer_Example example for e-radionica Inkplate 6PLUS
3+
For this example you will need only USB cable and Inkplate 6PLUS
4+
Select "Inkplate 6PLUS(ESP32)" from Tools -> Board menu.
5+
Don't have "Inkplate 6PLUS(ESP32)" option? Follow our tutorial and add it:
6+
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
7+
8+
This example shows you timer usage of Inkplate RTC.
9+
10+
Want to learn more about Inkplate? Visit www.inkplate.io
11+
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
12+
19 August 2021 by e-radionica.com
13+
*/
14+
15+
#ifndef ARDUINO_INKPLATE6PLUS
16+
#error "Wrong board selection for this example, please select Inkplate 6PLUS in the boards menu."
17+
#endif
18+
19+
#include "Inkplate.h" // Include Inkplate library to the sketch
20+
#include "driver/rtc_io.h" // Include ESP32 library for RTC pin I/O (needed for rtc_gpio_isolate() function)
21+
#include <rom/rtc.h> // Include ESP32 library for RTC (needed for rtc_get_reset_reason() function)
22+
23+
#define uS_TO_S_FACTOR 1000000 // Conversion factor for micro seconds to seconds
24+
#define TIME_TO_SLEEP 10 // Time how long ESP32 will be in deep sleep (in seconds). In this case 10 seconds.
25+
26+
Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1-bit mode (BW)
27+
28+
int countdown_time = 10;
29+
30+
void setup()
31+
{
32+
Serial.begin(115200);
33+
display.begin();
34+
35+
display.rtcSetTime(6, 54, 00); // 24H mode, ex. 6:54:00
36+
display.rtcSetDate(6, 16, 5, 2020); // 0 for Sunday, ex. Saturday, 16.5.2020.
37+
38+
display.setCursor(0, 100);
39+
display.setTextSize(3);
40+
display.print("Now is:");
41+
}
42+
43+
void loop()
44+
{
45+
printCurrentTime();
46+
display.print("Setting timer countdown, waking up in ");
47+
display.print(countdown_time);
48+
display.println(" seconds.");
49+
// while(!display.available());
50+
51+
/* source_clock
52+
* Inkplate::TIMER_CLOCK_4096HZ -> clk = 4096Hz -> min timer = 244uS -> MAX timer = 62.256mS
53+
* Inkplate::TIMER_CLOCK_64HZ -> clk = 64Hz -> min timer = 15.625mS -> MAX timer = 3.984s
54+
* Inkplate::TIMER_CLOCK_1HZ -> clk = 1Hz -> min timer = 1s -> MAX timer = 255s
55+
* Inkplate::TIMER_CLOCK_1PER60HZ -> clk = 1/60Hz -> min timer = 60s -> MAX timer = 4h15min
56+
* value
57+
* coundowntime in seconds
58+
* int_enable
59+
* true = enable interrupt; false = disable interrupt
60+
* int_pulse
61+
* true = interrupt generate a pulse; false = interrupt follows timer flag
62+
*/
63+
display.rtcTimerSet(Inkplate::TIMER_CLOCK_1HZ, countdown_time, false, false);
64+
65+
display.print("Waiting for a countdown");
66+
while (!display.rtcCheckTimerFlag())
67+
{
68+
display.print(".");
69+
delay(1000);
70+
}
71+
72+
display.print("\nInterrupt triggered on: ");
73+
}
74+
75+
void printCurrentTime()
76+
{
77+
switch (display.rtcGetWeekday())
78+
{
79+
case 0:
80+
display.print("Sunday , ");
81+
break;
82+
case 1:
83+
display.print("Monday , ");
84+
break;
85+
case 2:
86+
display.print("Tuesday , ");
87+
break;
88+
case 3:
89+
display.print("Wednesday , ");
90+
break;
91+
case 4:
92+
display.print("Thursday , ");
93+
break;
94+
case 5:
95+
display.print("Friday , ");
96+
break;
97+
case 6:
98+
display.print("Saturday , ");
99+
break;
100+
}
101+
102+
display.print(display.rtcGetDay());
103+
display.print(".");
104+
display.print(display.rtcGetMonth());
105+
display.print(".");
106+
display.print(display.rtcGetYear());
107+
display.print(". ");
108+
display.print(display.rtcGetHour());
109+
display.print(":");
110+
display.print(display.rtcGetMinute());
111+
display.print(":");
112+
display.println(display.rtcGetSecond());
113+
114+
display.display();
115+
}

0 commit comments

Comments
 (0)