Hi, I've been trying to interface a Waveshare 1.45inch 200x200 B/W e-paper display with arduino. The standard liberary test codes from both Waveshare and GxEPD work as expected. The issue is I'm not able to understand how the partial update function works in these displays. I tried to search for a GxEPD wiki, but seems like it doesn't exist. Please allow me to begin with the standard GxEPD Partial Update example. The code below only addresses an Arduino and is the bare minimum that I could get it work. Its working is perplexing and Im not able to understand when the code is refreshing a specific area on the display.
#include <GxEPD.h>
#include <GxGDEP015OC1/GxGDEP015OC1.cpp> // 1.54" b/w
#include <GxIO/GxIO_SPI/GxIO_SPI.cpp>
#include <GxIO/GxIO.cpp>
#include <Fonts/FreeMonoBold9pt7b.h> // FreeFonts from Adafruit_GFX
#include GxEPD_BitmapExamples
// pins_arduino.h, e.g. AVR
#define PIN_SPI_SS (10)
#define PIN_SPI_MOSI (11)
#define PIN_SPI_MISO (12)
#define PIN_SPI_SCK (13)
GxIO_Class io(SPI, SS, 8, 9);
GxEPD_Class display(io);
//#define DEMO_DELAY 3*60 // seconds
//#define DEMO_DELAY 1*60 // seconds
#define DEMO_DELAY 30
void setup(void)
{
Serial.begin(115200);
Serial.println();
Serial.println("setup");
display.init();
Serial.println("setup done");
}
void loop()
{
showPartialUpdate_AVR();
}
void showBlackBoxCallback(uint32_t v)
{
uint16_t box_x = 10;
uint16_t box_y = 15;
uint16_t box_w = 70;
uint16_t box_h = 20;
display.fillRect(box_x, box_y, box_w, box_h, v);
}
void showValueBoxCallback(const uint32_t v)
{
uint16_t box_x = 10;
uint16_t box_y = 15;
uint16_t box_w = 70;
uint16_t box_h = 20;
uint16_t cursor_y = box_y + box_h - 6;
display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
display.setCursor(box_x, cursor_y);
display.print(v / 100);
display.print(v % 100 > 9 ? "." : ".0");
display.print(v % 100);
}
void showPartialUpdate_AVR()
{
uint16_t box_x = 10;
uint16_t box_y = 15;
uint16_t box_w = 70;
uint16_t box_h = 20;
uint16_t cursor_y = box_y + box_h - 6;
uint32_t value = 1395;
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
display.setRotation(0);
// draw background
display.drawExampleBitmap(BitmapExample1, sizeof(BitmapExample1));
delay(2000);
// partial update to full screen to preset for partial update of box window
// (this avoids strange background effects)
display.drawExampleBitmap(BitmapExample1, sizeof(BitmapExample1), GxEPD::bm_flip_x | GxEPD::bm_partial_update);
delay(1000);
// show where the update box is
for (uint16_t r = 0; r < 4; r++)
{
display.setRotation(r);
display.drawPagedToWindow(showBlackBoxCallback, box_x, box_y, box_w, box_h, GxEPD_BLACK);
//display.drawPagedToWindow(showBlackBoxCallback, box_x, box_y, box_w, box_h, GxEPD_BLACK);
delay(1000);
display.drawPagedToWindow(showBlackBoxCallback, box_x, box_y, box_w, box_h, GxEPD_WHITE);
}
// show updates in the update box
for (uint16_t r = 0; r < 4; r++)
{
display.setRotation(r);
for (uint16_t i = 1; i <= 10; i++)
{
uint32_t v = value * i;
display.drawPagedToWindow(showValueBoxCallback, box_x, box_y, box_w, box_h, v);
delay(500);
}
delay(1000);
display.drawPagedToWindow(showBlackBoxCallback, box_x, box_y, box_w, box_h, GxEPD_WHITE);
}
}
I have certain questions regarding the code:
1. Why do we need to define a function like this:
[code]void showBlackBoxCallback(uint32_t v)
{
uint16_t box_x = 10;
uint16_t box_y = 15;
uint16_t box_w = 70;
uint16_t box_h = 20;
display.fillRect(box_x, box_y, box_w, box_h, v);
}
Is it not possible to include this in the loop itslef instead of "showPartialUpdate_AVR();"?
- When I add a standard Adafruit code, like:
display.setCursor(0, 5);
display.fillScreen(GxEPD_BLACK);
display.setTextColor(GxEPD_BLACK);
display.setTextSize(0);
display.println("Hello World!");
I see none of that displayed anywhere on the display. I've not been able to add any custom element since last couple of days. All I need is a few elements like text, shapes and variables (eg, DHT22) to be displayed and update them individually. I need some guidance here.
Thanks.