Basic Firmware Example

Jump-Start Your T-Display Firmware Projects

The T-Display board comes with a built-in TFT display and two built-in push buttons. Here is a simple platformio.project that illustrates how to work with the two push buttons, and how to display text on the TFT display.

Overview

The simple firmware created here will do this:

  • Button Press:
    When you press one of the two buttons, the display the button you pressed. When you press both buttons simultaneously, “Both buttons” is shown on the display.
  • TFT Display:
    The project illustrates how you write text to the display using the eTFT library. The methods in this library allow you to draw geometric shapes and more, so once it is up and running, you can easily extend the sample project.

To start, create a new project in platform.io.

platformio.ini

The first customization happens inside the platformio.ini file: open it in VSCode, and replace its content with this:

[env:lilygo-t-display]
platform = espressif32
board = lilygo-t-display
framework = arduino
lib_deps = 
  bodmer/TFT_eSPI@^2.5.43

Save the file. Platformio automatically installs the dependencies, i.e. the referenced eTFT library.

main.cpp

Your source code goes into the file src/main.cpp. Replace its content with this:

#include <Arduino.h>
#include <SPI.h>
#include <TFT_eSPI.h>

const int BTN1_PIN = 0;
const int BTN2_PIN = 35;

const int TEXT_X = 10;
const int TEXT_Y = 40;

String lastText = "";

/*
nmake sure you adjusted user_Setup.h in the eTFT library to match 
your display. 

Uncomment the line:
// #include <User_Setups/Setup25_TTGO_T_Display.h>
and comment out any other display type setup 
*/

TFT_eSPI tft = TFT_eSPI();  

bool initial = 1;

void drawStateText(const String &s) {
  // Option 1: clear the whole line area before drawing
  tft.fillRect(0, TEXT_Y, tft.width(), 20, TFT_BLACK);  // simple "clear line" [web:22][web:30]
  tft.setCursor(TEXT_X, TEXT_Y);
  tft.print(s);
}

void setup(void) {
  // initialize built-in buttons
  pinMode(BTN1_PIN, INPUT_PULLUP);  // active‑low
  pinMode(BTN2_PIN, INPUT_PULLUP);
  Serial.begin(115200);

  // initialize built-in display
  tft.init();
  tft.setRotation(1);
  tft.fillScreen(TFT_BLACK);
  tft.setTextColor(TFT_GREEN, TFT_BLACK); 
  tft.setTextSize(2);

  drawStateText("No button");

}

void loop() {
  bool b1 = (digitalRead(BTN1_PIN) == LOW);
  bool b2 = (digitalRead(BTN2_PIN) == LOW);

  String text;

  if (!b1 && !b2)       text = "No button";
  else if (b1 && !b2)   text = "Button 1";
  else if (!b1 && b2)   text = "Button 2";
  else                  text = "Both buttons";

  // Only re‑draw when the text actually changes
  if (text != lastText) {
    drawStateText(text);
    lastText = text;
  }

  delay(20);  // basic debounce
}

Adjusting TFT_eSPI Library

The TFT_eSPI library is a generic TFT library thats supports all kinds of TFT display sizes and controllers. In order for it to work, you need to adjust a setup file in the library.

In the file explorer, navigate to .pio/libdeps/lilygo-t-display/TFT_eSPI, and identify the file User_Setup_Select.h. Comment-out the default line:

//#include <User_Setup.h>  

Then comment-in the line that correctly defines the display driver, display type and SPI pins for your board:

#include <User_Setups/Setup25_TTGO_T_Display.h>
#define ILI9341_DRIVER

Next Steps

Your basic example project is done. You can now build and upload it in platformio.

Once uploaded, the built-in TFT display shows “No button”. Once you press one or both of the built-in buttons, the text changes and shows the pressed buttons.

Slow Website?

This website is very fast, and pages should appear instantly. If this site is slow for you, then your routing may be messed up, and this issue does not only affect done.land, but potentially a few other websites and downloads as well. Here are simple steps to speed up your Internet experience and fix issues with slow websites and downloads..

Comments

Please do leave comments below. I am using utteran.ce, an open-source and ad-free light-weight commenting system.

Here is how your comments are stored

Whenever you leave a comment, a new github issue is created on your behalf.

  • All comments become trackable issues in the Github Issues section, and I (and you) can follow up on them.

  • There is no third-party provider, no disrupting ads, and everything remains transparent inside github.

Github Users Yes, Spammers No

To keep spammers out and comments attributable, all you do is log in using your (free) github account and grant utteranc.es the permission to submit issues on your behalf.

If you don’t have a github account yet, go get yourself one - it’s free and simple.

If for any reason you do not feel comfortable with letting the commenting system submit issues for you, then visit Github Issues directly, i.e. by clicking the red button Submit Issue at the bottom of each page, and submit your issue manually. You control everything.

Discussions

For chit-chat and quick questions, feel free to visit and participate in Discussions. They work much like classic forums or bulletin boards. Just keep in mind: your valued input isn’t equally well trackable there.

  Show on Github    Submit Issue

(content created Feb 02, 2026)