Skip to content

ILI9341 & ESP32 - Unable to open JPEGs from SD Card - File Not Found #87

@cmcooper1971

Description

@cmcooper1971

I'm using an ESP32, ILI9341, which I can control with fill back grounds, draw lines etc. I can read text files and display them from the SD card using Serial.print, but no matter what I try for JPEGs, it says "Jpeg file not found"

I reverted back to the Arduino 1.8 IDE, removed all the libraries and reinstalled. This has made no difference.

These are my includes:

// Includes

#include "globalConfig.h"
#include "tft_Control.h"

#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>

#include <SD.h>

#include <Adafruit_ILI9341.h>
#include <Adafruit_ST7735.h>
#include <Adafruit_GFX.h>

#include <JPEGDecoder.h>

#include <Adafruit_MCP23X08.h>

My TFT declaration:

// Class Declarations and Definitions

Adafruit_ILI9341 TFT1 = Adafruit_ILI9341(TFT1_CS_DUMMY, TFT1_DC, TFT1_RST);

Within the setup, I initialise the displays, set various background colours, all in sequence, then I call the function to draw the JPEG as follows:

	/*-------------------------------------------*/

	listDir(SD, "/", 0);

	readFile(SD, "/test.txt");

	// Enable A-BUS Screen 5

	enable_Tft_5_ABus();
	drawJpeg("/house.jpg", 0, 0);

	// Disable screen chip select

	disableAllTftAllBus();

	/*-------------------------------------------*/

As you can see, I perform a little test to ensure the SD card is addressable and working, which it is.

Here is the drawJpeg function:

void drawJpeg(const char* filename, int xpos, int ypos) {

	Serial.println("===========================");
	Serial.print("Drawing file: "); Serial.println(filename);
	Serial.println("===========================");

	// Open the named file (the Jpeg decoder library will close it after rendering image)
	// fs::File jpegFile = SPIFFS.open(filename, "r");    // File handle reference for SPIFFS
	File jpegFile = SD.open(filename);  // or, file handle reference for SD library

	if (!jpegFile) {
		Serial.print("ERROR: File \""); Serial.print(filename); Serial.println("\" not found!");
		return;
	}

	// Use one of the three following methods to initialise the decoder:
	//boolean decoded = JpegDec.decodeFsFile(jpegFile); // Pass a SPIFFS file handle to the decoder,
	boolean decoded = JpegDec.decodeSdFile(jpegFile); // or pass the SD file handle to the decoder,
	//boolean decoded = JpegDec.decodeFsFile(filename);  // or pass the filename (leading / distinguishes SPIFFS files)
	// Note: the filename can be a String or character array type
	if (decoded) {
		// print information about the image to the serial port
		jpegInfo();

		// render the image onto the screen at given coordinates
		jpegRender(xpos, ypos);
	}
	else {
		Serial.println("Jpeg file format not supported!");
	}
}

It fails to open the listed file and I do not understand why? I have used FILE_READ as well as it is currently. The SD card works and therefore all GPIOs are correct. All TFTs are operational as I can control them independently, currently 10 displays, increasing to 25 assuming I can solve this issue.

To get the following line working:

boolean decoded = JpegDec.decodeSdFile(jpegFile);

I had to edit the JPEGDecoder.h file as follows:

  #ifdef ESP32  // SDFAT library not compatible with ESP32
    #define LOAD_SD_LIBRARY
    //#undef LOAD_SDFAT_LIBRARY
  #endif

All I can say is... HELP!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions