I'm using the Waveshare 1.54inch e-Paper display with my Arduino nano 33 BLE with the resources they provide to make an smartwatch display.
I've been able to make partial updates of different parts of the image in each loop. To do this, I use the SetFrameMemoryPartial() function many times to place different elements, and when all are set, I do DisplayPartFrame DisplayPartFrame().
This method works fine, but as it takes a lot of time to write each element I was trying to only draw the elements that have changed, hoping that the unchanged will remain as they are thanks to being a partial update. However, the not updated elements appear and dissapear with each update or display previous values (see the attached videos for a better understanding).
Why is this happening? Am I understanding anything wrong? There's not much documentation so I don't really understand how it really works.
Video 1, dissapearing behaviour
Video 2, previous values showing
Epd epd;
unsigned char image[1024];
Paint paint(image, WIDTH, HEIGHT);
String time_str = "";
int heart_rates[4] = {60, 34, 65, 86};
char textBuffer[MAX_TEXT_LENGTH + 1]; // +1 for null terminator
unsigned long time_start;
int i = 0;
void setup()
{
Serial.begin(115200);
Serial.println("e-Paper init and clear");
epd.LDirInit();
epd.Clear();
time_start = millis();
}
void loop()
{
// Write heart rate
writeTextXCentered(String(heart_rates[i % 4]).c_str(), &Font24, 30);
// Write time (hours and minutes)
snprintf(textBuffer, MAX_TEXT_LENGTH + 1, "%02d:%02d", (millis() - time_start) / 1000 / 60 / 60, (millis() - time_start) / 1000 / 60 % 60);
if (time_str != textBuffer)
{
Serial.println("Time changed");
writeNumberXCentered(textBuffer, &MonoRegular, 64); // 57 is the y position for mono regular font
}
// store time in a string
time_str = textBuffer;
epd.DisplayPartFrame();
delay(1000);
i++;
}
void writeTextXCentered(const char *text, sFONT *font, int pos_y)
{
int width, height;
calculateWidthHeight(text, &width, &height, font->Width, font->Height);
paint.SetWidth(WIDTH);
paint.SetHeight(height);
paint.Clear(UNCOLORED);
paint.DrawStringAt(DISPLACEMENT_CORRECTION, 0, text, font, COLORED);
epd.SetFrameMemoryPartial(paint.GetImage(), calculateDisplacementX(width), pos_y, paint.GetWidth(), paint.GetHeight());
}
Thanks!