Implement EPD deep sleep; Render battery voltage on screen
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include "esp_sleep.h"
|
||||||
|
|
||||||
//PIN LAYOUTS
|
//PIN LAYOUTS
|
||||||
#define SRAM_CS 32
|
#define SRAM_CS 32
|
||||||
@@ -10,8 +11,9 @@
|
|||||||
#define EPD_DC 33
|
#define EPD_DC 33
|
||||||
#define EPD_RESET -1 // can set to -1 and share with microcontroller Reset!
|
#define EPD_RESET -1 // can set to -1 and share with microcontroller Reset!
|
||||||
#define EPD_BUSY 27 // can set to -1 to not use a pin (will wait a fixed delay)
|
#define EPD_BUSY 27 // can set to -1 to not use a pin (will wait a fixed delay)
|
||||||
|
#define EPD_ENABLE 12
|
||||||
|
#define BATTERY_PIN A13
|
||||||
|
|
||||||
ThinkInk_290_Tricolor_Z10 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY);
|
ThinkInk_290_Tricolor_Z10 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY);
|
||||||
|
|
||||||
#define COLOR0 EPD_WHITE
|
#define COLOR0 EPD_WHITE
|
||||||
@@ -37,6 +39,10 @@ void setup() {
|
|||||||
while (!Serial) { delay(10); }
|
while (!Serial) { delay(10); }
|
||||||
Serial.println("Nightscout CGM BS Monitor starting...");
|
Serial.println("Nightscout CGM BS Monitor starting...");
|
||||||
|
|
||||||
|
//turn EPD on
|
||||||
|
pinMode(EPD_ENABLE, OUTPUT);
|
||||||
|
digitalWrite(EPD_ENABLE, HIGH);
|
||||||
|
|
||||||
ConnectToWifi();
|
ConnectToWifi();
|
||||||
String nightscoutResponse = httpGETRequest(nightscoutUrl);
|
String nightscoutResponse = httpGETRequest(nightscoutUrl);
|
||||||
Serial.println(nightscoutResponse);
|
Serial.println(nightscoutResponse);
|
||||||
@@ -57,6 +63,7 @@ void setup() {
|
|||||||
|
|
||||||
RenderGraph(array);
|
RenderGraph(array);
|
||||||
RenderRightPane(array[0]);
|
RenderRightPane(array[0]);
|
||||||
|
RenderBatteryPercentage();
|
||||||
|
|
||||||
display.display();
|
display.display();
|
||||||
|
|
||||||
@@ -101,6 +108,7 @@ void SleepWithTimeSync(int lastReadingInSeconds) {
|
|||||||
secondsToSleep = secondsToSleep + 7;
|
secondsToSleep = secondsToSleep + 7;
|
||||||
esp_sleep_enable_timer_wakeup(secondsToSleep * uS_TO_S_FACTOR);
|
esp_sleep_enable_timer_wakeup(secondsToSleep * uS_TO_S_FACTOR);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
|
TurnOffEPD();
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -109,9 +117,38 @@ void SleepWithTimeSync(int lastReadingInSeconds) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderBatteryPercentage() {
|
||||||
|
int batteryPinInput = analogRead(BATTERY_PIN);
|
||||||
|
Serial.printf("raw adc value %d", batteryPinInput);
|
||||||
|
//Vin = 3.3(read/4098)
|
||||||
|
float batteryVoltage = 3.3 * (float(batteryPinInput) / 4098.0);
|
||||||
|
//ESP32 A13 returns half the voltage, so double this reading
|
||||||
|
batteryVoltage = batteryVoltage * 2.0;
|
||||||
|
Serial.print("calc. voltage ");
|
||||||
|
Serial.println(batteryVoltage);
|
||||||
|
|
||||||
|
//Render on screen
|
||||||
|
display.setCursor(245, 110);
|
||||||
|
display.setTextSize(2);
|
||||||
|
if(batteryVoltage < 3.6)
|
||||||
|
display.setTextColor(COLOR2);
|
||||||
|
else
|
||||||
|
display.setTextColor(COLOR1);
|
||||||
|
display.print(batteryVoltage);
|
||||||
|
display.print("v");
|
||||||
|
}
|
||||||
|
|
||||||
|
void TurnOffEPD() {
|
||||||
|
digitalWrite(EPD_ENABLE, LOW);
|
||||||
|
delay(1000);
|
||||||
|
gpio_hold_en(GPIO_NUM_12);
|
||||||
|
gpio_deep_sleep_hold_en();
|
||||||
|
}
|
||||||
|
|
||||||
void SleepFiveMins() {
|
void SleepFiveMins() {
|
||||||
esp_sleep_enable_timer_wakeup(285 * uS_TO_S_FACTOR);
|
esp_sleep_enable_timer_wakeup(285 * uS_TO_S_FACTOR);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
|
TurnOffEPD();
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user