The next challenge for these little powerhouses was to be able to use Bodmer’s brilliant TFT_eSPI library to see what the graphics capabilities might be. Just recently the libraries have been updated to include the S2 chipsets, and they appear to work very well.
In fact the only reason for writing this post is to alert anyone interested about the possibilities and to note that the chip backlight can be handled differently. (See ESP32 S2 with ST7789 – Screen) . With the TFT_eSPI library this can be defined in the User_Setup.h file. In other words, with this driver, pin 33 doesn’t need to be set high in the code.
As always, the TFT_eSPI library requires setting up the User_Setup.h for each hardware application. I’d recommend using the included User_Setup_Select.h method and just comment / uncomment whichever board you are compiling for.
These settings worked well with the Lilygo T8 illustrated. (They are similar to the library’s Setup71 for the S2 board.)
// ../libraries/TFT_eSPI/User_Setup.h // USER DEFINED SETTINGS // Set driver type, fonts to be loaded, pins used and SPI control method etc #define ST7789_DRIVER // Full configuration option #define TFT_WIDTH 135 #define TFT_HEIGHT 240 #define TFT_CS 34 // Chip #define TFT_DC 37 // Data Command #define TFT_RST 38 // Set TFT_RST #define TFT_BL 33 // LED backlight #define TFT_MOSI 35 #define TFT_SCLK 36 #define LOAD_GLCD // Font 1. #define LOAD_FONT2 // Font 2. Small 16 pixel high font, #define LOAD_FONT4 // Font 4. Medium 26 pixel high font, #define LOAD_FONT6 // Font 6. Large 48 pixel font, #define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, #define LOAD_FONT8 // Font 8. Large 75 pixel font //#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, #define LOAD_GFXFF // FreeFonts. #define SMOOTH_FONT #define SPI_FREQUENCY 27000000 #define SPI_READ_FREQUENCY 20000000 #define SPI_TOUCH_FREQUENCY 2500000 #define USE_HSPI_PORT // Needed to coexist with SD card but issues with this board !!
After placing a couple of suitable sized jpgs into the sketch “data” folder, upload the data folder to SPIFFS. The image above is a slightly modified version of the Library example
“TJPG_Decoder > SPIFFS > SPIFFS_Jpg”.
Sadly I have had issues with the TFTeSPI library co-exiting with the SD card on these S2 chips.Problem raisedd with Bodmer.
In the meantime, the LittleFS filesystem (new approach to SPIFFS) works really well with the library as above.
#include <TJpg_Decoder.h>
#include "LittleFS.h" // LittleFS is declared
#include "SPI.h"
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI();
uint32_t loopTime = millis();
String imagefile;
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap)
{
if ( y >= tft.height() ) return 0;
tft.pushImage(x, y, w, h, bitmap);
return 1;
}
void setup() {
Serial.begin(115200);
Serial.println("Loading");
if (!LittleFS.begin()) {
Serial.println("LittleFS initialisation failed!");
while (1) yield(); // Stay here twiddling thumbs waiting
}
tft.begin();
tft.setSwapBytes(true); // We need to swap the colour bytes (endianess)
TJpgDec.setJpgScale(1);
TJpgDec.setCallback(tft_output);
tft.setRotation(0);
}
void loop() {
File root = LittleFS.open("/");
File file = root.openNextFile();
while (file) {
if (millis() >= loopTime + 5000) {
Serial.print("[FILE] ");
Serial.println(file.name());
imagefile = "/" + String(file.name());
tft.fillScreen(TFT_BLACK);
TJpgDec.drawFsJpg(0, 0, imagefile, LittleFS);
loopTime = millis();
file = root.openNextFile();
}
}
}
Remember to upload some 135x240px JPGs to the LittleFS filesystem. (A good enhancement to this would be to add a wifi module and Aysnchwebserver.h. Create a form to upload files….)