Hello, I'm fairly new about 2-3 months into Arduino so forgive me if I'm missing something. I've spent a lot of time searching for anyone who has a related issue but I have not found any answers. I was following a tutorial on how to build a low-power e-paper display that refreshes every 24 hours. I've spent a lot of time understanding how this project works. I've found that sleep mode is working as expected except a variable im incrementing [refreshCounter] every time it wakes up is losing its value, meaning when I print to the console it shows up as a weird string [][]. This only happens after a decent amount of time waking and sleeping. It used to be an hour but now its a few minutes. This ruins the functionality and I've messed with a lot of things trying to get this to work, like putting a delay and uncommenting out the e-paper functionality.
#include "LowPower.h"
#include "epd.h"
const int wake_up = 6;
// const int reset = 5;
const int lcd_on = 4;
const int button = 3;
int refreshRate = 10800; //time between loading images. number you enter * 8 = seconds between refresh (10800 = 24h)
int counter = 1;
int refreshCounter = 0;
int ByteReceived;
bool errorFlag = false;
bool picSend = false;
bool picLoaded = false;
// bool buttonP() {
// if (digitalRead(button) == HIGH) {
// delay(500);
// return true;
// } else {
// return false;
// }
// }
void setup(void)
{
Serial.begin(9600);
pinMode(lcd_on, OUTPUT);
pinMode(13, OUTPUT);
// pinMode (buttonP, INPUT);
digitalWrite(13, LOW);
// attachInterrupt(1, buttonPr, RISING);
}
void loop(void) {
DrawPic();
counter++;
}
// void buttonPr() {
// refreshCounter = refreshRate;
// wakeUp();
// }
void wakeUp() {
refreshCounter++;
Serial.println(refreshCounter);
if (refreshCounter < refreshRate ) enterSleep();
}
void DrawPic() {
// digitalWrite(13, LOW);
// //delay(2000);
// digitalWrite(lcd_on, HIGH);
// delay(300);
// epd_init(wake_up, reset);
// epd_wakeup(wake_up);
// epd_set_memory(MEM_TF);
// epd_clear();
// digitalWrite(13, HIGH);
// //int index = 7;
// String indexStr = String(counter);
// String str = 'i' + indexStr + ".BMP ";
// char character[str.length()] ;
// str.toCharArray(character, str.length());
// epd_disp_bitmap(character, 0, 0);
// epd_udpate();
// epd_enter_stopmode();
// while (1) {
// ByteReceived = Serial.read();
// if (ByteReceived == 13) {
// picSend = true;
// }
// if (ByteReceived == 69) {
// errorFlag = true;
// //if(!picSend && counter == 1) noSDcard();
// //if(picSend && counter == 1) noPic();
// //resetFunc();
// counter = 0;
// //Serial.flush();
// break;
// }
// if (ByteReceived == 75 && picSend && picLoaded) {
// break;
// }
// if (ByteReceived == 75 && picSend) {
// picLoaded = true;
// }
// }
// digitalWrite(13, LOW);
// digitalWrite(lcd_on, LOW);
// picLoaded = false;
// errorFlag = false;
// picSend = false;
refreshCounter = 0;
Serial.println("reset");
enterSleep();
}
void enterSleep() {
Serial.flush();
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
wakeUp();
}