Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By keaster
#92669 I'm trying to use multiple ST7735 tft displays on my ESP8266, using the TFT_eSPI library with TJpg_Decoder to display an image on the display from a SD Card, if I use 1 display with the hardware CS pin, all good no problems, when I use multi displays and designate other IO pins as the CS pin I get missing blocks in my image, but text is ok.

Code: Select all// 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()
{
}
You do not have the required permissions to view the files attached to this post.
User avatar
By picstart
#92702 Both LCDs will react to the same CS signal if they share the line...they will interact with each other.... use a different pin for each same goes with the SD card it with have CS issues if it shares the pin.
User avatar
By keaster
#92705 They all have there own CS pin, I can control each screen, If I use only 1 screen using the hardware CS pin all good, its only when I use a different I/O I get missing blocks on the image
User avatar
By QuickFix
#92712 I couldn't think of a reason when I first read your question last week (other than the small error in setting Display1_cs to HIGH in startup() for a second time instead of Display2_cs), but perhaps the switching (of the CS lines) between display 1 and 2 goes too fast for the displays?

Just a thought: have you tried adding a small delay between CS pin switching?
Code: Select all  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?