I have an esp32 and 2 round TFT displays. They should show the current hour. I read about them and to use multiple displays, you have to wire them in row and connect a CS pin to them. If CS is high → Display can't be written, CS Low → Display can be written. My code just works fine, I even hooked up the cs cable to an LED and it works as intended. But if I hock up the cables to the displays, both displays are updating, showing first the 1. digit of h(1-2) and after that both displays update to the second digit of the hour(0-9)
#include <gpio_viewer.h>
#include <WiFi.h>
#include "time.h"
#include <FS.h>
#include <SPI.h>
#include <TFT_eSPI.h>
#include <Dictionary.h>
#define AA_FONT_SMALL "NotoSansBold15"
#define AA_FONT_LARGE "NotoSansBold36"
//WIFI Keys
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 0;
const int daylightOffset_sec = 3600;
TFT_eSPI tft = TFT_eSPI();
GPIOViewer gpio_viewer;
Dictionary<int, String> screenContent;
int current_display_updating = 1;
int num_displays = 2;
int cs_pins[2] = {15, 27};
void setup() {
for (int i = 0; i < num_displays; i++) {
screenContent.set(i + 1, "-1");
pinMode(cs_pins[i], OUTPUT);
digitalWrite(cs_pins[i], HIGH); // Initialize all CS pins to HIGH
}
pinMode(25, OUTPUT);
Serial.begin(115200);
// Connect to Wi-Fi
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
WiFi.mode(WIFI_MODE_STA);
gpio_viewer.begin();
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
tft.begin();
tft.setRotation(0);
if (!SPIFFS.begin()) {
Serial.println("SPIFFS initialisation failed!");
while (1) yield();
}
Serial.println("\r\nSPIFFS available!");
// ESP32 will crash if any of the fonts are missing
bool font_missing = false;
if (!SPIFFS.exists("/NotoSansBold15.vlw")) font_missing = true;
if (!SPIFFS.exists("/NotoSansBold36.vlw")) font_missing = true;
if (font_missing) {
Serial.println("\r\nFont missing in SPIFFS, did you upload it?");
while (1) yield();
} else {
Serial.println("\r\nFonts found OK.");
}
tft.fillScreen(TFT_YELLOW);
tft.setTextColor(TFT_BLUE, TFT_YELLOW);
tft.loadFont(AA_FONT_LARGE);
tft.setCursor(100, 100);
tft.println("TEST");
}
void loop() {
digitalWrite(cs_pins[current_display_updating - 1], LOW);
//Serial.println(current_display_updating);
delay(5000);
tft.startWrite();
String currentHour = getCurrentTime("%H");
String displayContent[2] = {currentHour.substring(0, 1), currentHour.substring(1, 2)};
tft.fillScreen(TFT_YELLOW);
tft.setTextColor(TFT_BLUE, TFT_YELLOW);
tft.setCursor(100, 100);
tft.loadFont(AA_FONT_LARGE);
tft.println(displayContent[current_display_updating - 1]);
screenContent.set(current_display_updating, displayContent[current_display_updating - 1]);
tft.endWrite();
delay(1000);
digitalWrite(cs_pins[current_display_updating - 1], HIGH);
current_display_updating++;
if (current_display_updating > num_displays) {
current_display_updating = 1;
}
}
String getCurrentTime(const char* format) {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
return "Failed to obtain time";
}
char buffer[80];
strftime(buffer, sizeof(buffer), format, &timeinfo);
return String(buffer);
}
Display Esp32
VCC 3V
GND GND
SCC 18
SDA 23
DC 2
CS 15,27
RST 4
I just can't figure out what the problem might be.