// This sketch if for an ESP32, it draws Jpeg images pulled from an SD Card
// onto the TFT.
// As well as the TFT_eSPI library you will need the JPEG Decoder library.
// A copy can be downloaded here, it is based on the library by Makoto Kurauchi.
// https://github.com/Bodmer/JPEGDecoder
// Images on SD Card must be put in the root folder (top level) to be found
// Use the SD library examples to verify your SD Card interface works!
// The example images used to test this sketch can be found in the library
// JPEGDecoder/extras folder
//----------------------------------------------------------------------------------------------------
#include <SPI.h>
#include <FS.h>
#include <SD.h>
#include <TFT_eSPI.h>
// JPEG decoder library
#include <JPEGDecoder.h>
//#define TFT_DC 21 //already defined User_setup.h
//#define TFT_CS 22
//#define TFT_MOSI 23
//#define TFT_SCLK 18
//#define TFT_MISO 19
//#define ILI9341_DRIVER
#define sd_cs 32
TFT_eSPI tft = TFT_eSPI();
//####################################################################################################
// Setup
//####################################################################################################
void setup() {
Serial.begin(115200);
// Set all chip selects high to avoid bus contention during initialisation of each peripheral
//digitalWrite(22, HIGH); // Touch controller chip select (if used)
digitalWrite(22, HIGH); // TFT screen chip select
digitalWrite(sd_cs, HIGH); // SD card chips select, must use GPIO 5 (ESP32 SS)
tft.begin();
tft.setRotation(1);
tft.fillScreen(TFT_WHITE);
}
//####################################################################################################
// Main loop
//####################################################################################################
void loop() {
tft.setRotation(2); // portrait
tft.fillScreen(random(0xFFFF));
// The image is 300 x 300 pixels so we do some sums to position image in the middle of the screen!
// Doing this by reading the image width and height from the jpeg info is left as an exercise!
int x = (tft.width() - 300) / 2 - 1;
int y = (tft.height() - 300) / 2 - 1;
delay(2000);
while(1); // Wait here
}