Hi,
i´m starting with a new picture frame with a spectra 6 color display with a resolution of 1200x1600. The Display is slow, but the colors a not bad at all.
I like to update every hour or so. the data will come from a webserver.
if i take a picture with 850x1100 the variable "elementCount" in the function "void downloadImageData() {" returns the right value of 481526. If i take a bigger picture then it return is 1, so it seems that there is a limitation in the maximum string sitze. I didn´t found anything for the limitation. pictures with the full resolution of 1200x1600 will have 960000 values.
i´m using a Seed Xiao ESP32S3 with 8MB of PSRAM. the plan was:
get the string via http.getstring > count for ´,´ > alocate memory for the array in psram > fill the array with the hex values > send data to display framebuffer.
any idea?
the pictures are stored directly as array on the webserver:
// 6 Color Image Data 850*1133
const unsigned char Image6color[481525] = {
0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
// Image byte data is stored in PSRAM, so need to enable PSRAM.
#include "EPD_13in3e.h"
#include <WiFi.h>
#include <HTTPClient.h>
#define S_To_uS_Factor 1000000ULL //Conversion factor for micro seconds to seconds
const char* ssid = "xxx"; // Your WiFi SSID
const char* password = "xxxx"; // Your WiFi Password
const char* getImageUrl = "http://192.168.2.12/demo_image.h";
int schlafen = 3600;
void setup() {
Serial.begin(115200);
connectWiFi();
mainTask();
}
void loop() {
delay(60000);
}
void connectWiFi() {
int retryCount = 0;
WiFi.mode(WIFI_STA); // Set WiFi to station mode
WiFi.begin(ssid, password);
// Attempt to connect for a set number of retries
while (WiFi.status() != WL_CONNECTED && retryCount < 10) {
delay(1000);
Serial.println("Connecting to WiFi...");
retryCount++;
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println("Connected to WiFi!");
} else {
Serial.println("Failed to connect to WiFi after 10 attempts, stopping WiFi.");
hibernate(3600);
}
}
void mainTask() {
if (WiFi.status() == WL_CONNECTED) {
// Start downloading the image data
downloadImageData();
// Fetch the wakeup interval and go into deep sleep
// hibernate(schlafen);
} else {
// hibernate(3600); // Go to sleep for 1 hour if no WiFi connection
}
}
void downloadImageData() {
HTTPClient http;
if (!http.begin(getImageUrl)) {
Serial.println("Failed to initialize HTTP connection");
return;
}
Serial.println("httpget");
// Make the request
int httpResponseCode = http.GET();
if (httpResponseCode > 0 && httpResponseCode == HTTP_CODE_OK) {
Serial.println("string payload");
String payload = http.getString();
// Count the number of elements based on commas in the payload
long elementCount = 1;
for (long i = 0; i < payload.length(); i++) {
if (payload[i] == ',') elementCount++;
}
Serial.println(elementCount);
// Allocate memory for the uint8_t array
uint8_t* dataBuffer = (uint8_t*)ps_malloc(elementCount);
if (dataBuffer == nullptr) {
Serial.println("Failed to allocate memory in PSRAM");
return;
}
// Parse the payload string and fill the array
long index = 0;
long startPos = 0;
for (long i = 0; i < payload.length(); i++) {
if (payload[i] == ',' || i == payload.length() - 1) {
// Get the substring for the current hex value
String hexValue = payload.substring(startPos, i);
hexValue.trim(); // Trim whitespace around the hex string
// Convert hex string to uint8_t and store it in the array
dataBuffer[index++] = (uint8_t)strtol(hexValue.c_str(), nullptr, 16);
// Update start position for the next hex value
startPos = i + 1;
}
}
DEV_Module_Init();
EPD_13IN3E_Init();
// EPD_13IN3E_Clear(EPD_13IN3E_WHITE);
delay(5000);
Serial.println("print picture");
// EPD_13IN3E_DisplayPart((const uint8_t*)dataBuffer, 175, 234, 850,1133);
Serial.println("epd sleep");
EPD_13IN3E_Sleep();
Serial.println("epd power down");
DEV_Module_Exit();
free(dataBuffer); // Free the allocated memory if no longer needed
dataBuffer = nullptr;
} else {
Serial.printf("HTTP GET request failed, error: %s\n", http.errorToString(httpResponseCode).c_str());
}
http.end(); // Close connection
}
void hibernate(int interval) {
WiFi.disconnect(true); // Disconnect from any connection attempt
WiFi.mode(WIFI_OFF); // Turn off the WiFi
delay(1000);
esp_sleep_enable_timer_wakeup(interval * S_To_uS_Factor); // Convert to microseconds
esp_deep_sleep_start();
}

