Howdy,
I'm trying to use an esp32 (Lolin D32 Pro board) with an waveshare epaper display (2.9" BW) utilizing the GxEPD2 library. Everything works fine as long as I print directly to the display. However, using partial mode doesn't really work and I don't understand what's wrong. But since the example works, it must be something with my code.
So, here's the relevant part of it:
#define ENABLE_GxEPD2_GFX 0
#include <GxEPD2_BW.h>
//#include <GxEPD2_3C.h>
//#include <GxEPD2_7C.h>
#include <Fonts/FreeMonoBold9pt7b.h>
// select the display class and display driver class in the following file (new style):
#include "GxEPD2_display_selection_new_style.h"
// time management
#include <Esp.h>
#include <esp_system.h>
#include <sys/time.h>
// GLOBALS
char timebuf[64];
struct ShowBoxParameters {
uint16_t x, y, w, h;
};
void settime() {
// set current day/time
struct timeval tv;
tv.tv_sec = 1641126821; // enter UTC UNIX time (get it from https://www.unixtimestamp.com )
settimeofday(&tv, NULL);
// Set timezone to France (Europe/Paris)
setenv("TZ", "CET-1CEST,M3.5.0/2,M10.5.0/ 3", 1);
tzset();
}
void getClock() {
time_t now;
struct tm timeDetails;
time(&now);
localtime_r(&now, &timeDetails);
Serial.print("The current date/time is ");
Serial.println(&timeDetails, "%A, %B %d %Y %H:%M:%S");
strftime(timebuf, sizeof(timebuf), "%H:%M:%S", &timeDetails);
}
void timeBoxCallback(const void *parameters) {
const ShowBoxParameters* p = reinterpret_cast<const ShowBoxParameters*>(parameters);
display.fillRect(p->x, p->y, p->w, p->h, GxEPD_WHITE);
display.setCursor(p->x, p->y);
display.print(timebuf);
}
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("initializing epaper display");
display.init(115200);
display.setRotation(1);
display.setFont(&FreeMonoBold9pt7b);
display.setFullWindow();
display.fillScreen(GxEPD_WHITE);
Serial.print(" display width: ");
Serial.println(display.width());
Serial.print("display height: ");
Serial.println(display.height());
Serial.println("setting time");
settime();
Serial.println("setup done");
}
void loop() {
uint16_t x = 8;
uint16_t y = 8;
ShowBoxParameters boxParameters{x, y, 70, 20};
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
display.setPartialWindow(boxParameters.x, boxParameters.y,
boxParameters.w, boxParameters.h);
while (1) {
getClock();
display.firstPage();
do {
display.drawPaged(timeBoxCallback, &boxParameters);
} while (display.nextPage());
delay(1000);
}
}
extern "C" void app_main() {
setup();
loop();
}
Running this code results in this on the display:
On the serial monitor I can see this:
initializing epaper display
display width: 296
display height: 128
setting time
setup done
The current date/time is Sunday, January 02 2022 13:51:34
_PowerOn : 35875
_Update_Full : 1543779
_Update_Part : 353505
The current date/time is Sunday, January 02 2022 13:51:37
_Update_Part : 353516
_Update_Part : 353528
..
The current date/time is Sunday, January 02 2022 13:51:40
_Update_Part : 353456
_Update_Part : 353446
The current date/time is Sunday, January 02 2022 13:51:42
_Update_Part : 353457
_Update_Part : 353465
etc.
So, what's wrong here? The stuff which can be seen on the display looks like the top or bottom 1 or 2 pixel wide line of the printed time. If I print more (e.g. also the date), then this scattered line gets wider.
I also did not understand the positioning of the cursor. From the logical point of view one would assume, that setCursor() uses coordinates relative to the current window (or full screen if not inside a window), But whatever values I tried, nothing worked.
It would be really great if someone could help me understand this.
Thanks in advance,
Tom

