GxEPD2 Partial update shows scrambled text

Hello!

I am new to the forum and this is my first arduino project. I want to use a epaper display with a Seeed Studio XIAO nRF52840 to display some temperatures.

I have the following display from GoodDisplay: https://aliexpress.com/item/1005002546926786.html (So the GDEY029T94 with the DESPI-C02 shield).

I first print the layout, and then periodically want to update the numbers (for simplicity in the attached code those are random values). The first update of both temperatures works fine, any subsequent update result in scrambled numbers for the upper number, for the lower number everything works fine - please see my attached photos.

I hope this describes my problem enough!

I also tries switching the RESE values form 0,47 to 3 but I am not sure which is the correct number as both seem to produce the same result

This is my code:

#include <GxEPD2_BW.h>
#include <Fonts/FreeSans18pt7b.h>
#include <U8g2_for_Adafruit_GFX.h>
#include <bluefruit.h>

/*
Connection information:
Waveshare -- Seeed
-------------------
VCC/3.3   -- 3V3
GND       -- GND
DIN/SDI   -- MOSI
CLK/SCK   -- RX/SCK
CS        -- D6
DC        -- D5
RST       -- D4
BUSY      -- D3
*/

GxEPD2_BW<GxEPD2_290_T94, GxEPD2_290_T94::HEIGHT> display(GxEPD2_290_T94(/*CS=D6*/ D6, /*DC=DC5*/ D5, /*RST=D4*/ D4, /*BUSY=D3*/ D3)); 

U8G2_FOR_ADAFRUIT_GFX u8g2_4_gfx;
SoftwareTimer displayUpdateTimer;

void setup() {
  // low power mode 
  Bluefruit.begin(); // Sleep functions need the softdevice to be active.
  sd_power_mode_set(NRF_POWER_MODE_LOWPWR); 

  initDisplay();

  displayUpdateTimer.begin(10000, updateTemperatureCallback);  // Configure the timer with 1000 ms interval, with our callback
  displayUpdateTimer.start();  // Start the timer

  suspendLoop();
}

void loop() {
  // no code here time is used for this function and loop is suspended
}

void initDisplay() {
  display.init(115200, true);
  u8g2_4_gfx.begin(display);
  display.setRotation(0);

  printLayout();
  display.end();
}

void updateTemperatureCallback(TimerHandle_t xTimerID) {
  (void) xTimerID;
  updateTemperatures(random(19,25), random(0,35));
  sd_app_evt_wait(); // puts the nrf52 to sleep when there is nothing to do
}

void printLayout() {
  // setup font 
  u8g2_4_gfx.setFontMode(1);                   // use u8g2 transparent mode (this is default)
  u8g2_4_gfx.setFontDirection(0);              // left to right (this is default)
  u8g2_4_gfx.setForegroundColor(GxEPD_BLACK);  // apply Adafruit GFX color
  u8g2_4_gfx.setBackgroundColor(GxEPD_WHITE);  // apply Adafruit GFX color

  int16_t padding = 40;
  uint16_t width = 0;
  uint16_t x = 0;
  uint16_t y = 0;

  display.setFullWindow();
  display.firstPage();
  do
  {
    u8g2_4_gfx.setFont(u8g2_font_helvB10_tf);
    u8g2_4_gfx.setCursor(8, padding);
    u8g2_4_gfx.print("Innen:");
    u8g2_4_gfx.setCursor(8, display.height() / 2 + padding);
    u8g2_4_gfx.print("Außen:");

    display.drawLine(0, display.height() / 2, display.width(), display.height() / 2 , GxEPD_BLACK);
  }  
  while (display.nextPage());
}

void updateTemperatures(double insideTemp, double outsideTemp) 
{
  Serial.println("Begin update");
  display.init(115200, false);
  // append °C to the temperature strings
  String insideTempAsStr = String(String(insideTemp, 1) + "°C");
  String outsideTempAsStr = String(String(outsideTemp, 1) + "°C");

  uint16_t yCoordinateUpperHalfCenter = display.height() / 4;
  partiallyUpdateSingleTemperature(insideTempAsStr, yCoordinateUpperHalfCenter);

  delay(500);

  uint16_t yCoordinateLowerHalfCenter = display.height() / 4 * 3;
  partiallyUpdateSingleTemperature(outsideTempAsStr, yCoordinateLowerHalfCenter);

  display.end();
}

