This guide focuses on interfacing a 160x80 pixel LCD module driven by the ST7735 controller with the ESP32-C3 using the Arduino framework. The module also integrates a 5‑axis directional joystick. We cover both display and joystick integration.
- Display Wiring Overview
The LCD module uses SPI communication. The following GPIO mapping is used on the ESP32‑C3 (verify your board’s pinout):
#define TFT_SCLK 2 // SPI clock
#define TFT_MOSI 3 // SPI data
#define TFT_RST 10 // Reset (RES)
#define TFT_DC 6 // Data/Command (DC)
#define TFT_CS 7 // Chip select (CS)
- Installing the Library
Open the Arduino Library Manager and search for Adafruit_ST7735. Install both the ST7735 driver and its dependency Adafruit_GFX.
- Basic LCD Test
The folowing minimal sketch initialises the display and draws a red background with blue text. Choose the correct initialiser for your module. For a 160x80 display with a plug‑in FPC (which may show inverted colours without the PLUGIN variant), use INITR_MINI160x80_PLUGIN.
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
// Pin assignments
#define TFT_SCLK 2
#define TFT_MOSI 3
#define TFT_RST 10
#define TFT_DC 6
#define TFT_CS 7
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
void setup(void) {
// Initialize for 160x80 mini display with plug‑in FPC
tft.initR(INITR_MINI160x80_PLUGIN);
tft.fillScreen(ST7735_RED);
tft.setTextColor(ST7735_BLUE);
tft.setTextSize(2);
tft.setCursor(12, 0);
tft.print("Hello");
}
void loop(void) {
// Nothing repeated
}
- Running the Adafruit Graphics Demo
The library encludes a comprehensive test sketch. You can load it from File→Examples→Adafruit ST7735→graphicstest. After adjusting the pin definitions and initialiser, the demo will draw lines, rectangles, circles, text, and more. Use the same initialiser as above.
(The full example code is omitted here for brevity; refer to the library’s example.)
- Joystick Integration
The module provides five push‑button directions: left, up, centre, down, and right. They are connected to the following ESP32‑C3 pins:
#define BUTTON_LEFT 5
#define BUTTON_UP 8
#define BUTTON_CENTER 4
#define BUTTON_DOWN 13
#define BUTTON_RIGHT 9
All buttons are active‑low; the internal pull‑up resistors are enabled. The sketch below displays the current button state on the LCD.
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#define TFT_SCLK 2
#define TFT_MOSI 3
#define TFT_RST 10
#define TFT_DC 6
#define TFT_CS 7
#define BUTTON_LEFT 5
#define BUTTON_UP 8
#define BUTTON_CENTER 4
#define BUTTON_DOWN 13
#define BUTTON_RIGHT 9
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
void setup(void) {
pinMode(BUTTON_LEFT, INPUT_PULLUP);
pinMode(BUTTON_UP, INPUT_PULLUP);
pinMode(BUTTON_CENTER, INPUT_PULLUP);
pinMode(BUTTON_DOWN, INPUT_PULLUP);
pinMode(BUTTON_RIGHT, INPUT_PULLUP);
Serial.begin(9600);
tft.initR(INITR_MINI160x80_PLUGIN);
tft.setRotation(3); // Portrait orientation
tft.fillScreen(ST7735_RED);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(2);
tft.setCursor(24, 0);
tft.print("Hello");
}
void loop(void) {
tft.fillScreen(ST7735_RED);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.setCursor(0, 24);
tft.println("Button Status:");
tft.print("LEFT: ");
tft.println(digitalRead(BUTTON_LEFT));
tft.print("UP: ");
tft.println(digitalRead(BUTTON_UP));
tft.print("CENTER: ");
tft.println(digitalRead(BUTTON_CENTER));
tft.print("DOWN: ");
tft.println(digitalRead(BUTTON_DOWN));
tft.print("RIGHT: ");
tft.println(digitalRead(BUTTON_RIGHT));
delay(100);
}
- Testing the Joystick
Upload the sketch and press each direction. The LCD updates the state in real time. A logic LOW indicates the button is presed.