|
| 1 | +/* |
| 2 | + Inkplate_Partial_Update_With_Deep_Sleep example for e-radionica Inkplate 6 |
| 3 | + For this example you will need only USB cable and Inkplate 6 |
| 4 | + Select "Inkplate 6(ESP32)" from Tools -> Board menu. |
| 5 | + Don't have "Inkplate 6(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 partial update of epaper screen with deep sleep functionality of ESP32. |
| 9 | + This example is not same as Inkplate-basic_partial_update! Do not use Inkplate-basic_partial_update with deep sleep, IT WON'T WORK! |
| 10 | + Reason why you have to use this method with deep sleep is down how partail update works. It saves content from screen in RAM. |
| 11 | + By calling partialUpdate() function, code finds difference between what is currently on screen and what will be written and sends only that. |
| 12 | + When deep sleep is used, all content form the RAM has been deleted, so ESP32 doesn't know what is currently on the screen, so |
| 13 | + you have to "rewrite" what is currently on the screen, preload that and then create new screen that will be updated with partial update. |
| 14 | + NOTE: Partial update is only available on 1 Bit mode (BW) and it is not recommended to use it on first refresh after |
| 15 | + power up. It is recommended to do a full refresh every 5-10 partial refresh to maintain good picture quality. |
| 16 | +
|
| 17 | + Want to learn more about Inkplate? Visit www.inkplate.io |
| 18 | + Looking to get support? Write on our forums: http://forum.e-radionica.com/en/ |
| 19 | + 4 November 2020 by e-radionica.com |
| 20 | +*/ |
| 21 | + |
| 22 | +#include "Inkplate.h" // Include Inkplate library to the sketch |
| 23 | +#include <rom/rtc.h> // Include ESP32 library for RTC (needed for rtc_get_reset_reason() function) |
| 24 | +#include "driver/rtc_io.h" // Include ESP32 library for RTC pin I/O (needed for rtc_gpio_isolate() function) |
| 25 | + |
| 26 | +#define uS_TO_S_FACTOR 1000000 // Conversion factor for micro seconds to seconds |
| 27 | +#define TIME_TO_SLEEP 10 // Time how long ESP32 will be in deep sleep (in seconds). In this case 10 seconds. |
| 28 | + |
| 29 | +Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1-bit mode (BW) |
| 30 | + |
| 31 | +// Counter variable (stored in RTC RAM that stores variable even if deep sleep is used) |
| 32 | +// Variables that are changed after each partial update has to be stored in RTC RAM in order to recreate screen before deep sleep |
| 33 | +RTC_DATA_ATTR int counter = 0; |
| 34 | +RTC_DATA_ATTR float decimal = PI; |
| 35 | + |
| 36 | +void setup() |
| 37 | +{ |
| 38 | + display.begin(); // Init Inkplate library (you should call this function ONLY ONCE) |
| 39 | + createScreen(); // Function that contains everything that has to be written on screen |
| 40 | + |
| 41 | + if (rtc_get_reset_reason(0) == DEEPSLEEP_RESET) // Check if ESP32 is reseted by deep sleep or power up / user manual reset (or some other reason) |
| 42 | + { |
| 43 | + display.preloadScreen(); // If is woken up by deep sleep, recreate whole screen to be same as was before deep sleep |
| 44 | + counter++; // Update variable / variables |
| 45 | + decimal*=1.23; |
| 46 | + display.clearDisplay(); // Clear everything in buffer |
| 47 | + createScreen(); // Create new screen with new variables |
| 48 | + display.partialUpdate(INKPLATE_FORCE_PARTIAL); // Force partial update of screen. (Use this only in this scenario, otherwise YOU CAN DAMAGE YOUR SCRREN) |
| 49 | + } |
| 50 | + else // If is not deep sleep reset, that must be some thing else, so use normal update procerude (full screen update) |
| 51 | + { |
| 52 | + display.display(); |
| 53 | + } |
| 54 | + esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); // Set EPS32 to be woken up in 10 seconds (in this case) |
| 55 | + rtc_gpio_isolate(GPIO_NUM_12); // Isolate/disable GPIO12 on ESP32 (only to reduce power consumption in sleep) |
| 56 | + esp_deep_sleep_start(); //Put ESP32 into deep sleep (low power mode) |
| 57 | +} |
| 58 | + |
| 59 | +void loop() |
| 60 | +{ |
| 61 | + // Nothing should be here while using deep sleep! |
| 62 | +} |
| 63 | + |
| 64 | +void createScreen() |
| 65 | +{ |
| 66 | + display.setCursor(200, 300); // Set text cursor @ X = 200, Y = 300 |
| 67 | + display.setTextSize(3); // Set font to be scaled up three times |
| 68 | + display.print("First variable:"); // Write first variable to buffer |
| 69 | + display.print(counter, DEC); |
| 70 | + display.setCursor(200, 340); // Set text cursor @ X = 200, Y = 340 |
| 71 | + display.print("Second variable:"); // Write second variable to buffer (use two decimals places) |
| 72 | + display.print(decimal, 2); |
| 73 | +} |
0 commit comments