Lessons and the learning game

Color TFT screens and touch UI

Drive color screens from an ESP32: SPI panels, TFT_eSPI fonts and gauges, resistive and capacitive touch, tabs, and a life support thermostat.

Take the course at /learn/path/tft-ui-and-touch. It is an intermediate course: it assumes the Uno course and is easier after Displays: characters, digits and dots.

The lessons

Pixels over SPI. An ST7789 and a round GC9A01 share one SPI bus, each with its own chip select: clock, data, CS and DC, RGB565 color, and what a full-screen fill costs. Then TFT_eSPI on a 2.8 inch ILI9341: the setup defines, rotation, the numbered fonts, centered text with a datum, and a mission clock that redraws without flicker.

Widgets and touch. A rover fuel gauge: a smooth arc and a bar from one number typed on the serial monitor, a warning color, and a drawn button. Then the XPT2046 resistive touch panel: raw readings and pressure, a calibration, and a landscape bug to fix where BLUE lights RED.

Capacitive touch and screens. The FT6206 on I2C: pixel coordinates with no calibration, turned from the panel's portrait frame to landscape, and a landing pad to hit. Then a spaceship console with HOME, LIGHTS and COMMS tabs, run by one state variable.

Boss. A life support thermostat: a TMP36 in big digits, a set point on touch buttons, heating and cooling with hysteresis, and an alarm outside the safe range.

The benches

All three benches wire the panel straight to a classic ESP32 on TFT_eSPI's default pins: SCK 18, MOSI 23, CS 15, DC 2, RST 4.

  • Two panels: an ST7789 (CS 15, RES 4) and a GC9A01 (CS 5, RES tied to 3V3) on the same clock, data and DC.
  • Resistive: an ILI9341 with XPT2046 touch, T_CS on 21, T_DO on 19, the touch clock and data on the display's.
  • Capacitive: an ILI9341 with an FT6206 on SDA 21 and SCL 22. The boss adds a TMP36 on GPIO 34.

What each sketch does

  • tftspi: Adafruit_ST7789 and Adafruit_GC9A01A on one bus, RGB565 by hand, a timed fill, a readout and a planet.
  • tftsetup: TFT_eSPI, ROTATION, color565(), font heights, MC_DATUM and a padded elapsed-time clock in font 7.
  • tftwidgets: drawSmoothArc() and a bar from a value read with Serial.parseInt(), red below LOW_PERCENT, and a TFT_eSPI_Button.
  • tfttouch: getTouchRawZ() and getTouchRaw(), a map() calibration that starts with its axes wrong, and three color buttons.
  • tftcap: Adafruit_FT6206, an I2C check at 0x38, x = 320 - p.y and y = 240 - p.x, a landing pad and painted dots.
  • tftnav: an enum state, a tab bar, toggles and a ping button, each screen drawn when it changes.
  • tftboss: analogReadMilliVolts() in tenths of a degree, a set point from START_SET_C, hysteresis of HYST_TENTHS and a 15 to 30 C safe range.

Honest limits

  • The touch is your mouse pointer: one point at a time, with no noise, so the FT6206's second finger and real panel jitter are not exercised.
  • The panels do not answer over MISO, so reading pixels back from the screen gives black. Sprites read their own memory as usual.
  • The smooth arcs are drawn with soft floating point by the browser's compiler, so the gauge lesson takes a few seconds to draw, longer than on a real ESP32.
  • The TMP36 is a slider, not air, and the cabin has no thermal model: heating does not warm it. Move the slider to play the cabin.

Displays: characters, digits and dots and E-paper displays cover the other kinds of screen.