Skip to content

Commit 1879f0b

Browse files
committed
Finished examples
1 parent 5998154 commit 1879f0b

File tree

14 files changed

+2028
-0
lines changed

14 files changed

+2028
-0
lines changed
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/**
2+
**************************************************
3+
*
4+
* @file Inkplate_6_Motion_Simple_Deep_Sleep.ino
5+
* @brief How to use the low-power deep sleep feature on Inkplate 6MOTION,
6+
* read the wake up cause and set to wake on WAKE button
7+
*
8+
* For info on how to quickly get started with Inkplate 6MOTION visit docs.inkplate.com
9+
*
10+
* @authors Borna Biro and Robert Soric for soldered.com
11+
* @date January 2025
12+
***************************************************/
13+
14+
// Include Inkplate Motion Library
15+
#include <InkplateMotion.h>
16+
17+
// Include Soldered font
18+
#include "solderedFont30pt7b.h"
19+
20+
// Create Inkplate object
21+
Inkplate inkplate;
22+
23+
// Variable to store backup RAM data
24+
// Explained below, this is how you can store data between sleeps
25+
int value = 0;
26+
27+
void setup()
28+
{
29+
// Initialize Serial communication @ 115200 bauds
30+
Serial.begin(115200);
31+
32+
// Write debug message
33+
Serial.println("Inkplate started");
34+
35+
// Initialize Inkplate Motion library
36+
inkplate.begin();
37+
38+
// Initialize STM32 RTC (needed for Backup RAM) without reseting the whole RTC
39+
inkplate.rtc.begin(RTC_HOURFORMAT_24);
40+
41+
// Check if is this first time the example is run, reset the variable
42+
if (!inkplate.rtc.isRTCSet())
43+
{
44+
// Initialize RTC and reset it! Otherwise, backup RAM will return wrong value
45+
inkplate.rtc.begin(RTC_HOURFORMAT_24, true);
46+
47+
// Force RTC Set variable to run this part of the code only once
48+
// The otherway to do this is to set the clock or date
49+
inkplate.rtc.rtcSetFlag();
50+
51+
// Set variable stored in backup RAM to zero. This RAM is available between
52+
// system resets, but also between power cycles (if RTC battery is provided)
53+
inkplate.rtc.writeToBackupRAM(0, &value, sizeof(value));
54+
}
55+
56+
// Set Soldered font
57+
inkplate.setFont(&solderedFont30pt7b);
58+
59+
// Set text color to black with white background.
60+
inkplate.setTextColor(BLACK, WHITE);
61+
62+
// Start printing text at X = 0, Y = 50
63+
inkplate.setCursor(0, 50);
64+
65+
// Print the reset cause
66+
printResetCause();
67+
68+
// Get the new value of the variable from the backup RAM
69+
inkplate.rtc.readFromBackupRAM(0, &value, sizeof(value));
70+
71+
// Print some text on screen
72+
inkplate.printf("Inkplate 6 MOTION deep sleep example.\nWoken up %d times.", value++);
73+
74+
// Store the new value
75+
inkplate.rtc.writeToBackupRAM(0, &value, sizeof(value));
76+
77+
// Refresh the screen
78+
inkplate.display();
79+
80+
// Check if the wake up from sleep did reset the board. If so, clear the flags
81+
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
82+
{
83+
// Clear Standby flag
84+
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
85+
86+
// Wake-up button on Inkplate 6 Motion is PC13 = WAKEUP PIN 4.
87+
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN4);
88+
}
89+
90+
// Enable wake up button. By setting PC13 to low (button press), Inkplate will wake up
91+
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN4_LOW);
92+
93+
// Print last message before goint to sleep
94+
Serial.println("Going to sleep");
95+
Serial.flush();
96+
97+
// Finally, enter in sleep mode (deep sleep, lowest current consumption, but data is not retained, after wake up,
98+
// code starts from begining)
99+
deepSleep(); // Code stops here!
100+
}
101+
102+
void loop()
103+
{
104+
// Nothing! Must be empty!
105+
}
106+
107+
// This fucntion demonstrates the different reset causes
108+
// How to read them, and what they represent
109+
void printResetCause(void)
110+
{
111+
uint32_t reset_cause = RCC->RSR; // Read the RSR register
112+
113+
inkplate.print("Reset cause(s):\n");
114+
115+
if (reset_cause & RCC_RSR_CPURSTF)
116+
{
117+
inkplate.printf("-CPU Reset\n");
118+
}
119+
120+
if (reset_cause & RCC_RSR_D1RSTF)
121+
{
122+
inkplate.printf("-Deep sleep reset (D1)\n");
123+
}
124+
125+
if (reset_cause & RCC_RSR_D2RSTF)
126+
{
127+
inkplate.printf("-Deep sleep reset (D2)\n");
128+
}
129+
130+
if (reset_cause & RCC_RSR_BORRSTF)
131+
{
132+
inkplate.printf("-Brownout reset\n");
133+
}
134+
135+
if (reset_cause & RCC_RSR_PINRSTF)
136+
{
137+
inkplate.printf("-Pin reset\n");
138+
}
139+
140+
if (reset_cause & RCC_RSR_PORRSTF)
141+
{
142+
inkplate.printf("-Power-on reset\n");
143+
}
144+
145+
if (reset_cause & RCC_RSR_SFTRSTF)
146+
{
147+
inkplate.printf("-Software reset\n");
148+
}
149+
150+
if (reset_cause & RCC_RSR_IWDG1RSTF)
151+
{
152+
inkplate.printf("-Independent watchdog reset\n");
153+
}
154+
155+
if (reset_cause & RCC_RSR_WWDG1RSTF)
156+
{
157+
inkplate.printf("-Window watchdog reset\n");
158+
}
159+
160+
161+
if (reset_cause & RCC_RSR_LPWRRSTF)
162+
{
163+
inkplate.printf("-Low-power reset\n");
164+
}
165+
166+
// Clear the reset flags
167+
__HAL_RCC_CLEAR_RESET_FLAGS();
168+
}
169+
170+
// Deep sleep function. Calling this will put STM32 in deep sleep mode. If all peripherals are disabled
171+
// deep sleep current will be around 20-30uA
172+
void deepSleep()
173+
{
174+
// Disable all peripherals including WiFi, microSD card, SDRAM, sensors etc
175+
inkplate.peripheralState(INKPLATE_PERIPHERAL_ALL, false);
176+
177+
// Disable USB voltage detection on USB OTG (This causes high current consumption in sleep!)
178+
HAL_PWREx_DisableUSBVoltageDetector();
179+
180+
// Use different voltage scale for internal voltage regulator (lower current consumption in sleep mode)
181+
HAL_PWREx_ControlStopModeVoltageScaling(PWR_REGULATOR_SVOS_SCALE5);
182+
183+
// Put every domain into standby mode
184+
HAL_PWREx_EnterSTANDBYMode(PWR_D3_DOMAIN);
185+
HAL_PWREx_EnterSTANDBYMode(PWR_D2_DOMAIN);
186+
HAL_PWREx_EnterSTANDBYMode(PWR_D1_DOMAIN);
187+
}

