Project HOMEControl Part 2 The headquarters

The head office uses an ESP 32 Developer Board that supports both WLAN and Blue Tooth. A 1.8-inch TFT display with 128 x 160 pixels, which also has an SD-Card Reader installed, is used for display. Finally, a rotary encoder with a switch is used for input. In the following posts, we will expand this center with a menu and with setup functions. This center can of course also be used as a starting point for other applications where display, input and SD card are needed.

I decided to wire the headquarters firmly and not via a board. This has the advantage of a higher stability and enables the central station to be inserted into a housing later.

The ready-made headquarters then looks like this:

List of components used:

Wiring Plan:


Important change of the port SW of the Rotary-Encoder is now connected to GPIO14 and the connector SW now connected to GPIO15. The change was necessary because GPIO0 and GPIO2 should not be used!

 Attention of the wiring plan is from the display side of the sandwich, that is the pin inscription for the ESP32 is mirrored!

The following is the beginning of the program. The logo will be displayed on the display and the SD-Card Reader will be initialized. It is recognized whether an SD card is inserted in the reader and the result is shown accordingly.

 The program requires two libraries:

The Adafruit GFX Library

and the Adafruit ST7735 Library



#include // Core graphics library
#include // Hardware-specific library
// Integration of Font Libraries
#include < Fonts/FreeSans9pt7b.h > // Font for logo
#include < Fonts/FreeSansBold9pt7b.h > // Font for logo

#include <SPI.h>
#include <SD.h>

// Definition of the Pins used
#define TFT_CS 5 // Chip select line for TFT display
#define TFT_RST 22 // Reset line for TFT
#define TFT_DC 21 // Data/command line for TFT

#define SD_CS 16 // Chip select line for SD card

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

// function to display a text on the display in a certain color
void displayText (char * text, uint16_t color) {
tft.setTextColor (color);
tft.setTextWrap (true); // automatic line wrapping is enabled
tft.print (text);

// function to display a text at any point (x, y)
// the display. The color can be selected
void displayText (uint16_t x, uint16_t y, char * text, uint16_t color) {
tft.setCursor (x, y);
displayText (text, color);

// function to display the logo at the top of the display
void displayLogo () {
// Fill the background
tft.fillRect (0,0, 127, 30, ST7735_YELLOW);
// draw frame
tft.drawRect (1,1, 125, 28, ST7735_BLUE);
// Font for the word HOME bold
tft.setFont (& FreeSansBold9pt7b);
// Position the cursor
tft.setCursor (7, 20);
// Print the text in black
tft.setTextColor (ST7735_BLACK);
tft.print ("HOME");
// Font for the word control not bold
tft.setFont (& FreeSans9pt7b);
// Print the text to red
tft.setTextColor (ST7735_RED);
tft.print ("Control");
// Reset the font to default
tft.setFont (NULL);

void setup () {
Serial.begin (115200);
// initialize tft and black background
tft.fillScreen (ST7735_BLACK);
// Show the logo
displayLogo ();
// Initialize the SD card and display the result
if (!SD.begin (SD_CS)) {
displayText (20, 60, "No SD-Card", ST7735_YELLOW);
} else {
displayText (20, 60, "SD-Card OK", ST7735_GREEN);


void loop () {


DisplaysEsp-32Projects for advancedSmart home


Andreas Wolter

Andreas Wolter

Der Schaltplan wurde ausgetauscht.




vielen Dank für die Anleitung.
Könnt ihr bitte die Grafiken so einstellen, dass die Schrift lesbar ist.
Das wäre sehr hilfreich.
Danke :)



Hallo Herr Lechner,
können Sie bitte den Verdrahtungsplan so darstellen das man die Pinnummern lesen kann,
mein ESP32 hat eine etwas andere Belegung ,deshalb kann ich mich nicht nach den Verbindungslinien
mit freundlichen Grüßen

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN