RAM Problem with 1.54 inch E-Paper and ATmega328P + GxEPD2

I am a beginner with e-papers and I Need help! I want to display text on a Waveshare E-Paper BW display 1.54 inch with an Arduino UNO. Unfortunately, Waveshare does not have a product name for the display. My simple test program also works conditionally. If I change

#define MAX_DISPLAY_BUFFER_SIZE 400

to

#define MAX_DISPLAY_BUFFER_SIZE 1000

I get strange artifacts - you can see them on the photos.


I suspect it is a RAM problem. In both cases there seems to be enough free space:

Global variables use 945 bytes (46%) of dynamic memory, leaving 1103 bytes for local variables. Maximum is 2048 bytes.

Global variables use 1545 bytes (75%) of dynamic memory, leaving 503 bytes for local variables. Maximum is 2048 bytes.

My sketch:

#define ENABLE_GxEPD2_GFX 0
#include <GxEPD2_BW.h>
#include <Fonts/FreeSansBold18pt7b.h>

// SPI Arduino UNO
// #define SPI_DIN 11
// #define SPI_CLK 13
#define SPI_CS 10
#define SPI_DC 14    // A0
#define SPI_RST 15   // A1
#define SPI_BUSY 16  // A2

// #define GxEPD2_DRIVER_CLASS GxEPD2_154_GDEY0154D67
#define GxEPD2_DRIVER_CLASS GxEPD2_154_D67

#define MAX_DISPLAY_BUFFER_SIZE 400
//#define MAX_DISPLAY_BUFFER_SIZE 1000

#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 8))
GxEPD2_BW<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(SPI_CS, SPI_DC, SPI_RST, SPI_BUSY));

void setup() {
  display.init(0);
  display.setRotation(3);
  display.setTextColor(GxEPD_BLACK);
  staticScreen();
}


void staticScreen() {
  display.firstPage();
  do {
    display.fillScreen(GxEPD_WHITE);
    display.setCursor(48, 160);
    display.setFont(&FreeSansBold18pt7b);
    display.print("HELLO");
  } while (display.nextPage());
}

void loop() {
}

I look forward to any advice. Manfred

500 bytes is not enough memory for the micro to work; it needs about 400 bytes just to "run."
Why do you need to expand the buffer?

Try with 800. Like in the examples!

Thanks for your reply. I'll use the display for a batterie powered project, so power consum is impotant. I thought more buffer means less cycles in the paged-loop, resulting in less batterie consumption.

Thanks for the hint. Didn't notice that.

I have found a cause. setFont() shouldn't be called in the page-loop. That was a stupid thing for me to do. Sorry. Manfred

Update:

Excuse me. I think that was a coincidence. I need to reduce the buffer size. Manfred