SD.begin() will block TFT on ST7735 with ESP32

I am running the ESP32 with an ST7735 (1.8" TFT with SD card reader)
The TFT works fine on its own.
The SD card works fine. (read and write)
The TFT is blocked - processing no more commands - after the first SD.begin().
This is independent from the SD hardware being connected or not!!
(disconnected MOSI/ MISO/ CS/ SCLK from ST7735 board)
Ideas?

Stipped down code:

//#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <SD.h>
//#include "FS.h"

/*
   display settings
*/
#define TFT_CS         5
#define TFT_RST        16
#define TFT_DC         17

#define SD_CS          4

#define TFT_MOSI      23
#define TFT_SCLK      18

// For ST7735-based displays, we will use this call
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);


void setup(void) {
  Serial.begin(9600);
  tft.initR(INITR_BLACKTAB);

  tft.setRotation(1);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(0, 50);
  tft.setTextSize( 3);
  tft.print("begin");
  delay(2000);

  Serial.print("Initializing SD card...");
  tft.fillScreen(ST77XX_RED);
  tft.setCursor(0, 50);
  tft.print("bef. SD");

  if (!SD.begin(SD_CS)) {
    Serial.println(SD_CS);
    Serial.println("failed!");
  }
  tft.fillScreen(ST77XX_GREEN);
  tft.setCursor(0, 50);
  tft.print("after SD");
  Serial.println("DONE");
}

void loop(void) {
  Serial.print(".");
  delay(5000);
}

You are using the bit-bashed driver. Change to HW SPI

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

Then TFT and SD can both live on the same SPI bus.
I suggest that you always configure SPI Transactions

Untested recently. But TFT and SD always used to work

David.

Hi David,

thanks a lot für your hint!
I am making progress now.
It seems that both the TFT and the SD card can both work at the same time.
I am running into another issue plotting a bmp file onto the screen. This actually stops the program...
I'll have to run further investigations.
But - most importantly - the TFT is still alive after SD card actions - and all of those work properly!!

I'll close this topic as soon as I found out the little hurdles (tomorrow).
Cheers
Matthias

Plotting a BMP is simple but uses a lot of Flash or SD card.
Your ESP32 can render JPEG images. And because JPEGs are small, you can store several images in Flash memory or SPIFFS. No need for an external SD card.

Have you looked at TFT_eSPI library ?

David.

Hi David,

Have you looked at TFT_eSPI library ?

In fact I did but did not get the display running.
Might be a question of the settings in the User_Setup.
If you have a chance - can you please have a look at my settings?
And finally:

You are using the bit-bashed driver. Change to HW SPI

Can you elaborate on this - or give a link to more information?

Thanks in advance!
Matthias

User_Setup.h (13.7 KB)

Your User_Setup looks fine to me. Although I suspect you actually have ST7735_BLACKTAB
Especially since you have verified the wiring with the full-fat Adafruit constructor.

A sensible strategy with any new hardware:

  1. test with full Software constructor e.g. Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST)
  2. test with Hardware constructor i.e. Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST)
  3. configure User_Setup for the Hardware wiring verified in (2)
  4. test TFT_eSPI examples.
  5. never trust Adafruit constructors that omit TFT_RST

(1) should work on any board with any (digital) pins. It only uses pinMode() and digitalWrite()
(2) only works when you have wired to the hardware MOSI and SCK pins

Regarding (1). SD will never work because the TFT library has "bit-bashed" the SPI pins.
Which is why you always want to get (2) verified as soon as possible.

David.

Hi David,

I cannot get the TFT_eSPI running.
I'll have to try different setups.
For now I'll continue using the Adafruit even though the TFT_eSPI seems to be more advanced.

Due to your extended help I will be able to continue with my project.
Thanks again.

Last not least:
Trying things out on an Arduino always takes a lot of time. Most of the time is spent waiting for the IDE to compile. The CPU load and memory consumption of the IDE is really low - nonetheless it takes too much time for an iteration development step. If you got - yet another - hint to tune the IDE on Windows 10??

All the best
Matthias

Personally, I use this User_Setup:

#define TFT_CS   5  // Chip select control pin D8
#define TFT_DC   13  // Data Command control pin
#define TFT_RST  12  // Reset pin (could connect to NodeMCU RST, see next line)
//#define TFT_RST  -1    // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V
#define TOUCH_CS 25  // Chip select pin (T_CS) of touch screen

with MOSI, MISO, SCK on 23, 19, 18

which means that I can use Adafruit_ST7735 with SW or HW constructor for TFT-only programs.
or the HW constructor with TFT + SD programs.

I use the same wiring for every target e.g. Uno, Zero, Due, Teensy, ESP8266, ESP32, ...

The first step is always to get one single SPI device working e.g. TFT.
When that is verified, you can add SD and XPT2046 to the SPI bus.

David.