Good afternoon. Help me figure out how the SD card works. There is a Lolin Wemos D1 R1 + PCF8574 + TFT 2.4 (SPI) + SD module. (I tried using the built-in TFT SD module. The result is the same).
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <PCF8574.h>
#include <Wire.h>
#define BLACK 0x0000 // 0, 0, 0
#define NAVY 0x000F // 0, 0, 128
#define DARKGREEN 0x03E0 // 0, 128, 0
#define DARKCYAN 0x03EF // 0, 128, 128
#define MAROON 0x7800 // 128, 0, 0
#define PURPLE 0x780F // 128, 0, 128
#define OLIVE 0x7BE0 // 128, 128, 0
#define LIGHTGREY 0xC618 // 192, 192, 192
#define DARKGREY 0x2945 // 128, 128, 128
#define BLUE 0x001F // 0, 0, 255
#define GREEN 0x07E0 // 0, 255, 0
#define DEEPGREEN 0x0C81 // 0, 255, 0
#define CYAN 0x07FF // 0, 255, 255
#define RED 0xF800 // 255, 0, 0
#define MAGENTA 0xF81F // 255, 0, 255
#define YELLOW 0xFFE0 // 255, 255, 0
#define WHITE 0xFFFF // 255, 255, 255
#define ORANGE 0xFD20 // 255, 165, 0
#define GREENYELLOW 0xAFE5 // 173, 255, 47
#define PINK 0xF81F
#define DEEPBLUE 0x0007
#define GREY 0x4A89
PCF8574 pcf8574(0x25);
#define TFT_CS 10
#define TFT_DC D8
#define TFT_RST D9
extern unsigned char OnOff[];
extern unsigned char WiFiLogo[];
extern unsigned char ClockLogo[];
#define SD_CS_PIN 8;
File myFile;
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
void setup(void)
{
Serial.begin(115200);
tft.init(240, 320, SPI_MODE2);
tft.setRotation(1);
tft.invertDisplay(false);
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(0, 0); tft.setTextSize(2); tft.setTextColor(CYAN);
if ( !pcf8574.begin() )
{
tft.setCursor(50, 60); tft.setTextColor(CYAN);
tft.setTextSize(2); tft.print ("PCF module - OK");
for (int i = 0; i<=7; i++) pcf8574.pinMode(i, OUTPUT);
pcf8574.digitalWrite(P0, HIGH);
pcf8574.digitalWrite(P1, HIGH);
pcf8574.digitalWrite(P2, LOW);
pcf8574.digitalWrite(P3, LOW);
pcf8574.digitalWrite(P4, HIGH);
pcf8574.digitalWrite(P5, HIGH);
pcf8574.digitalWrite(P6, HIGH);
pcf8574.digitalWrite(P7, HIGH);
}
else
{ tft.setCursor(50, 60); tft.setTextColor(RED); tft.setTextSize(2); tft.print("PCF module - Fail"); }
if ( !SD.begin(2) )
{
tft.setCursor(50, 85); tft.setTextColor(RED); tft.setTextSize(2); tft.print("SD-card - Fail");
}
else
{
tft.setCursor(50, 85); tft.setTextColor(CYAN); tft.setTextSize(2); tft.print("SD-card - OK");
}
}
void loop ()
{
}
Free pins on D1R1 from 0 to 6, D11 and D12. In SD.begin (?) instead of ? I've tried them all.
Always a white screen. As soon as I turn off the initialization of the SD module, everything is displayed on the TFT. Please explain why this is happening.
Or, for example, I connect the CS SD module to D6, the TFT is working and the card is not initialized and WEMOS is restarted at intervals of 5-7 seconds. By myself.
P.S. I don't know technical English well, so I use a translator. Who could translate something wrong.