examples/Advanced/Sensors/Inkplate_6_MOTION_Accelerometer_Cube/Inkplate_6_MOTION_Accelerometer_Cube.ino renamed to examples/Advanced/Sensors_Other/Inkplate_6_MOTION_Accelerometer_Cube/Inkplate_6_MOTION_Accelerometer_Cube.ino

File renamed without changes.

examples/Advanced/Sensors/Inkplate_6_MOTION_GestureSensor_Gesture/FreeSansBold24pt7b.h renamed to examples/Advanced/Sensors_Other/Inkplate_6_MOTION_GestureSensor_Gesture/FreeSansBold24pt7b.h

File renamed without changes.

examples/Advanced/Sensors/Inkplate_6_MOTION_GestureSensor_Gesture/Inkplate_6_MOTION_GestureSensor_Gesture.ino renamed to examples/Advanced/Sensors_Other/Inkplate_6_MOTION_GestureSensor_Gesture/Inkplate_6_MOTION_GestureSensor_Gesture.ino

File renamed without changes.

examples/Advanced/Sensors/Inkplate_6_MOTION_GestureSensor_Gesture/image.h renamed to examples/Advanced/Sensors_Other/Inkplate_6_MOTION_GestureSensor_Gesture/image.h

File renamed without changes.

examples/Advanced/Sensors/Inkplate_6_MOTION_GestureSensor_Interrupts/FreeSansBold24pt7b.h renamed to examples/Advanced/Sensors_Other/Inkplate_6_MOTION_GestureSensor_Interrupts/FreeSansBold24pt7b.h

File renamed without changes.

examples/Advanced/Sensors/Inkplate_6_MOTION_GestureSensor_Interrupts/Inkplate_6_MOTION_GestureSensor_Interrupts.ino renamed to examples/Advanced/Sensors_Other/Inkplate_6_MOTION_GestureSensor_Interrupts/Inkplate_6_MOTION_GestureSensor_Interrupts.ino

File renamed without changes.

examples/Advanced/Sensors/Inkplate_6_MOTION_GestureSensor_Interrupts/image.h renamed to examples/Advanced/Sensors_Other/Inkplate_6_MOTION_GestureSensor_Interrupts/image.h

File renamed without changes.

0 commit comments

Comments
 (0)