Introduction
After a long break I try again on an e-paper project with ESP8266, Arduino and the GxEPD2. Last time the project failed because of the energy hunger of my solution. Currently I try to write a bitmap provided by my server in parts to the display. To avoid a long activity of the WiFi module, the image should reach the display without writing page by page. This process took more than 20 seconds in the past.
Vision/Problem
The basic idea of the new solution is relatively simple: from the TCP stream of the server, one line of the image should always be buffered and then written to the display. Afterwards the image is displayed. However, my understanding of the GxEPD2 does not seem to be sufficient. The display flickers and then is only white to see.
Beyond my current code, I have no ideas to address the problem. Any tips on a possible solution would really help me.
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <GxEPD2_BW.h>
#include "ops.h"
#include "wifi.h"
// GDEW075T7 800x480 GxEPD 2 Implementation
GxEPD2_BW<GxEPD2_750_T7, GxEPD2_750_T7::HEIGHT> display(
GxEPD2_750_T7(/*CS=D8*/ 5, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 15));
static char ssid[] = "*";
static char psk[] = "*";
static IPAddress host(192, 168, 137, 1);
static uint16_t port = 4200;
void setup() {
Serial.begin(115200);
delay(10);
Serial.printf("\nConnecting to ssid: %s, psk: %s\n", ssid, psk);
WiFi.begin(ssid, psk);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.printf("Status %i\n", WiFi.status());
}
Serial.println("Connection established!");
}
void loop() {
WiFiClient wc;
if (!wc.connect(host, port)) {
Serial.println("Failed to connect");
delay(60000);
ESP.restart();
}
FetchRequest req{};
FetchResponse res{
.error = 0xff,
};
if (!fetch(wc, req, res)) {
Serial.println("Failed to fetch");
delay(60000);
ESP.restart();
}
display.init();
display.setRotation(res.rotation);
for (int16_t y = 0; y < display.height(); y++) {
if (!wc.available()) {
Serial.println("Connection closed prematurely");
delay(60000);
ESP.restart();
}
uint16_t w = display.width();
uint8_t line[w / 8];
wc.readBytes(line, sizeof(line));
display.drawImagePart(line, 0, y, // x_part, y_part: position in the part
w, 1, // w_bitmap, h_bitmap: size of the part
0, y, // x, y: position on the display
w, 1); // w, h: size on the display
}
display.display();
delay(60000);
ESP.restart();
}