-
Notifications
You must be signed in to change notification settings - Fork 49
Description
I have a XIAO ESP32-S3 with a 7.5" ePaper display (it's the Seeed Studio TRMNL DIY kit). I'm trying to get it to download a Jpeg from a locally hosted server and then render it to the display. (The jpeg is already the right size and in grayscale).
The Jpeg renders, but it's very distorted. You can tell it's the same image, but it's unusable. Can't tell whether it's a decoding problem or rendering problem. If I take the image and run it through image2cpp then render the image directly from a header file then it works perfectly.
Any ideas or suggestions on how to debug this, please?
Main sketch:
#define WIFI_SSID "XXX"
#define PASSWORD "YYY"
// Include the jpeg decoder library
#include <TJpg_Decoder.h>
#include "image.h"
// Include LittleFS
#include <FS.h>
#include "LittleFS.h"
#define FORMAT_LITTLEFS_IF_FAILED true
// Include WiFi and http client
#include <WiFi.h>
#include <HTTPClient.h>
// Load tabs attached to this sketch
#include "ListLittleFS.h"
#include "WebFetch.h"
// Include the TFT library https://github.com/Bodmer/TFT_eSPI
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
#define DASHBOARD_FILENAME "/dashboard.jpeg"
EPaper epaper = EPaper(); // Invoke custom library
// This next function will be called during decoding of the jpeg file to
// render each block to the TFT. If you use a different TFT library
// you will need to adapt this function to suit.
bool epaper_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap)
{
// Stop further decoding as image is running off bottom of screen
if ( y >= epaper.height() ) return 0;
// This function will clip the image block rendering automatically at the TFT boundaries
epaper.pushImage(x, y, w, h, bitmap);
// Return 1 to decode next block
return 1;
}
void setup()
{
Serial.begin(115200);
// Initialise LittleFS
if (!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED)) {
Serial.println("LittleFS initialisation failed!");
Serial.println("An Error has occurred while mounting LittleFS");
while (1) yield(); // Stay here twiddling thumbs waiting
}
Serial.println("\r\nInitialisation done.");
// Initialise the TFT
epaper.begin();
epaper.fillScreen(TFT_WHITE);
epaper.update();
// The jpeg image can be scaled by a factor of 1, 2, 4, or 8
TJpgDec.setJpgScale(1);
// The byte order can be swapped (set true for TFT_eSPI)
TJpgDec.setSwapBytes(true);
// The decoder must be given the exact name of the rendering function above
TJpgDec.setCallback(epaper_output);
WiFi.begin(WIFI_SSID, PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println();
Serial.println("Started Wifi connection and opened ePaper...");
// This is for demoe purposes only so that file is fetched each time this is run
if (LittleFS.exists(DASHBOARD_FILENAME) == true) {
Serial.println("For test only, removing file");
LittleFS.remove(DASHBOARD_FILENAME);
}
}
void loop()
{
// Time recorded for test purposes
uint32_t t = millis();
// Fetch the jpg file from the specified URL, examples only, from imgur
bool loaded_ok = getFile("http://XYZ", DASHBOARD_FILENAME); // Note name preceded with "/"
t = millis() - t;
if (loaded_ok) { Serial.print(t); Serial.println(" ms to download"); }
// List files stored in LittleFS, should have the file now
listLittleFS();
t = millis();
// Now draw the LittleFS file
TJpgDec.drawFsJpg(0, 0, DASHBOARD_FILENAME, LittleFS);
//epaper.pushImage(0, 0, 800, 480, (uint16_t *)epd_bitmap_cat); <-- This works perfectly!
epaper.update();
t = millis() - t;
Serial.print(t); Serial.println(" ms to draw to ePaper");
// Wait forever
while(1) yield();
}
`
<driver.h>
#define BOARD_SCREEN_COMBO 502 // 7.5 inch monochrome ePaper Screen (UC8179) #define USE_XIAO_EPAPER_DISPLAY_BOARD_EE04
Just to add some further detail...
Have tried setSwapBytes true and false.
It's not a progressively encoded Jpeg.


