// Include the jpeg decoder library
#include <TJpg_Decoder.h>
// Include SD
#define FS_NO_GLOBALS
#include <FS.h>
#ifdef ESP32
#include "SPIFFS.h" // ESP32 only
#endif
#define SD_CS D2
#define Display1_cs D4
#define Display2_cs D3
// Include the TFT library https://github.com/Bodmer/TFT_eSPI
#include "SPI.h"
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI(); // 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 tft_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 >= tft.height() ) return 0;
// This function will clip the image block rendering automatically at the TFT boundaries
tft.pushImage(x, y, w, h, bitmap);
// This might work instead if you adapt the sketch to use the Adafruit_GFX library
// tft.drawRGBBitmap(x, y, bitmap, w, h);
// Return 1 to decode next block
return 1;
}
void setup()
{
Serial.begin(9600);
Serial.println("\n\n Testing TJpg_Decoder library");
pinMode(Display1_cs, OUTPUT);
digitalWrite(Display1_cs,HIGH);
pinMode(Display2_cs, OUTPUT);
digitalWrite(Display1_cs,HIGH);
// Initialise the TFT
digitalWrite(Display1_cs, LOW);
digitalWrite(Display2_cs, LOW);
tft.begin();
tft.setTextColor(0xFFFF, 0x0000);
tft.fillScreen(TFT_WHITE );
tft.setSwapBytes(true); // We need to swap the colour bytes (endianess)
digitalWrite(Display1_cs, HIGH);
digitalWrite(Display2_cs, HIGH);
// digitalWrite(Display2_cs, LOW);
// tft.begin();
// tft.setTextColor(0xFFFF, 0x0000);
// tft.fillScreen(TFT_WHITE);
// tft.setSwapBytes(true); // We need to swap the colour bytes (endianess)
// digitalWrite(Display2_cs, HIGH);
// The jpeg image can be scaled by a factor of 1, 2, 4, or 8
TJpgDec.setJpgScale(0);
// The decoder must be given the exact name of the rendering function above
TJpgDec.setCallback(tft_output);
digitalWrite(Display1_cs, LOW);
delay(1);
tft.setCursor(25, 30);
tft.setTextColor(TFT_BLACK );
tft.setTextSize(0);
tft.println("Screen Test 1");
digitalWrite(Display1_cs, HIGH);
digitalWrite(Display2_cs, LOW);
tft.setCursor(25, 30);
tft.setTextColor(TFT_BLACK );
tft.setTextSize(0);
tft.println("Screen Test 2");
digitalWrite(Display2_cs, HIGH);
// Initialise SD before TFT
if (!SD.begin(SD_CS)) {
Serial.println(F("SD.begin failed!"));
while (1) delay(0);
}
Serial.println("\r\nInitialisation done.");
digitalWrite(Display1_cs, LOW);
TJpgDec.drawSdJpg(20, 0, "/two.jpg");
digitalWrite(Display1_cs, HIGH);
digitalWrite(Display2_cs, LOW);
TJpgDec.drawSdJpg(20, 0, "/one.jpg");
digitalWrite(Display2_cs, HIGH);
}
void loop()
{
}
Moderator: igrr
Just a thought: have you tried adding a small delay between CS pin switching?
digitalWrite(Display1_cs, LOW);
// Let the TFT code do its thing here for display 1
digitalWrite(Display1_cs, HIGH);
delay(10); // or whatever value
digitalWrite(Display2_cs, LOW);
// Let the TFT code do its thing here for display 1
digitalWrite(Display2_cs, HIGH);
delay(10); // or whatever value
// Rinse and repeat
Or maybe it's a glitch in the CS lines which you can solve by adding a small pull to HIGH?