void partiallyUpdateSingleTemperature(String temperatureStr, uint16_t yCoordinateCenter) {
  // Convert temperature string to char array to be able to determine length
  int strLen = temperatureStr.length() + 1; 
  char temperatureAsCharArray[strLen];
  temperatureStr.toCharArray(temperatureAsCharArray, strLen);

  u8g2_4_gfx.setFont(u8g2_font_helvR24_tf);
  uint16_t tempStrWidth = u8g2_4_gfx.getUTF8Width(temperatureAsCharArray);
  uint16_t x = ((display.width() - tempStrWidth) / 2);
  uint16_t y = yCoordinateCenter + (u8g2_4_gfx.getFontAscent() / 2); // here the height of the font is used to center it in a box, baseline is the lower left of a text box

  display.fillRect(0, yCoordinateCenter - (u8g2_4_gfx.getFontAscent() / 2), display.width(), u8g2_4_gfx.getFontAscent(), GxEPD_WHITE);
  u8g2_4_gfx.setCursor(x, y);
  u8g2_4_gfx.print(temperatureAsCharArray);
  display.displayWindow(0, yCoordinateCenter - (u8g2_4_gfx.getFontAscent() / 2), display.width(), u8g2_4_gfx.getFontAscent());
}

Please note that i want to use the display.end() call as I want to achieve a very low power project.

The serial monitor prints the following:

20:01:05.693 -> Begin update
20:01:05.855 -> _PowerOn : 95703
20:01:06.275 -> _Update_Part : 406250
20:01:07.208 -> _Update_Part : 406250
20:01:15.685 -> Begin update
20:01:15.846 -> _PowerOn : 95704
20:01:16.264 -> _Update_Part : 406250
20:01:17.199 -> _Update_Part : 406250
20:01:25.710 -> Begin update
20:01:25.871 -> _PowerOn : 95704
20:01:26.256 -> _Update_Part : 406250
20:01:27.191 -> _Update_Part : 406250
20:01:35.703 -> Begin update
20:01:35.863 -> _PowerOn : 95703
20:01:36.250 -> _Update_Part : 406250
20:01:37.185 -> _Update_Part : 406250
20:01:45.693 -> Begin update
20:01:45.855 -> _PowerOn : 95704
20:01:46.272 -> _Update_Part : 406250
20:01:47.176 -> _Update_Part : 406250

Could you please assist me on how to get my partial updates working?

Often the library's author is around here with the definitive answer, however I think he is away for a little bit right now.

I can see roughly what is happening here, but I'm not sure familiar enough with GxEPD2's code to know exactly how to deal with it.

With a full refresh, all the pixels are cleared before the new image is displayed.
With the fast partial update, the refresh is "differential". Only pixels that change from the previous image to the new image are adjusted. To do this, the display's onboard memory stores two images: the new image to be drawn, and the previous image for comparison.

It looks to me that, for some reason, the display's memory of the previous image is not being correctly set / retained.

I have a few guesses, but it might help to get some follow-up information:

  • In updateTemperatures(), when the image breaks, do you see:
    a) the top value draw correctly, then become incorrect when the bottom is drawn, or
    b) the top image draw incorrectly, then remain unchanged, while the bottom draws correctly?

  • If you allow updateTemperatureCallback() to run several times:
    a) the bottom value continues to draw correctly, or
    b) the bottom value also becomes broken?

  • During printLayout():
    a) the display is cleared (flashing), then the image is drawn with partial update,
    b) the entire image is drawn with full-refresh (flashing), or
    c) no flashing occurs during the initial update

Most likely U8G2_FOR_ADAFRUIT_GFX doesn't draw the background, same as Adafruit_GFX with TrueType fonts. This effect is often reported for TFT displays also.

That's a good point, and I hadn't actually considered this.

I think that might not be the case here though, as the bottom half of the display is updating correctly, and if you look closely you can see that the black pixels have poor contrast where the two values are printed overlapping. This makes me think an issue with the refresh operation; if the overwriting was happening in the mcu image buffer, I would expect to see well defined pixels.

