Arduino Nano ESP32 - 2.25 inch TFT LCD Display Screen 76x284

The Arduino Nano ESP32 combines the Nano layout with an ESP32-S3 chip, Wi-Fi and Bluetooth. Its 3.3V pins drive the 2.25 inch TFT LCD display screen directly, which makes it a neat base for a connected status display. This tutorial explains:

Arduino Nano ESP32 wired to a 2.25 inch 76x284 ST7789 TFT LCD display over SPI - wiring and pinout

Hardware Preparation

1×Arduino Nano ESP32
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×2.25 inch TFT LCD Display Screen 76x284
1×Jumper Wires
1×Breadboard
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano ESP32

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of the 2.25 inch TFT LCD Display Screen 76x284

The 2.25 inch TFT LCD display screen is a long, narrow color panel with 76 x 284 pixels. It is driven by an ST7789 chip, which receives drawing commands over SPI. The panel has no touch layer, and its shape suits status bars, level meters, clocks and scrolling text.

Item Value
Screen size 2.25 inch (diagonal)
Resolution 76 x 284 pixels (284 x 76 in landscape)
Panel IPS, wide viewing angle
Driver chip ST7789
Interface SPI, write only (no MISO pin)
Colors 16-bit RGB565 (65,536 colors)
Touch No
Backlight Active-LOW (on when BL is LOW)

The ST7789 chip has memory for a 240 x 320 picture, but this panel shows only a 76 x 284 window in the middle of that memory. When you create the display object with the size 76 x 284, the DIYables_TFT_SPI library picks the right settings for this panel: it shifts every drawing call into that window, uses the panel's color order, and sets a 20 MHz SPI clock. You simply draw with screen coordinates, starting from (0, 0) at the top-left corner.

Pinout

The display module has 8 pins:

Pin Function
GND Ground
VCC Power supply (3.3V)
SCL SPI clock (SCK)
SDA SPI data input (MOSI) - data from the Nano ESP32 to the display
RST Hardware reset
DC Data / Command select - HIGH for pixel data, LOW for commands
CS Chip Select - LOW selects the display on the SPI bus
BL Backlight - active-LOW: LOW (GND) turns the backlight on, HIGH turns it off

Note — SCL and SDA are SPI pins: The names SCL and SDA are often used for I2C, but on this module they are the SPI clock (SCK) and the SPI data line (MOSI). Connect them to the hardware SPI pins of the Nano ESP32, not to its I2C pins.

Note — no MISO pin: The display only receives data, so it has no MISO (SDO) pin. The library never reads from the display, so nothing is missing.

2.25 inch TFT LCD display screen 76x284 pinout

Wiring Diagram

Note — the backlight is active-LOW: Connect BL to GND to turn the backlight on. If BL is connected to 3.3V, the backlight stays off and the screen looks black even when the code is running. To switch the backlight from code instead, connect BL to a free pin and call TFT_display.initBacklight(pin, true); the true tells the library that the backlight is active-LOW.

Note: The Arduino Nano ESP32 uses 3.3V logic. Connect the display's VCC to the 3.3V pin only.

Note — D labels: The code writes the pins as D10, D9 and D8 instead of plain numbers. The D labels always point to the pins printed on the board, whichever Pin Numbering option is selected in the Tools menu.

Connect SCL to D13 and SDA to D11, the hardware SPI pins of the Nano ESP32. RST, DC and CS can use any free digital pins - D8, D9 and D10 are used in the examples.

Display Pin Nano ESP32 Pin Description
GND GND Ground
VCC 3.3V Power supply (3.3V)
SCL D13 SPI clock (SCK)
SDA D11 SPI data (MOSI)
RST D8 Reset
DC D9 Data / Command select
CS D10 Chip Select
BL GND Backlight on (active-LOW)
The wiring diagram between Arduino Nano ESP32 and 2.25 inch TFT LCD display screen 76x284

This image is created using Fritzing. Click to enlarge image

Library Installation

  • Connect the Nano ESP32 to your computer with a USB cable.
  • Open Arduino IDE, select the right board and port.
  • Navigate to the Libraries icon on the left bar of the Arduino IDE.
  • Search "DIYables_TFT_SPI", then find the DIYables_TFT_SPI library by DIYables.
  • Click Install button to install the latest version of the library.
  • When prompted to install dependencies, click Install All to also install the Adafruit GFX Library.
  • Search for DIYables TFT SPI created by DIYables.io and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano ESP32
