How to update only a portion of a e-paper display

I am programming a Waveshare 4.2 inch e-paper display using the epd4in2b_V2 sample as a base. I created a small rectangle to hold a value that I want to update periodically with a temperature. I looked through the .h and .cpp files to find a way to do this without a full screen refresh, but don't see a way. The DisplayFrame routine refreshes the entire display and it takes a long time with something like 10 flashes. I posted a simplified version of my code below. The Update_Count() routine is where I'm trying to update just the rectangle holding a number.



#include <SPI.h>
#include "epd4in2b_V2.h"
#include "imagedata.h"
#include "epdpaint.h"

#define COLORED     0
#define UNCOLORED   1

Epd epd;
unsigned char image[3000];       // how do I calculate what value I need?
Paint paint(image, 400, 24);     // width should be the multiple of 8

void setup() {
  Serial.begin(9600);
  Epd epd;

  if (epd.Init() != 0) {
    Serial.print("e-Paper initialization failed");
    return;
  }

  epd.ClearFrame();                // This clears the SRAM of the e-paper display
  //  unsigned char image[3000];       // how do I calculate what value I need?
  //  Paint paint(image, 400, 24);     // width should be the multiple of 8

  // Title
  paint.SetWidth(400);
  paint.SetHeight(24);
  paint.Clear(UNCOLORED);         // black text in white background
  paint.DrawStringAt(50, 0, "This is the title", &Font24, COLORED);
  epd.SetPartialWindowBlack(paint.GetImage(), 0, 0, paint.GetWidth(), paint.GetHeight());

  // draw a box to hold a count
  paint.SetWidth(41);   // width of window
  paint.SetHeight(31);  // height of window
  paint.Clear(UNCOLORED);
  paint.DrawRectangle(0, 0, 40, 30, COLORED);
  paint.DrawStringAt(10, 10, "T1", &Font16, COLORED);
  epd.SetPartialWindowBlack(paint.GetImage(), 200, 80, paint.GetWidth(), paint.GetHeight()); 

  /* This displays the data from the SRAM in e-Paper module */
  epd.DisplayFrame(); // show the frame

  /* This displays an image */
  // epd.DisplayFrame(IMAGE_BLACK, IMAGE_RED);

  /* Deep sleep */
   epd.Sleep();
}

void Update_count(int ct) {                         // Add simple count to display
  char b[5];                                        // create a char array
  itoa(ct, b, 10);                                  // convert the integer to char for DrawString function
  paint.SetWidth(41);                               // set width of window
  paint.SetHeight(31);                              // set height of window
  paint.Clear(UNCOLORED);                           // clear the window
  paint.DrawRectangle(0, 0, 40, 30, COLORED);       // draw the rectangle
  paint.DrawStringAt(10, 10, b, &Font16, COLORED);  // draw the count number in the rectangle
  Serial.println("updating display");
  epd.SetPartialWindowBlack(paint.GetImage(), 200, 80, paint.GetWidth(), paint.GetHeight()); //where the origin is
  epd.DisplayFrame();                               // refresh the frame
}

void loop() {
    for (int c1 = 0; c1 < 20; c1++) {
      Serial.println(c1);
      Update_count(c1);
      delay(1000);
    }

Perhaps you use the "SetPartialWindow" functions of the library:

    void SetPartialWindow(const unsigned char* buffer_black, const unsigned char* buffer_red, int x, int y, int w, int l);
    void SetPartialWindowBlack(const unsigned char* buffer_black, int x, int y, int w, int l);
    void SetPartialWindowRed(const unsigned char* buffer_red, int x, int y, int w, int l);

I have not used such a display but on the LCD display I print the old text with the background color to delete it and then I print the new text with normal color. I don't know if this method is applicable to this type of display but you can try.

I am using that command already. I think the problem is with the DisplayFrame() function. It updates the entire display when all I need is for it to update only a portion of it. If I comment out that line, it doesn't update at all.

So it turns out that the tri-color version of the 4.2" Waveshare display does not support partial updates. It was suggested that I use the monochrome version.

So why do they have versions of the SetPartialWindow() function that can write to Red, Black, or both?

All I know is that I spent a few days trying to figure it out, searching the header and cpp files for calls and came up empty. I also tried other code samples to no avail. I'm returning the display to Amazon and looking for a monochrome version with proper code samples. Here was their reply.

The tricolor display which supports three colors doesn't support partial updates.
If you require the partial update, how about using the monochrome version?
https://www.waveshare.com/4.2inch-e-paper-module.htm

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.