2 st7735 screens, 1 sd card adapter and a esp32 #2236
Unanswered
jerecraft54
asked this question in
Q&A - General
Replies: 1 comment 1 reply
-
The problem is that one TFT chip select is low when drawSdJpeg is called:
This means there is a conflict when the SD card is read. You need to set the TFT chip selects both high before calling drawSdJpeg. Within the jpegRender functions set the correct TFT chip select low and then high immedately before and after tft.pushImage: Viz:
Notice the extra curly braces! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
First,sorry for my english ( i'm french)
my issue is that i want display pictures on 2 screens (ST7735) in using a sd card adapter.
i use 2 CS for each screen (21 and 22) and one for the SD Adapter (5)
i use tft-espi and JPEGDecoder library
in user-setup.h (tft-espi library) , i uncommended pin for esp 32 (pin 19,23,18,15,2 and 4)
but for the THT-CS , i don't use pin 15 but 2 pins 21 and 22 call THT_CS1 and THT_CS2.
i can display text on each screens witout issues but when i want to display a picture, i show my picture but lot of pixel are white.
I think, it's a issue when i use the CS of sd adapter with the CS of one screen.
I have made a test in unpluging pin 21 (tht1) and plug in pin 15 ( normaly the tft-cs define in the user-setup) and i have a good picture.
my program is
#include <SPI.h>
#include <FS.h>
#include <SD.h>
#include <TFT_eSPI.h>
#include <JPEGDecoder.h>
#define TFT_CS1 21 // CS THT1
#define TFT_CS2 22 // CS THT2
#define SD_CS 5 // CS SD
TFT_eSPI tft = TFT_eSPI();
void setup() {
pinMode(TFT_CS1,OUTPUT);
pinMode(TFT_CS2,OUTPUT);
pinMode(SD_CS,OUTPUT);
Serial.begin(115200);
digitalWrite(TFT_CS1, HIGH); // CS1
digitalWrite(TFT_CS2, HIGH); // CS2
digitalWrite( SD_CS, HIGH);
digitalWrite(TFT_CS1, LOW); // CS1
digitalWrite(TFT_CS2, LOW); // CS2
tft.init();
digitalWrite(TFT_CS1, HIGH); // CS1
digitalWrite(TFT_CS2, HIGH); // CS2
SD.begin();
}
//####################################################################################################
// Main loop
//####################################################################################################
void loop() {
digitalWrite(TFT_CS2, LOW);
digitalWrite(TFT_CS1, HIGH);
tft.setRotation(3); //
tft.fillScreen(TFT_WHITE);
tft.setTextColor(TFT_RED);
tft.setTextSize(2);
tft.drawString("Red Griffin ",0,40);
delay (2000);
digitalWrite(TFT_CS2, HIGH);
delay(100);
digitalWrite(TFT_CS1, LOW);
digitalWrite(TFT_CS2, HIGH);//
tft.setRotation(2); //
tft.fillScreen(TFT_BLACK);
tft.setRotation(2);
drawSdJpeg("/scania.jpg", 0, 0);
delay(2000);
digitalWrite(TFT_CS1, HIGH); //
delay(100);
digitalWrite(TFT_CS2, LOW);
digitalWrite(TFT_CS1, HIGH);//
tft.setRotation(2); //
tft.fillScreen(TFT_BLACK);
tft.setRotation(2);
drawSdJpeg("/Mouse480.jpg", 0, 0);
delay(2000);
digitalWrite(TFT_CS2, HIGH); //
delay(100);
}
//####################################################################################################
// Draw a JPEG on the TFT pulled from SD Card
//####################################################################################################
// xpos, ypos is top left corner of plotted image
void drawSdJpeg(const char *filename, int xpos, int ypos) {
// Open the named file (the Jpeg decoder library will close it)
File jpegFile = SD.open( filename, FILE_READ); // or, file handle reference for SD library
// Use one of the following methods to initialise the decoder:
bool decoded = JpegDec.decodeSdFile(jpegFile); // Pass the SD file handle to the decoder,
//bool decoded = JpegDec.decodeSdFile(filename); // or pass the filename (String or character array)
if (decoded) {
// print information about the image to the serial port
// jpegInfo();
// render the image onto the screen at given coordinates
jpegRender(xpos, ypos);
}
}
//####################################################################################################
// Draw a JPEG on the TFT, images will be cropped on the right/bottom sides if they do not fit
//####################################################################################################
// This function assumes xpos,ypos is a valid screen coordinate. For convenience images that do not
// fit totally on the screen are cropped to the nearest MCU size and may leave right/bottom borders.
void jpegRender(int xpos, int ypos) {
uint16_t *pImg;
uint16_t mcu_w = JpegDec.MCUWidth;
uint16_t mcu_h = JpegDec.MCUHeight;
uint32_t max_x = JpegDec.width;
uint32_t max_y = JpegDec.height;
bool swapBytes = tft.getSwapBytes();
tft.setSwapBytes(true);
uint32_t min_w = jpg_min(mcu_w, max_x % mcu_w);
uint32_t min_h = jpg_min(mcu_h, max_y % mcu_h);
// save the current image block size
uint32_t win_w = mcu_w;
uint32_t win_h = mcu_h;
// record the current time so we can measure how long it takes to draw an image
uint32_t drawTime = millis();
// save the coordinate of the right and bottom edges to assist image cropping
// to the screen size
max_x += xpos;
max_y += ypos;
// Fetch data from the file, decode and display
while (JpegDec.read()) { // While there is more data in the file
pImg = JpegDec.pImage ; // Decode a MCU (Minimum Coding Unit, typically a 8x8 or 16x16 pixel block)
}
tft.setSwapBytes(swapBytes);
//showTime(millis() - drawTime); // These lines are for sketch testing only
}
Can you help me?
Thank you
Beta Was this translation helpful? Give feedback.
All reactions