Skip to content

Commit a347202

Browse files
committed
Added RTC Examples for IP6COLOR
1 parent f1e21ca commit a347202

File tree

5 files changed

+548
-0
lines changed

5 files changed

+548
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
Inkplate_RTC_Alarm_Deep_Sleep_Example example for e-radionica Inkplate 6COLOR
3+
For this example you will need only USB cable and Inkplate 6COLOR
4+
Select "Inkplate 6COLOR(ESP32)" from Tools -> Board menu.
5+
Don't have "Inkplate 6COLOR(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+
19 May 2022 by Soldered.com
15+
*/
16+
17+
#ifndef ARDUINO_INKPLATECOLOR
18+
#error "Wrong board selection for this example, please select Inkplate 6COLOR 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; // Create an object on Inkplate library
26+
27+
void setup()
28+
{
29+
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
30+
31+
display.rtcReset(); // Reset RTC if there is some data in it
32+
33+
display.rtcClearAlarmFlag(); // Clear alarm flag from any previous alarm
34+
35+
if (!display.rtcIsSet()) // Check if RTC is already is set. If ts not, set time and date
36+
{
37+
// setTime(hour, minute, sec);
38+
display.rtcSetTime(6, 54, 00); // 24H mode, ex. 6:54:00
39+
// setDate(weekday, day, month, yr);
40+
display.rtcSetDate(5, 19, 5, 2022); // 0 for Sunday, ex. Saturday, 16.5.2020.
41+
42+
// display.rtcSetEpoch(1589610300); // Or use epoch for setting the time and date
43+
}
44+
45+
printCurrentTime(); // Display current time and date
46+
display.display();
47+
48+
display.rtcSetAlarmEpoch(display.rtcGetEpoch() + 60, RTC_ALARM_MATCH_DHHMMSS); // Set RTC alarm 60 seconds from now
49+
50+
// Enable wakup from deep sleep on gpio 39 where RTC interrupt is connected
51+
esp_sleep_enable_ext0_wakeup(GPIO_NUM_39, 0);
52+
53+
// Go to sleep
54+
esp_deep_sleep_start();
55+
}
56+
57+
void loop()
58+
{
59+
// Nothing...
60+
}
61+
62+
void printCurrentTime()
63+
{
64+
display.setCursor(100, 300);
65+
display.setTextSize(3);
66+
display.setTextColor(INKPLATE_BLUE, INKPLATE_WHITE); //Set text color and background
67+
68+
switch (display.rtcGetWeekday())
69+
{
70+
case 0:
71+
display.print("Sunday , ");
72+
break;
73+
case 1:
74+
display.print("Monday , ");
75+
break;
76+
case 2:
77+
display.print("Tuesday , ");
78+
break;
79+
case 3:
80+
display.print("Wednesday , ");
81+
break;
82+
case 4:
83+
display.print("Thursday , ");
84+
break;
85+
case 5:
86+
display.print("Friday , ");
87+
break;
88+
case 6:
89+
display.print("Saturday , ");
90+
break;
91+
}
92+
93+
display.print(display.rtcGetDay());
94+
display.print(".");
95+
display.print(display.rtcGetMonth());
96+
display.print(".");
97+
display.print(display.rtcGetYear());
98+
display.print(". ");
99+
print2Digits(display.rtcGetHour());
100+
display.print(':');
101+
print2Digits(display.rtcGetMinute());
102+
display.print(':');
103+
print2Digits(display.rtcGetSecond());
104+
}
105+
106+
void print2Digits(uint8_t _d)
107+
{
108+
if (_d < 10)
109+
display.print('0');
110+
display.print(_d, DEC);
111+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
Inkplate_RTC_Alarm_Example example for e-radionica Inkplate 6COLOR
3+
For this example you will need USB cable and Inkplate 6COLOR.
4+
Select "Inkplate 6COLOR(ESP32)" from Tools -> Board menu.
5+
Don't have "Inkplate 6COLOR(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.
10+
11+
Want to learn more about Inkplate? Visit www.inkplate.io
12+
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
13+
19 May 2022 by Soldered.com
14+
*/
15+
16+
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
17+
#ifndef ARDUINO_INKPLATECOLOR
18+
#error "Wrong board selection for this example, please select Inkplate 6COLOR in the boards menu."
19+
#endif
20+
21+
#include "Inkplate.h" // Include Inkplate library to the sketch
22+
Inkplate display; // Create an object on Inkplate library
23+
24+
// Set clock
25+
uint8_t hour = 12;
26+
uint8_t minutes = 51;
27+
uint8_t seconds = 0;
28+
29+
// Set date and weekday (NOTE: In weekdays 0 means Sunday, 1 menas Monday, ...)
30+
uint8_t weekday = 5;
31+
uint8_t day = 19;
32+
uint8_t month = 5;
33+
uint8_t year = 22;
34+
35+
// Set alarm time and date (alarm will be generated 60 seconds after board power up)
36+
uint8_t alarmHour = 12;
37+
uint8_t alarmMinutes = 52;
38+
uint8_t alarmSeconds = 0;
39+
uint8_t alarmWeekday = 5;
40+
uint8_t alarmDay = 19;
41+
42+
void setup()
43+
{
44+
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
45+
display.rtcReset(); // Reset RTC if there is some data in it
46+
display.clearDisplay(); // Clear frame buffer of display
47+
display.display(); // Put clear image on display
48+
display.setTextSize(3); // Set text to be 4 times bigger than classic 5x7 px text
49+
50+
pinMode(39, INPUT_PULLUP);
51+
52+
display.rtcSetTime(hour, minutes, seconds); // Send time to RTC
53+
display.rtcSetDate(weekday, day, month, year); // Send date to RTC
54+
display.rtcSetAlarm(alarmSeconds, alarmMinutes, alarmHour, alarmDay, alarmWeekday); // Set alarm
55+
}
56+
57+
void loop()
58+
{
59+
display.rtcGetRtcData(); // Get the time and date from RTC
60+
seconds = display.rtcGetSecond(); // Store senconds in a variable
61+
minutes = display.rtcGetMinute(); // Store minutes in a variable
62+
hour = display.rtcGetHour(); // Store hours in a variable
63+
day = display.rtcGetDay(); // Store day of month in a variable
64+
weekday = display.rtcGetWeekday(); // Store day of week in a variable
65+
month = display.rtcGetMonth(); // Store month in a variable
66+
year = display.rtcGetYear(); // Store year in a variable
67+
68+
display.clearDisplay(); // Clear content in frame buffer
69+
display.setCursor(100, 300); // Set position of the text
70+
display.setTextColor(INKPLATE_GREEN, INKPLATE_WHITE); //Set text color and background
71+
printTime(hour, minutes, seconds, day, weekday, month, year); // Print the time on screen
72+
73+
if (display.rtcCheckAlarmFlag()) // Check if alarm has occurred
74+
{
75+
display.rtcClearAlarmFlag(); // It's recommended to clear alarm flag after alarm has occurred
76+
display.setCursor(400, 400); // Set new position for cursor
77+
display.print("ALARM!");
78+
}
79+
80+
display.display(true); // Do a full refresh
81+
82+
83+
delay(60000); // Delay between refreshes one minute
84+
}
85+
86+
void printTime(uint8_t _hour, uint8_t _minutes, uint8_t _seconds, uint8_t _day, uint8_t _weekday, uint16_t _month,
87+
uint8_t _year)
88+
{
89+
// Write time and date info on screen
90+
char *wday[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
91+
92+
print2Digits(_hour);
93+
display.print(':');
94+
print2Digits(_minutes);
95+
display.print(':');
96+
print2Digits(_seconds);
97+
98+
display.print(' ');
99+
100+
display.print(wday[_weekday]);
101+
display.print(", ");
102+
print2Digits(_day);
103+
display.print('/');
104+
print2Digits(_month);
105+
display.print('/');
106+
display.print(_year, DEC);
107+
}
108+
109+
void print2Digits(uint8_t _d)
110+
{
111+
if (_d < 10)
112+
display.print('0');
113+
display.print(_d, DEC);
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Inkplate_RTC_Basic_Example example for e-radionica Inkplate 6COLOR
3+
For this example you will need USB cable and Inkplate 6COLOR.
4+
Select "Inkplate 6COLOR(ESP32)" from Tools -> Board menu.
5+
Don't have "Inkplate 6COLOR(ESP32)" option? Follow our tutorial and add it:
6+
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
7+
8+
Example 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.
10+
11+
Want to learn more about Inkplate? Visit www.inkplate.io
12+
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
13+
19 May 2022 by Soldered.com
14+
*/
15+
16+
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
17+
#ifndef ARDUINO_INKPLATECOLOR
18+
#error "Wrong board selection for this example, please select Inkplate 6COLOR in the boards menu."
19+
#endif
20+
21+
#include "Inkplate.h" // Include Inkplate library to the sketch
22+
Inkplate display; // Create an object on Inkplate library
23+
24+
// Set clock
25+
uint8_t hour = 12;
26+
uint8_t minutes = 50;
27+
uint8_t seconds = 0;
28+
29+
// Set date and weekday (NOTE: In weekdays 0 means Sunday, 1 menas Monday, ...)
30+
uint8_t weekday = 5;
31+
uint8_t day = 19;
32+
uint8_t month = 5;
33+
uint8_t year = 22;
34+
35+
void setup()
36+
{
37+
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
38+
display.rtcReset(); // Reset RTC if there is some data in it
39+
display.clearDisplay(); // Clear frame buffer of display
40+
display.display(); // Put clear image on display
41+
display.setTextSize(3); // Set text to be 4 times bigger than classic 5x7 px text
42+
display.setTextColor(INKPLATE_BLACK, INKPLATE_WHITE); //Set text color and background
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+
void loop()
49+
{
50+
display.rtcGetRtcData(); // Get the time and date from RTC
51+
seconds = display.rtcGetSecond(); // Store senconds in a variable
52+
minutes = display.rtcGetMinute(); // Store minutes in a variable
53+
hour = display.rtcGetHour(); // Store hours in a variable
54+
day = display.rtcGetDay(); // Store day of month in a variable
55+
weekday = display.rtcGetWeekday(); // Store day of week in a variable
56+
month = display.rtcGetMonth(); // Store month in a variable
57+
year = display.rtcGetYear(); // Store year in a variable
58+
59+
display.clearDisplay(); // Clear content in frame buffer
60+
display.setCursor(80, 300); // Set position of the text
61+
printTime(hour, minutes, seconds, day, weekday, month, year); // Print the time on screen
62+
63+
display.display(); // Do a full refresh
64+
65+
delay(60000); // Delay between refreshes one minute
66+
}
67+
68+
void printTime(uint8_t _hour, uint8_t _minutes, uint8_t _seconds, uint8_t _day, uint8_t _weekday, uint8_t _month,
69+
uint16_t _year)
70+
{
71+
// Write time and date info on screen
72+
char *wday[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
73+
74+
print2Digits(_hour);
75+
display.print(':');
76+
print2Digits(_minutes);
77+
display.print(':');
78+
print2Digits(_seconds);
79+
80+
display.print(' ');
81+
82+
display.print(wday[_weekday]);
83+
display.print(", ");
84+
print2Digits(_day);
85+
display.print('/');
86+
print2Digits(_month);
87+
display.print('/');
88+
display.print(_year, DEC);
89+
}
90+
91+
void print2Digits(uint8_t _d)
92+
{
93+
if (_d < 10)
94+
display.print('0');
95+
display.print(_d, DEC);
96+
}

0 commit comments

Comments
 (0)