So I have been dealing with this LCD for weeks now and decided to set the record straight by making a post with absolutely everything to resolve all the problems.
Note that I am not an expert at this, so if anything isn’t clear, feel free to ask!
I have a 3.5" TFT LCD with a shield for an Arduino MEGA 2560 that is 480 x 320. It uses an ILI9486 driver with a parallel interface:
My goal is to display JPGs and GIFs from the built-in SD card reader on it using an ESP32 Wroom32D Devkit C . The connections are as follows:
So my first question is: Should I connect the 3V3 to the 3.3V pin on the ESP32? I am asking this question because I can't find the specifications for this specific LCD. Also, when I first used it on an Arduino, it would get hot on the side where the flex connector is. The TFT-Arduino shield would also connect the pin between the GND and 5V pins to GND.
I am using the TFT_eSPI library. Once I managed to connect it to the ESP32 with the connections I mentioned above, but without the 3.3V, I uploaded the "TFT_Meters" sketch, and it worked fine. It didn't get hot at all, and everything was smooth.
The problem arose when I started uploading JPGs. The code had no errors and uploaded successfully, but the output was the problem. This is what would happen:
The screen would go from a bright white to a much darker white, and not only that, but the serial monitor would display nothing. I checked everything: the port, the board, the baud rate... and nothing seemed to help.
Here is the code:
#include <SPI.h>
#include <FS.h>
#include <SD.h>
#include <TFT_eSPI.h>
#include <JPEGDecoder.h>
TFT_eSPI tft = TFT_eSPI(); // Initialize TFT
void setup() {
Serial.begin(115200);
Serial.println("Starting...");
// Set chip select high to avoid bus contention during initialization
digitalWrite(33, HIGH); // TFT chip select
digitalWrite(5, HIGH); // SD card chip select
tft.begin();
// Initialize the SD card
if (!SD.begin(5)) { // Pass only the CS pin
Serial.println("Card Mount Failed");
return;
}
Serial.println("SD card initialized.");
displayImage("/DispenserScreen_resized.jpg"); // Display the image
}
void loop() {
// Nothing to do in loop
}
void displayImage(const char *filename) {
File jpegFile = SD.open(filename, FILE_READ);
if (!jpegFile) {
Serial.print("ERROR: File "");
Serial.print(filename);
Serial.println("" not found!");
return;
}
Serial.println("===========================");
Serial.print("Drawing file: ");
Serial.println(filename);
Serial.println("===========================");
bool decoded = JpegDec.decodeSdFile(jpegFile); // Decode the image
if (decoded) {
jpegRender(0, 0); // Render the image at (0, 0)
} else {
Serial.println("Jpeg file format not supported!");
}
}
void jpegRender(int xpos, int ypos) {
uint16_t *pImg;
uint16_t mcu_w = JpegDec.MCUWidth;
uint16_t mcu_h = JpegDec.MCUHeight;
tft.setSwapBytes(true);
while (JpegDec.read()) {
pImg = JpegDec.pImage;
int mcu_x = JpegDec.MCUx * mcu_w + xpos;
int mcu_y = JpegDec.MCUy * mcu_h + ypos;
// Directly push the image since dimensions match
tft.pushImage(mcu_x, mcu_y, mcu_w, mcu_h, pImg);
}
tft.setSwapBytes(false);
}
That is all!
If you have any ideas, code, or alternatives, please let me know.
Thanks!