Skip to content

Commit 88ce396

Browse files
committed
Added Inkplate6COLOR wake-up on touchpad example and some keywords
1 parent 255d391 commit 88ce396

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
Inkplate6COLOR_Wake_Up_On_Touchpads example for Soldered Inkplate 6 COLOR
3+
For this example you will need USB cable and an Inkplate 6 COLOR
4+
Select "Soldered Inkplate 6COLOR" from Tools -> Board menu.
5+
Don't have "Soldered Inkplate 6COLOR" option? Follow our tutorial and add it:
6+
https://soldered.com/learn/add-inkplate-6-board-definition-to-arduino-ide/
7+
8+
Here is shown how to use I/O Expander and ESP interrupts to wake up the MCU from deepsleep when touchpad is pressed.
9+
10+
Want to learn more about Inkplate? Visit www.inkplate.io
11+
Looking to get support? Write on our forums: https://forum.soldered.com/
12+
13 April 2023 by Soldered
13+
*/
14+
15+
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
16+
#ifndef ARDUINO_INKPLATECOLOR
17+
#error "Wrong board selection for this example, please select Soldered Inkplate 6COLOR in the boards menu."
18+
#endif
19+
20+
// Include Inkplate library to the sketch
21+
#include <Inkplate.h>
22+
23+
// Conversion factor for micro seconds to seconds
24+
#define uS_TO_S_FACTOR 1000000
25+
26+
// Time ESP32 will go to sleep (in seconds)
27+
#define TIME_TO_SLEEP 30
28+
29+
// Initiate Inkplate object
30+
Inkplate display;
31+
32+
// Store int in rtc data, to remain persistent during deep sleep
33+
RTC_DATA_ATTR int bootCount = 0;
34+
35+
void setup()
36+
{
37+
// Init Inkplate library (you should call this function ONLY ONCE)
38+
display.begin();
39+
40+
// Set interrupt on each touchpad
41+
display.setIntPin(PAD1);
42+
display.setIntPin(PAD2);
43+
display.setIntPin(PAD3);
44+
45+
++bootCount;
46+
47+
// Our function declared below
48+
displayInfo();
49+
50+
// Go to sleep for TIME_TO_SLEEP seconds, but also enable wake up from gpio 34
51+
// Gpio 34 is where the I/O Expander interrupt is connected
52+
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
53+
esp_sleep_enable_ext0_wakeup(GPIO_NUM_34, LOW);
54+
55+
// Go to sleep
56+
// Put the panel in the deep sleep
57+
display.setPanelDeepSleep(0);
58+
59+
// Start deep sleep (this function does not return). Program stops here.
60+
esp_deep_sleep_start();
61+
}
62+
63+
void loop()
64+
{
65+
// Never here! If you are using deep sleep, the whole program should be in setup() because the board restarts each
66+
// time. loop() must be empty!
67+
}
68+
69+
// Function that will write number of boots and boot reason to screen
70+
void displayInfo()
71+
{
72+
// First, lets delete everything from frame buffer
73+
display.clearDisplay();
74+
75+
// Set text cursor and size
76+
display.setCursor(10, 280);
77+
display.setTextSize(2);
78+
display.setTextColor(INKPLATE_BLACK);
79+
80+
display.print(F("Boot count: "));
81+
display.println(bootCount, DEC); // Print the number
82+
83+
// Set next line cursor position
84+
display.setCursor(10, 320);
85+
86+
// Display wake up reason
87+
esp_sleep_wakeup_cause_t wakeup_reason;
88+
wakeup_reason = esp_sleep_get_wakeup_cause();
89+
switch (wakeup_reason)
90+
{
91+
case ESP_SLEEP_WAKEUP_EXT0:
92+
display.println("Wakeup caused by touchpads");
93+
break;
94+
case ESP_SLEEP_WAKEUP_TIMER:
95+
display.println("Wakeup caused by timer");
96+
break;
97+
default:
98+
display.println("Wakeup was not caused by deep sleep");
99+
break;
100+
}
101+
102+
// Show a message on the screen
103+
display.display();
104+
}

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Datatypes (KEYWORD1)
44
Inkplate KEYWORD1
55
SdFile KEYWORD1
6+
esp_sleep_wakeup_cause_t KEYWORD1
67

78
# Methods and Functions (KEYWORD2)
89
begin KEYWORD2
@@ -101,6 +102,7 @@ dirIndex KEYWORD2
101102
isHidden KEYWORD2
102103
getName KEYWORD2
103104
isSubDir KEYWORD2
105+
esp_sleep_get_wakeup_cause KEYWORD2
104106

105107
# Instances (KEYWORD2)
106108

0 commit comments

Comments
 (0)