Yet another untested use case. So I need to interrupt my timeout.

In GxEPD2_290_T94.cpp add this statement:

  _writeImage(0x26, bitmap, x, y, w, h, invert, mirror_y, pgm); // set previous

before or after line 69. And add this statement:

  _writeImagePart(0x26, bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);

before or after line128.
The second addition may solve your issue.

I will need to verify this, when I have more time. And fix many other driver classes also.
-jz-

Added: But maybe these additions are not needed. There is a fix in version 1.5.6 related to this issue. This version is on GitHub, but not yet released.

GxEPD2 GDEY042T81 (Waveshare 4.2 BW v2.2) - partial update issue - Using Arduino / Displays - Arduino Forum

Thank you all for taking your time to look into my issue.

@toddnz To address the question to updateTemperatures() the top value is never correctly drawn on update so a) . Please see here GIF of first partial update

Regarding the updateTemperatureCallback() the bottom value actually never gets broken and always refreshes correctly.

Regarding the initial layout printing, it seems my display is doing b). It flashes several times and draws the full layout at once (also from what I can ready through the serial monitor).

Also thank you @ZinggJM. I tried adding those lines but this did not help. Unfortunantely now the upper value is drawn in very pale font. Also on update the upper values gets scrambled again see the picture here for how it looks after the first print:

I have also downloaded the lastest zip from your main branch on github and extracted it to my Arduino libraries directory, which resulted in the same value. I tried all of those aspects using both RESE values.

Are there any other ideas on how I could fix my issue?

Thanks!

Did you make sure the display receives power while your processor is in deep sleep?
I currently can't help you any further, I need my timeout.

The most straight-forward thing here would be to wait for the library's author (ZinggJM) to get a patch out in the not-too-distant future. I guess you can consider this conversation as a sort of bug report.

If you're still keen to kludge around try get a hot-fix working in the meantime, we can do that, but just be aware that this will most likely all get sorted officially at some point.

That is of course, if the behavior you're seeing is related to the library, and not something that about your set-up that no-one has spotted yet.


As ZinggJm mentioned:

Did you make sure the display receives power while your processor is in deep sleep?

Do you own a digital multimeter? It would be good to check that the display does continue to receive power during deep-sleep. If the Seeed Studio XIAO is removing power from the display, the display won't retain memory of the previous image, and will do something similar to what your images show.

If this is the case, you can probably tweak the deep-sleep settings somehow to make sure power is maintained. The current used to retain the memory is tiny, on the order of micro-amps.


Thank you for getting back with answers to those questions. Starting again with the unmodified code from the github repo, would you be able to test something else for me?

Two tests that won't fix the problem, but might give a clue:

  • Run updateTemperatures() twice per callback. Does this now break the bottom value?
void updateTemperatureCallback(TimerHandle_t xTimerID) {
  (void) xTimerID;
  updateTemperatures(random(19,25), random(0,35));
  delay(2000);
  updateTemperatures(random(19,25), random(0,35));
  sd_app_evt_wait(); // puts the nrf52 to sleep when there is nothing to do
}
  • Starting again from unmodified code: change the order of partiallyUpdateSingleTemperature(), so that the bottom value is set before the top. Does this now break the bottom value? Does the top value now draw correctly?

void updateTemperatures(double insideTemp, double outsideTemp) 
{
  Serial.println("Begin update");
  display.init(115200, false);
  // append °C to the temperature strings
  String insideTempAsStr = String(String(insideTemp, 1) + "°C");
  String outsideTempAsStr = String(String(outsideTemp, 1) + "°C");

  uint16_t yCoordinateLowerHalfCenter = display.height() / 4 * 3;
  partiallyUpdateSingleTemperature(outsideTempAsStr, yCoordinateLowerHalfCenter);

  delay(500);

  uint16_t yCoordinateUpperHalfCenter = display.height() / 4;
  partiallyUpdateSingleTemperature(insideTempAsStr, yCoordinateUpperHalfCenter);

  display.end();
}

Another thing I notice is that you're using end(), which ends SPI. I think you probably want hibernate(), which puts display into low-power state). I don't think this is related to the partial update situation though.

