Skip to content

Commit 4606206

Browse files
authored
Merge pull request #113 from e-radionicacom/dev
Enabled external RTC for all Inkplate boards, added more RTC functions, added new RTC examples all boards (except in Inkplate Color)
2 parents f5170c2 + 64012ad commit 4606206

File tree

23 files changed

+2482
-311
lines changed

23 files changed

+2482
-311
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
Inkplate_RTC_Alarm_Deep_Sleep_Example example for e-radionica Inkplate 10
3+
For this example you will need only USB cable and Inkplate 10
4+
Select "Inkplate 10(ESP32)" from Tools -> Board menu.
5+
Don't have "Inkplate 10(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 with deep sleep.
9+
Inkplate features RTC chip with interrupt for alarm connected to GPIO39
10+
Inkplate board will wake up every 10 seconds, refresh screen and go back to sleep.
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+
15 November 2021 by e-radionica.com
15+
*/
16+
17+
#ifndef ARDUINO_INKPLATE10
18+
#error "Wrong board selection for this example, please select Inkplate 10 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+
Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1-bit mode (BW)
26+
27+
void setup()
28+
{
29+
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
30+
31+
display.rtcClearAlarmFlag(); // Clear alarm flag from any previous alarm
32+
33+
if (!display.rtcIsSet()) // Check if RTC is already is set. If ts not, set time and date
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+
40+
// display.rtcSetEpoch(1589610300); // Or use epoch for setting the time and date
41+
}
42+
43+
printCurrentTime(); // Display current time and date
44+
display.display();
45+
46+
display.rtcSetAlarmEpoch(display.rtcGetEpoch() + 10, RTC_ALARM_MATCH_DHHMMSS); // Set RTC alarm 10 seconds from now
47+
48+
// Enable wakup from deep sleep on gpio 39 where RTC interrupt is connected
49+
esp_sleep_enable_ext0_wakeup(GPIO_NUM_39, 0);
50+
51+
// Go to sleep
52+
esp_deep_sleep_start();
53+
}
54+
55+
void loop()
56+
{
57+
// Nothing...
58+
}
59+
60+
void printCurrentTime()
61+
{
62+
display.setCursor(100, 300);
63+
display.setTextSize(3);
64+
65+
switch (display.rtcGetWeekday())
66+
{
67+
case 0:
68+
display.print("Sunday , ");
69+
break;
70+
case 1:
71+
display.print("Monday , ");
72+
break;
73+
case 2:
74+
display.print("Tuesday , ");
75+
break;
76+
case 3:
77+
display.print("Wednesday , ");
78+
break;
79+
case 4:
80+
display.print("Thursday , ");
81+
break;
82+
case 5:
83+
display.print("Friday , ");
84+
break;
85+
case 6:
86+
display.print("Saturday , ");
87+
break;
88+
}
89+
90+
display.print(display.rtcGetDay());
91+
display.print(".");
92+
display.print(display.rtcGetMonth());
93+
display.print(".");
94+
display.print(display.rtcGetYear());
95+
display.print(". ");
96+
print2Digits(display.rtcGetHour());
97+
display.print(':');
98+
print2Digits(display.rtcGetMinute());
99+
display.print(':');
100+
print2Digits(display.rtcGetSecond());
101+
}
102+
103+
void print2Digits(uint8_t _d)
104+
{
105+
if (_d < 10)
106+
display.print('0');
107+
display.print(_d, DEC);
108+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
Inkplate_RTC_Alarm_Example example for e-radionica Inkplate 10
3+
For this example you will need USB cable and Inkplate 10.
4+
Select "Inkplate 10(ESP32)" from Tools -> Board menu.
5+
Don't have "Inkplate 10(ESP32)" option? Follow our tutorial and add it:
6+
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
7+
8+
In this example we will show how to use basic alarm and clock functions of PCF85063 RTC on Inkplate board.
9+
This example will show how to set time and date, how to set alarm, how to read time and how to print time on Inkplate using partial updates.
10+
NOTE: Partial update is only available on 1 Bit mode (BW) and it is not recommended to use it on first refresh after
11+
power up. It is recommended to do a full refresh every 5-10 partial refresh to maintain good picture quality.
12+
13+
Want to learn more about Inkplate? Visit www.inkplate.io
14+
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
15+
12 November 2021 by e-radionica.com
16+
*/
17+
18+
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
19+
#ifndef ARDUINO_INKPLATE10
20+
#error "Wrong board selection for this example, please select Inkplate 10 in the boards menu."
21+
#endif
22+
23+
#include "Inkplate.h" // Include Inkplate library to the sketch
24+
Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1-bit mode (BW)
25+
26+
// Set clock
27+
uint8_t hour = 12;
28+
uint8_t minutes = 50;
29+
uint8_t seconds = 30;
30+
31+
// Set date and weekday (NOTE: In weekdays 0 means Sunday, 1 menas Monday, ...)
32+
uint8_t weekday = 4;
33+
uint8_t day = 11;
34+
uint8_t month = 11;
35+
uint8_t year = 21;
36+
37+
// Set alarm time and date (alarm will be generated 10 seconds after board power up)
38+
uint8_t alarmHour = 12;
39+
uint8_t alarmMinutes = 50;
40+
uint8_t alarmSeconds = 40;
41+
uint8_t alarmWeekday = 4;
42+
uint8_t alarmDay = 11;
43+
44+
void setup()
45+
{
46+
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
47+
display.clearDisplay(); // Clear frame buffer of display
48+
display.display(); // Put clear image on display
49+
display.setTextSize(5); // Set text to be 5 times bigger than classic 5x7 px text
50+
51+
pinMode(39, INPUT_PULLUP);
52+
53+
display.rtcSetTime(hour, minutes, seconds); // Send time to RTC
54+
display.rtcSetDate(weekday, day, month, year); // Send date to RTC
55+
display.rtcSetAlarm(alarmSeconds, alarmMinutes, alarmHour, alarmDay, alarmWeekday); // Set alarm
56+
}
57+
58+
// Variable that keeps count on how much screen has been partially updated
59+
int n = 0;
60+
void loop()
61+
{
62+
display.rtcReadTime(); // Get the time and date from RTC
63+
seconds = display.rtcGetSecond(); // Store senconds in a variable
64+
minutes = display.rtcGetMinute(); // Store minutes in a variable
65+
hour = display.rtcGetHour(); // Store hours in a variable
66+
day = display.rtcGetDay(); // Store day of month in a variable
67+
weekday = display.rtcGetWeekday(); // Store day of week in a variable
68+
month = display.rtcGetMonth(); // Store month in a variable
69+
year = display.rtcGetYear(); // Store year in a variable
70+
71+
display.clearDisplay(); // Clear content in frame buffer
72+
display.setCursor(100, 300); // Set position of the text
73+
printTime(hour, minutes, seconds, day, weekday, month, year); // Print the time on screen
74+
75+
if (display.rtcCheckAlarmFlag()) // Check if alarm has occurred
76+
{
77+
display.rtcClearAlarmFlag(); // It's recommended to clear alarm flag after alarm has occurred
78+
display.setCursor(400, 400); // Set new position for cursor
79+
display.print("ALARM!");
80+
}
81+
82+
if (n > 9) // Check if you need to do full refresh or you can do partial update
83+
{
84+
display.display(true); // Do a full refresh
85+
n = 0;
86+
}
87+
else
88+
{
89+
display.partialUpdate(false, true); // Do partial update and keep e-papr power supply on
90+
n++; // Keep track on how many times screen has been partially updated
91+
}
92+
93+
delay(700); // Delay between refreshes.
94+
}
95+
96+
void printTime(uint8_t _hour, uint8_t _minutes, uint8_t _seconds, uint8_t _day, uint8_t _weekday, uint16_t _month,
97+
uint8_t _year)
98+
{
99+
// Write time and date info on screen
100+
char *wday[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
101+
102+
print2Digits(_hour);
103+
display.print(':');
104+
print2Digits(_minutes);
105+
display.print(':');
106+
print2Digits(_seconds);
107+
108+
display.print(' ');
109+
110+
display.print(wday[_weekday]);
111+
display.print(", ");
112+
print2Digits(_day);
113+
display.print('/');
114+
print2Digits(_month);
115+
display.print('/');
116+
display.print(_year, DEC);
117+
}
118+
119+
void print2Digits(uint8_t _d)
120+
{
121+
if (_d < 10)
122+
display.print('0');
123+
display.print(_d, DEC);
124+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
Inkplate_RTC_Basic_Example example for e-radionica Inkplate 10
3+
For this example you will need USB cable and Inkplate 10.
4+
Select "Inkplate 10(ESP32)" from Tools -> Board menu.
5+
Don't have "Inkplate 10(ESP32)" option? Follow our tutorial and add it:
6+
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
7+
8+
Example will shows how to use basic clock functions of PCF85063A RTC on Inkplate board.
9+
This example will show how to set time and date, how to read time and how to print time on Inkplate using partial updates.
10+
NOTE: Partial update is only available on 1 Bit mode (BW) and it is not recommended to use it on first refresh after
11+
power up. It is recommended to do a full refresh every 5-10 partial refresh to maintain good picture quality.
12+
13+
Want to learn more about Inkplate? Visit www.inkplate.io
14+
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
15+
12 November 2021 by e-radionica.com
16+
*/
17+
18+
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
19+
#ifndef ARDUINO_INKPLATE10
20+
#error "Wrong board selection for this example, please select Inkplate 10 in the boards menu."
21+
#endif
22+
23+
#include "Inkplate.h" // Include Inkplate library to the sketch
24+
Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1-bit mode (BW)
25+
26+
// Set clock
27+
uint8_t hour = 12;
28+
uint8_t minutes = 50;
29+
uint8_t seconds = 30;
30+
31+
// Set date and weekday (NOTE: In weekdays 0 means Sunday, 1 menas Monday, ...)
32+
uint8_t weekday = 4;
33+
uint8_t day = 11;
34+
uint8_t month = 11;
35+
uint8_t year = 21;
36+
37+
void setup()
38+
{
39+
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
40+
display.clearDisplay(); // Clear frame buffer of display
41+
display.display(); // Put clear image on display
42+
display.setTextSize(5); // Set text to be 5 times bigger than classic 5x7 px text
43+
44+
display.rtcSetTime(hour, minutes, seconds); // Send time to RTC
45+
display.rtcSetDate(weekday, day, month, year); // Send date to RTC
46+
}
47+
48+
// Variable that keeps count on how much screen has been partially updated
49+
int n = 0;
50+
void loop()
51+
{
52+
display.rtcReadTime(); // Get the time and date from RTC
53+
seconds = display.rtcGetSecond(); // Store senconds in a variable
54+
minutes = display.rtcGetMinute(); // Store minutes in a variable
55+
hour = display.rtcGetHour(); // Store hours in a variable
56+
day = display.rtcGetDay(); // Store day of month in a variable
57+
weekday = display.rtcGetWeekday(); // Store day of week in a variable
58+
month = display.rtcGetMonth(); // Store month in a variable
59+
year = display.rtcGetYear(); // Store year in a variable
60+
61+
display.clearDisplay(); // Clear content in frame buffer
62+
display.setCursor(100, 300); // Set position of the text
63+
printTime(hour, minutes, seconds, day, weekday, month, year); // Print the time on screen
64+
65+
if (n > 9) // Check if you need to do full refresh or you can do partial update
66+
{
67+
display.display(true); // Do a full refresh
68+
n = 0;
69+
}
70+
else
71+
{
72+
display.partialUpdate(false, true); // Do partial update and keep e-papr power supply on
73+
n++; // Keep track on how many times screen has been partially updated
74+
}
75+
76+
delay(700); // Delay between refreshes.
77+
}
78+
79+
void printTime(uint8_t _hour, uint8_t _minutes, uint8_t _seconds, uint8_t _day, uint8_t _weekday, uint8_t _month,
80+
uint16_t _year)
81+
{
82+
// Write time and date info on screen
83+
char *wday[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
84+
85+
print2Digits(_hour);
86+
display.print(':');
87+
print2Digits(_minutes);
88+
display.print(':');
89+
print2Digits(_seconds);
90+
91+
display.print(' ');
92+
93+
display.print(wday[_weekday]);
94+
display.print(", ");
95+
print2Digits(_day);
96+
display.print('/');
97+
print2Digits(_month);
98+
display.print('/');
99+
display.print(_year, DEC);
100+
}
101+
102+
void print2Digits(uint8_t _d)
103+
{
104+
if (_d < 10)
105+
display.print('0');
106+
display.print(_d, DEC);
107+
}

0 commit comments

Comments
 (0)