Library Manager
Type:
All
Topic:
All
DIYables TFT SPI by DIYables.io
Works with both touch and non-touch versions of the same SPI TFT modules. Supports ILI9341 (240x320, 16-bit RGB565), ILI9488 (320x480, 18-bit RGB666), ST7789 (240x320 and the 2.25" 76x284 bar display, 16-bit RGB565), ST7796 / ST7796S (320x480, 16-bit RGB565), and ST7735 (128x160, 128x128, 80x160, 16-bit RGB565) over SPI. Includes built-in driver for XPT2046 / HR2046 / ADS7843 SPI touch controllers and 4-wire resistive touch panels - no separate touch library required. Use the display-only API for non-touch panels, or add initTouchSPI() to enable touch on modules that include a touch controller. Extends Adafruit GFX for full graphics support. Works with any Arduino-compatible board that has SPI. More info
1.1.0
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
Arduino Nano ESP32 on COM15
1

Note: If the Nano ESP32 does not appear in the board list, install the Arduino ESP32 Boards package from the Boards Manager first.

Basic Structure

Every sketch for this display starts from the same few lines:

#include <DIYables_TFT_SPI.h> #define TFT_CS_PIN D10 #define TFT_DC_PIN D9 #define TFT_RST_PIN D8 // 76 x 284 is the portrait size of the 2.25 inch display DIYables_ST7789_SPI TFT_display(76, 284, TFT_CS_PIN, TFT_DC_PIN, TFT_RST_PIN); void setup() { TFT_display.begin(); TFT_display.setRotation(1); // 1 = landscape: 284 x 76 pixels } void loop() { // drawing code here }
  • Always pass 76, 284 - the width and height in portrait. This size tells the library to use the settings of the 2.25 inch panel. With another size, the picture appears shifted or not at all.
  • Rotation 0 and 2 are portrait (76 pixels wide, 284 tall). Rotation 1 and 3 are landscape (284 wide, 76 tall). All examples in this tutorial use landscape.
  • begin() uses a 20 MHz SPI clock. You can pass another clock, for example TFT_display.begin(10000000) for 10 MHz, if long jumper wires cause noise on the screen.

Nano ESP32 Code - Draw Shapes

The DrawShapes example draws two rows of shapes across the long screen: outlined and filled circles and triangles plus a diamond outline on the top row, and outlined and filled rectangles and rounded rectangles plus a filled diamond on the bottom row. It uses the drawing functions of the Adafruit GFX Library.

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-2.25-inch-tft-lcd-display-screen-76x284 */ /* Created by DIYables This example code is in the public domain Product page: https://diyables.io/tft-spi For the 2.25 inch 76x284 ST7789 bar display (no touch). Draws circles, triangles, rectangles, round rectangles and diamonds in two rows across the long landscape screen. */ // ============================================= // Single include brings in all driver classes. // ============================================= #include <DIYables_TFT_SPI.h> // ============================================= // Wiring (Arduino Nano ESP32) // --------------------------------------------- // Module pins: GND, VCC, SCL, SDA, RST, DC, CS, BL // // Display pin Arduino Nano ESP32 // ------------ --------------------------------- // GND -> GND // VCC -> 3.3V (NOT 5V!) // SCL -> D13 (hardware SPI SCK) // SDA -> D11 (hardware SPI MOSI) // RST -> D8 (TFT_RST_PIN) // DC -> D9 (TFT_DC_PIN) // CS -> D10 (TFT_CS_PIN) // BL -> GND (backlight is active-LOW: GND = on, 3.3V = off) // or a GPIO + TFT_display.initBacklight(pin, true) // ============================================= // ============================================= // SPI pin definitions (adjust for your board) // ============================================= #define TFT_CS_PIN D10 #define TFT_DC_PIN D9 #define TFT_RST_PIN D8 // SCL and SDA use the default hardware SPI pins (D13 / D11) // ============================================= // Create display object (portrait size 76 x 284) // ============================================= DIYables_ST7789_SPI TFT_display(76, 284, TFT_CS_PIN, TFT_DC_PIN, TFT_RST_PIN); #define BLUE DIYables_TFT_SPI::colorRGB(0, 0, 255) #define RED DIYables_TFT_SPI::colorRGB(255, 0, 0) #define GREEN DIYables_TFT_SPI::colorRGB(0, 255, 0) #define ORANGE DIYables_TFT_SPI::colorRGB(255, 165, 0) #define PINK DIYables_TFT_SPI::colorRGB(255, 192, 203) #define VIOLET DIYables_TFT_SPI::colorRGB(148, 0, 211) #define TURQUOISE DIYables_TFT_SPI::colorRGB(64, 224, 208) #define WHITE DIYables_TFT_SPI::colorRGB(255, 255, 255) // Helper to draw an outlined diamond void drawDiamond(int cx, int cy, int h, int v, uint16_t color) { TFT_display.drawLine(cx, cy - v, cx + h, cy, color); TFT_display.drawLine(cx + h, cy, cx, cy + v, color); TFT_display.drawLine(cx, cy + v, cx - h, cy, color); TFT_display.drawLine(cx - h, cy, cx, cy - v, color); } // Helper to draw a filled diamond void fillDiamond(int cx, int cy, int h, int v, uint16_t color) { TFT_display.fillTriangle(cx, cy - v, cx + h, cy, cx, cy + v, color); TFT_display.fillTriangle(cx, cy - v, cx, cy + v, cx - h, cy, color); } void setup() { TFT_display.begin(); TFT_display.setRotation(1); // Landscape: 284 x 76 } void loop() { TFT_display.fillScreen(WHITE); uint16_t w = TFT_display.width(); // 284 uint16_t h = TFT_display.height(); // 76 // 5 columns x 2 rows int colW = w / 5; int row1 = h / 4; // centre of the top row int row2 = h * 3 / 4; // centre of the bottom row int cx[5]; for (int i = 0; i < 5; i++) cx[i] = colW * i + colW / 2; // ---- Top row: outlined / filled pairs ---- TFT_display.drawCircle(cx[0], row1, 15, RED); TFT_display.fillCircle(cx[1], row1, 15, RED); TFT_display.drawTriangle(cx[2] - 18, row1 + 14, cx[2] + 18, row1 + 14, cx[2], row1 - 14, BLUE); TFT_display.fillTriangle(cx[3] - 18, row1 + 14, cx[3] + 18, row1 + 14, cx[3], row1 - 14, GREEN); drawDiamond(cx[4], row1, 16, 15, GREEN); // ---- Bottom row ---- TFT_display.drawRect(cx[0] - 22, row2 - 13, 44, 26, ORANGE); TFT_display.fillRect(cx[1] - 22, row2 - 13, 44, 26, TURQUOISE); TFT_display.drawRoundRect(cx[2] - 22, row2 - 13, 44, 26, 6, VIOLET); TFT_display.fillRoundRect(cx[3] - 22, row2 - 13, 44, 26, 6, PINK); fillDiamond(cx[4], row2, 16, 15, BLUE); delay(10000); }

Detailed Instructions

  • Wire the display to the Nano ESP32 as shown in the wiring diagram above.
  • Connect the Nano ESP32 to your computer with a USB cable.
  • Open Arduino IDE, select the right board and port.
  • Copy the above code and paste it to the editor of Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to the Nano ESP32.
  • The screen shows two rows of colored shapes on a white background.

API Summary

Method Description Example
TFT_display.begin() Initialize the display. Call once in setup(). TFT_display.begin();
TFT_display.setRotation(r) Set screen orientation. 1 = landscape (284 x 76). TFT_display.setRotation(1);
TFT_display.fillScreen(color) Fill the entire screen with one color. TFT_display.fillScreen(WHITE);
DIYables_TFT_SPI::colorRGB(r,g,b) Convert RGB values to a 16-bit color. DIYables_TFT_SPI::colorRGB(255, 0, 0)
TFT_display.drawCircle(x,y,r,color) Draw a circle outline. TFT_display.drawCircle(30, 20, 15, RED);
TFT_display.fillCircle(x,y,r,color) Draw a filled circle. TFT_display.fillCircle(30, 20, 15, RED);
TFT_display.drawTriangle(x0,y0,x1,y1,x2,y2,color) Draw a triangle outline. TFT_display.drawTriangle(10, 34, 46, 34, 28, 6, BLUE);
TFT_display.fillRoundRect(x,y,w,h,r,color) Draw a filled rectangle with rounded corners. TFT_display.fillRoundRect(10, 44, 44, 26, 6, PINK);
TFT_display.drawLine(x0,y0,x1,y1,color) Draw a line. TFT_display.drawLine(0, 0, 283, 75, GREEN);

Nano ESP32 Code - Show Text and Number

The ShowTextAndNumber example prints text and numbers with the built-in font, the way you would show sensor readings: a temperature and a humidity value in magenta on a white background. Text size 2 makes each character 12 x 16 pixels, so two lines fit comfortably in the 76-pixel height.

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-2.25-inch-tft-lcd-display-screen-76x284 */ /* Created by DIYables This example code is in the public domain Product page: https://diyables.io/tft-spi For the 2.25 inch 76x284 ST7789 bar display (no touch). Shows text and numbers with the built-in font. */ // ============================================= // Single include brings in all driver classes. // ============================================= #include <DIYables_TFT_SPI.h> // ============================================= // Wiring (Arduino Nano ESP32) // --------------------------------------------- // Module pins: GND, VCC, SCL, SDA, RST, DC, CS, BL // // Display pin Arduino Nano ESP32 // ------------ --------------------------------- // GND -> GND // VCC -> 3.3V (NOT 5V!) // SCL -> D13 (hardware SPI SCK) // SDA -> D11 (hardware SPI MOSI) // RST -> D8 (TFT_RST_PIN) // DC -> D9 (TFT_DC_PIN) // CS -> D10 (TFT_CS_PIN) // BL -> GND (backlight is active-LOW: GND = on, 3.3V = off) // or a GPIO + TFT_display.initBacklight(pin, true) // ============================================= // ============================================= // SPI pin definitions (adjust for your board) // ============================================= #define TFT_CS_PIN D10 #define TFT_DC_PIN D9 #define TFT_RST_PIN D8 // SCL and SDA use the default hardware SPI pins (D13 / D11) // ============================================= // Create display object (portrait size 76 x 284) // ============================================= DIYables_ST7789_SPI TFT_display(76, 284, TFT_CS_PIN, TFT_DC_PIN, TFT_RST_PIN); #define MAGENTA DIYables_TFT_SPI::colorRGB(255, 0, 255) #define WHITE DIYables_TFT_SPI::colorRGB(255, 255, 255) void setup() { Serial.begin(9600); Serial.println(F("TFT SPI Display - Show text and numbers")); TFT_display.begin(); TFT_display.setRotation(1); // Landscape: 284 x 76 TFT_display.fillScreen(WHITE); // Set text color and size (size 2 = 12 x 16 pixels per character) TFT_display.setTextColor(MAGENTA); TFT_display.setTextSize(2); // Sample values float temperature = 23.5; float humidity = 78.6; // Display temperature TFT_display.setCursor(10, 14); TFT_display.print("Temperature: "); TFT_display.print(temperature, 1); TFT_display.print(char(247)); TFT_display.println("C"); // Display humidity TFT_display.setCursor(10, 46); TFT_display.print("Humidity: "); TFT_display.print(humidity, 1); TFT_display.print("%"); } void loop() { }

Detailed Instructions

  • Wire the display to the Nano ESP32 as shown in the wiring diagram above.
  • Connect the Nano ESP32 to your computer with a USB cable.
  • Open Arduino IDE, select the right board and port.
  • Copy the above code and paste it to the editor of Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to the Nano ESP32.
  • The screen shows two lines: Temperature: 23.5°C and Humidity: 78.6%.

API Summary

Method Description Example
TFT_display.setTextColor(color) Set the text color. TFT_display.setTextColor(MAGENTA);
TFT_display.setTextSize(size) Set the text scale (1 = 6 x 8 pixels, 2 = 12 x 16 pixels, ...). TFT_display.setTextSize(2);
TFT_display.setCursor(x, y) Move the text cursor. TFT_display.setCursor(10, 14);
TFT_display.print(value) Print a string or a number at the cursor. TFT_display.print(23.5, 1);
TFT_display.println(value) Print, then move the cursor to the next line. TFT_display.println("C");

Nano ESP32 Code - Draw Image

The DrawImage example draws a 120 x 53 pixel color picture in the middle of the screen, then inverts its colors every 2 seconds. The pixels are stored in flash memory in the companion file bitmap.h as a const uint16_t array, so they do not use any RAM. The picture is wider than 76 pixels, so it only fits in landscape.

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-2.25-inch-tft-lcd-display-screen-76x284 */ /* Created by DIYables This example code is in the public domain Product page: https://diyables.io/tft-spi For the 2.25 inch 76x284 ST7789 bar display (no touch). Draws a 120x53 bitmap stored in flash (bitmap.h) in the middle of the landscape screen, then toggles color inversion every 2 seconds. */ // ============================================= // Single include brings in all driver classes. // ============================================= #include <DIYables_TFT_SPI.h> #include "bitmap.h" // ============================================= // Wiring (Arduino Nano ESP32) // --------------------------------------------- // Module pins: GND, VCC, SCL, SDA, RST, DC, CS, BL // // Display pin Arduino Nano ESP32 // ------------ --------------------------------- // GND -> GND // VCC -> 3.3V (NOT 5V!) // SCL -> D13 (hardware SPI SCK) // SDA -> D11 (hardware SPI MOSI) // RST -> D8 (TFT_RST_PIN) // DC -> D9 (TFT_DC_PIN) // CS -> D10 (TFT_CS_PIN) // BL -> GND (backlight is active-LOW: GND = on, 3.3V = off) // or a GPIO + TFT_display.initBacklight(pin, true) // ============================================= // ============================================= // SPI pin definitions (adjust for your board) // ============================================= #define TFT_CS_PIN D10 #define TFT_DC_PIN D9 #define TFT_RST_PIN D8 // SCL and SDA use the default hardware SPI pins (D13 / D11) // ============================================= // Create display object (portrait size 76 x 284) // ============================================= DIYables_ST7789_SPI TFT_display(76, 284, TFT_CS_PIN, TFT_DC_PIN, TFT_RST_PIN); #define WHITE DIYables_TFT_SPI::colorRGB(255, 255, 255) int img_width = 120; int img_height = 53; void setup() { Serial.begin(9600); Serial.println(F("TFT SPI Display - Draw Image")); TFT_display.begin(); TFT_display.setRotation(1); // Landscape: 284 x 76 (the image is wider than 76) uint16_t SCREEN_WIDTH = TFT_display.width(); uint16_t SCREEN_HEIGHT = TFT_display.height(); int x = (SCREEN_WIDTH - img_width) / 2; int y = (SCREEN_HEIGHT - img_height) / 2; TFT_display.fillScreen(WHITE); TFT_display.drawRGBBitmap(x, y, myBitmap, img_width, img_height); } void loop() { delay(2000); TFT_display.invertDisplay(true); delay(2000); TFT_display.invertDisplay(false); }

Detailed Instructions

  • Wire the display to the Nano ESP32 as shown in the wiring diagram above.
  • Place bitmap.h in the same folder as the sketch.
  • Connect the Nano ESP32 to your computer with a USB cable.
  • Open Arduino IDE, select the right board and port, paste the code, and click Upload.
  • The picture appears in the middle of the screen. Every 2 seconds, its colors invert and then return to normal.

API Summary

Method Description Example
TFT_display.drawRGBBitmap(x,y,bitmap,w,h) Draw an RGB565 bitmap from flash memory at position (x, y). TFT_display.drawRGBBitmap(82, 11, myBitmap, 120, 53);
TFT_display.invertDisplay(on) Invert all colors on the screen (true) or show them normally (false). TFT_display.invertDisplay(true);
TFT_display.width() / TFT_display.height() Get the screen size for the current rotation. int x = (TFT_display.width() - 120) / 2;

Nano ESP32 Code - Use External Font

The UseExternalFont example prints the same two readings with FreeSansBold12pt7b, one of the fonts included in the Adafruit GFX Library. External fonts have smooth, proportional characters that look much better than the built-in 5 x 7 font. Call setFont(NULL) at any time to go back to the built-in font.

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-2.25-inch-tft-lcd-display-screen-76x284 */ /* Created by DIYables This example code is in the public domain Product page: https://diyables.io/tft-spi For the 2.25 inch 76x284 ST7789 bar display (no touch). Shows text with an external Adafruit GFX font (FreeSansBold12pt7b). */ // ============================================= // Single include brings in all driver classes. // ============================================= #include <DIYables_TFT_SPI.h> #include <Fonts/FreeSansBold12pt7b.h> // ============================================= // Wiring (Arduino Nano ESP32) // --------------------------------------------- // Module pins: GND, VCC, SCL, SDA, RST, DC, CS, BL // // Display pin Arduino Nano ESP32 // ------------ --------------------------------- // GND -> GND // VCC -> 3.3V (NOT 5V!) // SCL -> D13 (hardware SPI SCK) // SDA -> D11 (hardware SPI MOSI) // RST -> D8 (TFT_RST_PIN) // DC -> D9 (TFT_DC_PIN) // CS -> D10 (TFT_CS_PIN) // BL -> GND (backlight is active-LOW: GND = on, 3.3V = off) // or a GPIO + TFT_display.initBacklight(pin, true) // ============================================= // ============================================= // SPI pin definitions (adjust for your board) // ============================================= #define TFT_CS_PIN D10 #define TFT_DC_PIN D9 #define TFT_RST_PIN D8 // SCL and SDA use the default hardware SPI pins (D13 / D11) // ============================================= // Create display object (portrait size 76 x 284) // ============================================= DIYables_ST7789_SPI TFT_display(76, 284, TFT_CS_PIN, TFT_DC_PIN, TFT_RST_PIN); #define MAGENTA DIYables_TFT_SPI::colorRGB(255, 0, 255) #define WHITE DIYables_TFT_SPI::colorRGB(255, 255, 255) void setup() { Serial.begin(9600); Serial.println(F("TFT SPI Display - Use external font")); TFT_display.begin(); TFT_display.setFont(&FreeSansBold12pt7b); TFT_display.setRotation(1); // Landscape: 284 x 76 TFT_display.fillScreen(WHITE); TFT_display.setTextColor(MAGENTA); TFT_display.setTextSize(1); float temperature = 23.5; float humidity = 78.6; // With an external font, setCursor() sets the text BASELINE (bottom of // the letters), not the top-left corner. TFT_display.setCursor(10, 30); TFT_display.print("Temperature: "); TFT_display.print(temperature, 1); TFT_display.print(" C"); // the degree sign is not part of this font TFT_display.setCursor(10, 64); TFT_display.print("Humidity: "); TFT_display.print(humidity, 1); TFT_display.print("%"); } void loop() { }

Detailed Instructions

  • Wire the display to the Nano ESP32 as shown in the wiring diagram above.
  • Connect the Nano ESP32 to your computer with a USB cable.
  • Open Arduino IDE, select the right board and port.
  • Copy the above code and paste it to the editor of Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to the Nano ESP32.
  • The screen shows the temperature and humidity in a smooth, bold font. This font has no degree sign, so the temperature is shown as 23.5 C.

API Summary

Method Description Example
TFT_display.setFont(&FontName) Switch to an Adafruit GFX font. Pass NULL to return to the built-in font. TFT_display.setFont(&FreeSansBold12pt7b);
TFT_display.setCursor(x, y) With an external font, y is the baseline of the text (the bottom of letters without descenders), not the top. TFT_display.setCursor(10, 30);
TFT_display.print(text) Print a string with the active font. TFT_display.print("Humidity: ");

Nano ESP32 Code - Custom SPI

The CustomSPI example passes the SPI bus to the display object as the last argument of the constructor. This matters on boards that have more than one SPI bus, or when you want to make the bus choice clear in the code.

The Nano ESP32 exposes one hardware SPI bus on the Nano header (D13 = SCK, D11 = MOSI), so the sketch keeps &SPI. The example shows where the bus is chosen, so the code is easy to adapt later.

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-2.25-inch-tft-lcd-display-screen-76x284 */ /* Created by DIYables This example code is in the public domain Product page: https://diyables.io/tft-spi For the 2.25 inch 76x284 ST7789 bar display (no touch). This example demonstrates how to use a custom (non-default) SPI bus with the DIYables TFT SPI library. This is useful on boards that have multiple SPI interfaces, such as: - ESP32: HSPI / VSPI - Arduino Giga / Portenta: SPI1 - Raspberry Pi Pico: SPI1 */ // ============================================= // Single include brings in all driver classes. // ============================================= #include <DIYables_TFT_SPI.h> // ============================================= // Wiring (Arduino Nano ESP32 - default SPI bus) // --------------------------------------------- // NOTE: The Arduino Nano ESP32 exposes one hardware SPI bus on the Nano // header (D11 = MOSI, D13 = SCK), so MY_SPI must remain &SPI. // // Module pins: GND, VCC, SCL, SDA, RST, DC, CS, BL // // Display pin Arduino Nano ESP32 // ------------ --------------------------------- // GND -> GND // VCC -> 3.3V (NOT 5V!) // SCL -> D13 (hardware SPI SCK) // SDA -> D11 (hardware SPI MOSI) // RST -> D8 (TFT_RST_PIN) // DC -> D9 (TFT_DC_PIN) // CS -> D10 (TFT_CS_PIN) // BL -> GND (backlight is active-LOW: GND = on, 3.3V = off) // or a GPIO + TFT_display.initBacklight(pin, true) // ============================================= // ============================================= // SPI pin definitions (adjust for your board) // ============================================= #define TFT_CS_PIN D10 #define TFT_DC_PIN D9 #define TFT_RST_PIN D8 // ============================================= // Select alternate SPI bus (uncomment for your board) // ============================================= // --- Nano ESP32: default SPI (SCL -> D13, SDA -> D11) --- #define MY_SPI &SPI // ============================================= // Create display object with custom SPI bus // (portrait size 76 x 284) // ============================================= DIYables_ST7789_SPI TFT_display(76, 284, TFT_CS_PIN, TFT_DC_PIN, TFT_RST_PIN, MY_SPI); #define BLACK DIYables_TFT_SPI::colorRGB(0, 0, 0) #define WHITE DIYables_TFT_SPI::colorRGB(255, 255, 255) #define RED DIYables_TFT_SPI::colorRGB(255, 0, 0) #define GREEN DIYables_TFT_SPI::colorRGB(0, 255, 0) #define BLUE DIYables_TFT_SPI::colorRGB(0, 0, 255) void setup() { Serial.begin(9600); // For ESP32 HSPI: optionally remap pins before begin() // hspi.begin(14, 12, 13, -1); // SCK, MISO, MOSI, SS TFT_display.begin(); TFT_display.setRotation(1); // Landscape: 284 x 76 TFT_display.fillScreen(BLACK); uint16_t w = TFT_display.width(); uint16_t h = TFT_display.height(); // Draw a simple test pattern TFT_display.fillRect(0, 0, w / 3, h, RED); TFT_display.fillRect(w / 3, 0, w / 3, h, GREEN); TFT_display.fillRect(w * 2 / 3, 0, w - w * 2 / 3, h, BLUE); TFT_display.setTextColor(WHITE); TFT_display.setTextSize(2); TFT_display.setCursor(40, h / 2 - 8); TFT_display.print("Custom SPI bus OK"); } void loop() { // Nothing to do }

Detailed Instructions

  • Wire the display to the Nano ESP32 as shown in the wiring diagram above.
  • Connect the Nano ESP32 to your computer with a USB cable.
  • Open Arduino IDE, select the right board and port.
  • Copy the above code and paste it to the editor of Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to the Nano ESP32.
  • The screen shows three color bars - red, green and blue - with the text Custom SPI bus OK.

API Summary

Method Description Example
DIYables_ST7789_SPI(w,h,cs,dc,rst,spi) Constructor with the SPI bus as the last argument. Without it, the library uses &SPI. DIYables_ST7789_SPI TFT_display(76, 284, TFT_CS_PIN, TFT_DC_PIN, TFT_RST_PIN, &SPI);
TFT_display.begin() Initialize the display on the selected SPI bus. TFT_display.begin();

Nano ESP32 Code - Display Test

The ColligateTest example is a full graphics benchmark laid out for this long, low screen. It runs 14 tests - text, triangle-function curves, a sine wave, filled rectangles, round rectangles, circles and triangles, grid lines, and random pixels, lines and shapes - and measures how long each one takes. The results are shown on the screen in two pages and printed on the Serial Monitor. It is also a quick way to check that every part of the wiring works.

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-2.25-inch-tft-lcd-display-screen-76x284 */ /* Created by DIYables This example code is in the public domain Comprehensive graphics benchmark - tests most drawing functions and reports timing for each operation, both on the screen and on the Serial Monitor. Product page: https://diyables.io/tft-spi For the 2.25 inch 76x284 ST7789 bar display (no touch). Same tests as the main ColligateTest example, laid out for this long, low screen: - no header line, so the tests get more room - the shape tests draw one row of 5 big shapes - the results table is shown in two pages (14 lines do not fit in 76 pixels) Credit: This example is based on the colligate_test example from the LCDWIKI library */ // ============================================= // Single include brings in all driver classes. // ============================================= #include <DIYables_TFT_SPI.h> // ============================================= // Wiring (Arduino Nano ESP32) // --------------------------------------------- // Module pins: GND, VCC, SCL, SDA, RST, DC, CS, BL // // Display pin Arduino Nano ESP32 // ------------ --------------------------------- // GND -> GND // VCC -> 3.3V (NOT 5V!) // SCL -> D13 (hardware SPI SCK) // SDA -> D11 (hardware SPI MOSI) // RST -> D8 (TFT_RST_PIN) // DC -> D9 (TFT_DC_PIN) // CS -> D10 (TFT_CS_PIN) // BL -> GND (backlight is active-LOW: GND = on, 3.3V = off) // or a GPIO + TFT_display.initBacklight(pin, true) // ============================================= // ============================================= // SPI pin definitions (adjust for your board) // ============================================= #define TFT_CS_PIN D10 #define TFT_DC_PIN D9 #define TFT_RST_PIN D8 // SCL and SDA use the default hardware SPI pins (D13 / D11) // ============================================= // Create display object (portrait size 76 x 284) // ============================================= DIYables_ST7789_SPI TFT_display(76, 284, TFT_CS_PIN, TFT_DC_PIN, TFT_RST_PIN); // The tests run in landscape (284 x 76), so the screen size is filled in by setup() uint16_t SCREEN_WIDTH; uint16_t SCREEN_HEIGHT; // Layout: a red frame from the top edge down to the footer bar. // The drawing area is everything inside the frame. #define FOOTER_H 15 #define TOP_Y 1 // first row inside the frame #define BOT_Y (SCREEN_HEIGHT - FOOTER_H - 2) // last row inside the frame #define AREA_H (BOT_Y - TOP_Y + 1) // rows inside the frame #define MID_Y ((TOP_Y + BOT_Y) / 2) // middle row of the drawing area // The shape tests draw one row of 5 shapes, as big as the drawing area allows #define SHAPE_COUNT 5 #define SHAPE_GAP 4 // Color definitions (RGB565) #define BLACK DIYables_TFT_SPI::colorRGB(0, 0, 0) #define WHITE DIYables_TFT_SPI::colorRGB(255, 255, 255) #define RED DIYables_TFT_SPI::colorRGB(255, 0, 0) #define GREEN DIYables_TFT_SPI::colorRGB(0, 255, 0) #define BLUE DIYables_TFT_SPI::colorRGB(0, 0, 255) #define CYAN DIYables_TFT_SPI::colorRGB(0, 255, 255) #define MAGENTA DIYables_TFT_SPI::colorRGB(255, 0, 255) #define YELLOW DIYables_TFT_SPI::colorRGB(255, 255, 0) #define ORANGE DIYables_TFT_SPI::colorRGB(255, 165, 0) // Print text horizontally centered on the screen void printCentered(const char *text, int16_t y, uint16_t color) { int16_t x1, y1; uint16_t w, h; TFT_display.setTextColor(color); TFT_display.setTextSize(1); TFT_display.getTextBounds(text, 0, y, &x1, &y1, &w, &h); int16_t x = (SCREEN_WIDTH - (int16_t)w) / 2; if (x < 0) x = 0; TFT_display.setCursor(x, y); TFT_display.print(text); } // Plot one point of a curve, skipping points outside the drawing area // (tan and cot grow without bound near their asymptotes) void plotCurve(int16_t x, float value, uint16_t color) { if (value > 30000.0 || value < -30000.0) return; int16_t y = MID_Y + (int16_t)value; if (y < TOP_Y || y > (int16_t)BOT_Y) return; TFT_display.drawPixel(x, y, color); } // Random point inside the drawing area, 1 pixel away from the frame int16_t randomX(void) { return 2 + random(SCREEN_WIDTH - 4); } int16_t randomY(void) { return TOP_Y + 1 + random(AREA_H - 2); } // Size of each shape in the row of 5 int16_t shapeSize(void) { int16_t size = AREA_H - 8; // 4 pixels free above and below int16_t fit = (SCREEN_WIDTH - (SHAPE_COUNT + 1) * SHAPE_GAP) / SHAPE_COUNT; return size < fit ? size : fit; } // Left edge of shape i in the row (the row is centered) int16_t shapeX(uint8_t i, int16_t size) { int16_t row = SHAPE_COUNT * size + (SHAPE_COUNT - 1) * SHAPE_GAP; return (SCREEN_WIDTH - row) / 2 + i * (size + SHAPE_GAP); } // Top edge of the row (centered in the drawing area) int16_t shapeY(int16_t size) { return TOP_Y + (AREA_H - size) / 2; } // Display main surface: red frame and footer bar (no header line) unsigned long show_text(void) { unsigned long time_start = micros(); TFT_display.fillRect(0, SCREEN_HEIGHT - FOOTER_H, SCREEN_WIDTH, FOOTER_H, DIYables_TFT_SPI::colorRGB(128, 128, 128)); printCentered("<https://diyables.io/tft-spi>", SCREEN_HEIGHT - 11, WHITE); TFT_display.drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - FOOTER_H, RED); return micros() - time_start; } // Display triangle functions (sin, cos, tan, cot) unsigned long show_triangle_function(void) { uint16_t i; unsigned long time_start = micros(); float amp = (BOT_Y - TOP_Y) / 2.0 - 2.0; // fill the drawing area float step = 360.0 / (SCREEN_WIDTH - 2); // one full period across the screen // Draw crosshairs TFT_display.drawFastVLine(SCREEN_WIDTH / 2 - 1, TOP_Y, AREA_H, BLUE); TFT_display.drawFastHLine(1, MID_Y, SCREEN_WIDTH - 2, BLUE); for (i = 1; i <= AREA_H / 2 / 10; i++) { TFT_display.drawFastHLine(SCREEN_WIDTH / 2 - 3, MID_Y - i * 10, 5, BLUE); TFT_display.drawFastHLine(SCREEN_WIDTH / 2 - 3, MID_Y + i * 10, 5, BLUE); } for (i = 1; i <= (SCREEN_WIDTH - 2) / 2 / 10; i++) { TFT_display.drawFastVLine(SCREEN_WIDTH / 2 - 1 - i * 10, MID_Y - 2, 5, BLUE); TFT_display.drawFastVLine(SCREEN_WIDTH / 2 - 1 + i * 10, MID_Y - 2, 5, BLUE); } TFT_display.setTextSize(1); TFT_display.setTextColor(CYAN); TFT_display.setCursor(5, TOP_Y + 2); TFT_display.print(F("sin")); TFT_display.setTextColor(GREEN); TFT_display.setCursor(5, TOP_Y + 10); TFT_display.print(F("cos")); TFT_display.setTextColor(YELLOW); TFT_display.setCursor(5, TOP_Y + 18); TFT_display.print(F("tan")); TFT_display.setTextColor(RED); TFT_display.setCursor(5, TOP_Y + 26); TFT_display.print(F("cot")); for (i = 1; i < SCREEN_WIDTH - 1; i++) { float rad = radians(i * step); plotCurve(i, sin(rad) * amp, CYAN); plotCurve(i, cos(rad) * amp, GREEN); plotCurve(i, tan(rad) * 10.0, YELLOW); float t = tan(rad); if (t != 0.0) plotCurve(i, (1.0 / t) * 10.0, RED); } return micros() - time_start; } // Draw a moving sinewave. The previous trace is erased by recomputing the // value one screen-width earlier, so no frame buffer is needed - that keeps // this example runnable on boards with very little RAM, such as the Uno R3. unsigned long show_sinewave(void) { unsigned long time_start = micros(); uint16_t span = SCREEN_WIDTH - 2; uint32_t total = (uint32_t)span * 12; float amp = (BOT_Y - TOP_Y) / 2.0 - 2.0; float step = 720.0 / span; // two periods across the screen TFT_display.drawFastVLine(SCREEN_WIDTH / 2 - 1, TOP_Y, AREA_H, BLUE); TFT_display.drawFastHLine(1, MID_Y, SCREEN_WIDTH - 2, BLUE); for (uint32_t i = 0; i < total; i++) { uint16_t x = 1 + (i % span); // Erase the point drawn at this x one screen ago if (i >= span) { uint32_t prev = i - span; float decay = 1.0 - (float)prev / (float)total * 0.5; int16_t oldY = MID_Y + (int16_t)(sin(radians(prev * step)) * amp * decay); // Keep the axes intact while erasing if (x == SCREEN_WIDTH / 2 - 1 || oldY == (int16_t)MID_Y) { TFT_display.drawPixel(x, oldY, BLUE); } else { TFT_display.drawPixel(x, oldY, BLACK); } } float decay = 1.0 - (float)i / (float)total * 0.5; int16_t y = MID_Y + (int16_t)(sin(radians(i * step)) * amp * decay); TFT_display.drawPixel(x, y, DIYables_TFT_SPI::colorRGB(255, 64, 255)); } return micros() - time_start; } // Draw a row of filled rectangles unsigned long show_fill_rectangle(void) { unsigned long time_start = micros(); int16_t size = shapeSize(); int16_t y = shapeY(size); uint16_t colors[] = { MAGENTA, RED, GREEN, BLUE, YELLOW }; for (uint8_t i = 0; i < SHAPE_COUNT; i++) { TFT_display.fillRect(shapeX(i, size), y, size, size, colors[i]); } return micros() - time_start; } // Draw a row of filled round rectangles unsigned long show_fill_round_rectangle(void) { unsigned long time_start = micros(); int16_t size = shapeSize(); int16_t y = shapeY(size); uint16_t colors[] = { MAGENTA, RED, GREEN, BLUE, YELLOW }; for (uint8_t i = 0; i < SHAPE_COUNT; i++) { TFT_display.fillRoundRect(shapeX(i, size), y, size, size, size / 5, colors[i]); } return micros() - time_start; } // Draw a row of filled circles unsigned long show_fill_circle(void) { unsigned long time_start = micros(); int16_t size = shapeSize(); int16_t r = size / 2; int16_t y = shapeY(size); uint16_t colors[] = { MAGENTA, RED, GREEN, BLUE, YELLOW }; for (uint8_t i = 0; i < SHAPE_COUNT; i++) { TFT_display.fillCircle(shapeX(i, size) + r, y + r, r, colors[i]); } return micros() - time_start; } // Draw a row of filled triangles unsigned long show_fill_triangle(void) { unsigned long time_start = micros(); int16_t size = shapeSize(); int16_t y = shapeY(size); uint16_t colors[] = { MAGENTA, RED, GREEN, BLUE, YELLOW }; for (uint8_t i = 0; i < SHAPE_COUNT; i++) { int16_t x = shapeX(i, size); TFT_display.fillTriangle( x, y + size - 1, // bottom left x + size / 2, y, // top x + size - 1, y + size - 1, // bottom right colors[i]); } return micros() - time_start; } // Draw grid lines pattern unsigned long show_grid_lines(void) { uint16_t i; unsigned long time_start = micros(); // Sweep the far end of each line across the full width as i walks down float k = (float)(SCREEN_WIDTH - 3) / (float)(BOT_Y - TOP_Y); for (i = TOP_Y; i < BOT_Y; i += 5) TFT_display.drawLine(1, i, 1 + (i - TOP_Y) * k, BOT_Y, RED); for (i = TOP_Y; i < BOT_Y; i += 5) TFT_display.drawLine(SCREEN_WIDTH - 2, i, SCREEN_WIDTH - 2 - (i - TOP_Y) * k, TOP_Y, RED); for (i = TOP_Y; i < BOT_Y; i += 5) TFT_display.drawLine(1, i, 1 + (i - TOP_Y) * k, TOP_Y, CYAN); for (i = TOP_Y; i < BOT_Y; i += 5) TFT_display.drawLine(SCREEN_WIDTH - 2, i, SCREEN_WIDTH - 2 - (i - TOP_Y) * k, BOT_Y, CYAN); return micros() - time_start; } // Draw some random pixels unsigned long show_random_pixels(void) { uint16_t i; unsigned long time_start = micros(); for (i = 0; i < 10000; i++) { TFT_display.drawPixel(randomX(), randomY(), DIYables_TFT_SPI::colorRGB(random(255), random(255), random(255))); } return micros() - time_start; } // Draw some random lines unsigned long show_random_lines(void) { uint16_t i; unsigned long time_start = micros(); for (i = 0; i < 300; i++) { TFT_display.drawLine(randomX(), randomY(), randomX(), randomY(), DIYables_TFT_SPI::colorRGB(random(255), random(255), random(255))); } return micros() - time_start; } // Draw some random rectangles unsigned long show_random_rectangles(void) { uint16_t i; unsigned long time_start = micros(); for (i = 0; i < 150; i++) { int16_t x1 = randomX(); int16_t y1 = randomY(); int16_t x2 = randomX(); int16_t y2 = randomY(); TFT_display.drawRect(min(x1, x2), min(y1, y2), abs(x2 - x1), abs(y2 - y1), DIYables_TFT_SPI::colorRGB(random(255), random(255), random(255))); } return micros() - time_start; } // Draw some random round rectangles unsigned long show_random_round_rectangles(void) { uint16_t i; unsigned long time_start = micros(); for (i = 0; i < 150; i++) { int16_t x1 = randomX(); int16_t y1 = randomY(); int16_t x2 = randomX(); int16_t y2 = randomY(); int16_t w = abs(x2 - x1); int16_t h = abs(y2 - y1); // A round rectangle needs room for the corner radius if (w < 12 || h < 12) continue; TFT_display.drawRoundRect(min(x1, x2), min(y1, y2), w, h, 5, DIYables_TFT_SPI::colorRGB(random(255), random(255), random(255))); } return micros() - time_start; } // Draw some random circles unsigned long show_random_circles(void) { uint16_t i; unsigned long time_start = micros(); int16_t r_max = AREA_H / 6; for (i = 0; i < 150; i++) { TFT_display.drawCircle( 2 + r_max + random(SCREEN_WIDTH - 4 - r_max * 2), TOP_Y + 1 + r_max + random(AREA_H - 2 - r_max * 2), random(r_max), DIYables_TFT_SPI::colorRGB(random(255), random(255), random(255))); } return micros() - time_start; } // Draw some random triangles unsigned long show_random_triangles(void) { uint16_t i; unsigned long time_start = micros(); for (i = 0; i < 150; i++) { TFT_display.drawTriangle( randomX(), randomY(), randomX(), randomY(), randomX(), randomY(), DIYables_TFT_SPI::colorRGB(random(255), random(255), random(255))); } return micros() - time_start; } // Clear the drawing area (inside the frame) void clear_screen(void) { delay(2000); TFT_display.fillRect(1, TOP_Y, SCREEN_WIDTH - 2, AREA_H, BLACK); } // Function pointer array and labels typedef unsigned long (*ShowFunc)(void); ShowFunc show_function[] = { show_text, show_triangle_function, show_sinewave, show_fill_rectangle, show_fill_round_rectangle, show_fill_circle, show_fill_triangle, show_grid_lines, show_random_pixels, show_random_lines, show_random_rectangles, show_random_round_rectangles, show_random_circles, show_random_triangles, }; #define NUM_TESTS 14 #define LABEL_LEN 32 // 30 visible chars + terminator, rounded up // Kept in flash so the sketch still fits the Uno R3's 2 KB of RAM const char show_str[NUM_TESTS][LABEL_LEN] PROGMEM = { "show text :", "show triangle function :", "show sinewave :", "show fill rectangle :", "show fill round rectangle :", "show fill circle :", "show fill triangle :", "show grid lines :", "show random pixels :", "show random lines :", "show random rectangles :", "show random round rectangles :", "show random circles :", "show random triangles :" }; // Run all tests and display timing results unsigned long show_total_time(void) { uint16_t i; unsigned long buf[NUM_TESTS]; unsigned long time_start = micros(); char strbuf[LABEL_LEN]; for (i = 0; i < NUM_TESTS; i++) { buf[i] = show_function[i](); clear_screen(); } // 14 result lines do not fit in 76 pixels: show them in pages of 7 int16_t x_off = (SCREEN_WIDTH - 260) / 2; if (x_off < 2) x_off = 2; const uint8_t per_page = 7; for (i = 0; i < NUM_TESTS; i++) { uint8_t line = i % per_page; if (line == 0) { if (i > 0) delay(5000); // let the previous page be read TFT_display.fillScreen(BLACK); } strcpy_P(strbuf, show_str[i]); TFT_display.setTextColor(ORANGE); TFT_display.setTextSize(1); TFT_display.setCursor(x_off, 4 + line * 10); TFT_display.print(strbuf); TFT_display.setTextColor(GREEN); TFT_display.setCursor(x_off + 185, 4 + line * 10); TFT_display.print(buf[i]); // Also print to Serial for easy comparison Serial.print(strbuf); Serial.print(F(" ")); Serial.print(buf[i]); Serial.println(F(" us")); } // Print total unsigned long total = 0; for (i = 0; i < NUM_TESTS; i++) total += buf[i]; Serial.print(F("Total (tests only): ")); Serial.print(total); Serial.println(F(" us")); Serial.println(); delay(5000); return micros() - time_start; } // Display ending screen with total time void show_end(unsigned long run_time) { TFT_display.fillScreen(CYAN); int16_t bw = 240, bh = SCREEN_HEIGHT - 6; if (bw > (int16_t)SCREEN_WIDTH - 10) bw = SCREEN_WIDTH - 10; TFT_display.fillRoundRect((SCREEN_WIDTH - bw) / 2, (SCREEN_HEIGHT - bh) / 2, bw, bh, 5, RED); int16_t cy = (SCREEN_HEIGHT - bh) / 2 + 6; printCentered("Running over!", cy, CYAN); printCentered("That's ok!", cy + 10, CYAN); printCentered("After a few seconds,", cy + 20, CYAN); printCentered("it will restart.", cy + 30, CYAN); printCentered("Please wait ...", cy + 40, CYAN); char line[40]; sprintf(line, "Total runtime(us): %lu", run_time); printCentered(line, cy + 52, YELLOW); delay(10000); } void setup() { Serial.begin(9600); TFT_display.begin(); TFT_display.setRotation(1); // landscape: 284 x 76 TFT_display.fillScreen(BLACK); SCREEN_WIDTH = TFT_display.width(); SCREEN_HEIGHT = TFT_display.height(); randomSeed(analogRead(A0)); } void loop() { unsigned long total_time; TFT_display.fillScreen(BLACK); total_time = show_total_time(); show_end(total_time); }

Detailed Instructions

  • Wire the display to the Nano ESP32 as shown in the wiring diagram above.
  • Connect the Nano ESP32 to your computer with a USB cable.
  • Open Arduino IDE, select the right board and port, paste the code, and click Upload.
  • Open the Serial Monitor at 9600 baud.
  • The screen runs the tests one by one, then shows the time of each test. The same times are printed on the Serial Monitor. After a few seconds, the test starts again.

Troubleshoot

If the code is not working, there are some common issues you can troubleshoot:

  • Screen stays black: The backlight is off. Check that BL is connected to GND, not to 3.3V. Then check VCC and GND.
  • Backlight is on but the screen stays white: The display does not receive commands. Check that SCL is on D13 and SDA is on D11, and that CS, DC and RST are on the pins defined in the code.
  • Picture is shifted, cut off, or has random pixels along the edges: The constructor must use the portrait size 76, 284 - not 284, 76 and not another size.
  • Colors look wrong, or the screen shows noise: Use the latest version of the DIYables_TFT_SPI library. If you use long jumper wires, try a lower SPI clock, for example TFT_display.begin(10000000);.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!