I would happily support debugging the library, however my knowledge is not very good on the inner workings of the display. As a "normal" application programmer, these hardware components are still a little bit of a black box to me. Is there any reference where I can read up the protocol on how to send commands to the display, this would probably help me understand a little bit better what is going on? Also should I post my bug issue somewhere else?


Regarding the idea from @ZinggJM

Did you make sure the display receives power while your processor is in deep sleep?

Yes i have a multimeter. I have now measured the 3.3v pin of the DESPI-C02 and during deep sleep of the chip it still delivers 0.08 mA - during partial refresh it draws about 1.4 mA.

Run updateTemperatures() twice per callback. Does this now break the bottom value?

I removed the library from my folder and re-installed it using the Arduino IDE Library manager I hope this is what you meant. I still see the same behaviour of only the upper number breaking, here a video to demonstrate how it looks like: Updating numbers twice

Starting again from unmodified code: change the order of partiallyUpdateSingleTemperature(), so that the bottom value is set before the top. Does this now break the bottom value? Does the top value now draw correctly?

Ah I forgot to mention that, but that's what I already tried beforehand and yes I repeated this test and now the bottom value is broken while the upper value is fine.


Regarding the hibernate() vs end() I did this on purpose as otherwise the power draw of the battery from the chip is significantly higher. I thought as long as the display gets power during deep-sleep (which is does see my measurements above) and I call display.init(115200, false); everything should work out fine. I was inspired by GxEPD2 - Partial update with deep sleep - #3 by raggio . Did I maybe miss something here?

Thanks again for all your contributions in supporting my project :smiley:

I can't exactly claim that my knowledge is all that thorough either..

Thank you for taking the time to upload that. It really helps to see what's going on.

I'm not aware of any really good reference. If there is one, I'd certainly like to know about it. Two documents you could look at would be the specifications for your display, and the datasheet for its internal controller IC. They're both pretty technical, but sections like "Operation Flow" and "Command Table" might start to give you an idea of what's going on. Of course, GxEPD2 itself is a good place to look at what it takes to get these displays working.


I just think you might have these two mixed up is all.
The code behind end() is only ending SPI and associated pins.

The code behind hibernate() powers down the hardware which generates voltages to drive the display refresh, and ends all on-display processing, until the next call to init(). This is key for power saving, and also important for display health. (Or at least, I think that's the case)


In other news, I may have spotted the issue:
I think you might be using the wrong class for your display.

// Try this instead
#include <GxEPD2_4C.h>
GxEPD2_4C<GxEPD2_290_GDEY029T94, GxEPD2_290_GDEY029T94::HEIGHT> display(GxEPD2_290_GDEY029T94(/*CS=D6*/ D6, /*DC=DC5*/ D5, /*RST=D4*/ D4, /*BUSY=D3*/ D3));

Swapping this over (and using hibernate) might be all it takes to get everything working correctly.

I can't resist replying... But at least I had a quiet day.

I didn't notice in the top post, although I should have, thanks to the link provided.

//GxEPD2_BW<GxEPD2_290_T94, GxEPD2_290_T94::HEIGHT> display(GxEPD2_290_T94(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEM029T94 128x296, SSD1680

is for the older panel GDEM029T94

You need to use this driver class:

//GxEPD2_BW<GxEPD2_290_GDEY029T94, GxEPD2_290_GDEY029T94::HEIGHT> display(GxEPD2_290_GDEY029T94(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEY029T94  128x296, SSD1680, (FPC-A005 20.06.15)

for your panel GDEY029T94.

And you also need to take the actual version from GitHub for your use case.

@toddnz : it is a b/w panel, you shouldn't use the display template class GxEPD2_4C with it.
-jz-

Oh right, sorry about that. I can see that in the code now that you point it out. I think maybe I was thrown by the fact that GoodDisplay have it labelled as a four grayscale panel. It seems that rather than making it easier for you to step away for a moment, I've just made another mess that you've had to clean up.. oops..

But it has helped! I wouldn't have spotted this without your post. Thank you!
-jz-

Thank you guys! That's it, works like a charm ... I always checked the T94 at the end but it never occurred to me that there is another driver.