Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

RTL8720DN-Based Interactive Button-Controlled TFT Display

View and Edit Project In Cirkit DesignerImage of RTL8720DN-Based Interactive Button-Controlled TFT Display

Circuit Documentation

Summary

This circuit involves an RTL8720DN microcontroller interfaced with a China ST7735S 160x128 TFT LCD display and four pushbuttons. The microcontroller reads the states of the pushbuttons and displays their statuses on the TFT LCD. The circuit is designed to demonstrate basic input reading and display output using an embedded system.

Component List

  1. RTL8720DN Microcontroller

    • Description: A low-power, high-performance microcontroller with multiple GPIO pins.
    • Pins: PA15(pin4), CHIP-EN, 3V3, GND, PA12(pin12), PA30(pin3), PA27(pin2), PA14(pin10), PA13(pin11), PA8(pin1), PA26(pin8), NC, VIN, PB2(pin5), PA7(pin0), PA25(pin7), PB3(pin6), PB1(pin4)
  2. Pushbutton (4 instances)

    • Description: A simple pushbutton used for user input.
    • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)
  3. China ST7735S 160x128 TFT LCD Display

    • Description: A 160x128 pixel TFT LCD display module.
    • Pins: GND, VCC, SCL, SDA, RES, DC, CS, BL

Wiring Details

RTL8720DN Microcontroller

Pushbutton 1

Pushbutton 2

Pushbutton 3

Pushbutton 4

China ST7735S 160x128 TFT LCD Display

Code Documentation

#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>

// Pin Definition for LCD
#define TFT_SCLK PA14 // clock
#define TFT_MOSI PA12 // data
#define TFT_RES PA26 // reset
#define TFT_DC PA25 // data/command
#define TFT_CS PA27 // chip select
#define TFT_BL PA30 // backlight

// button pin definition
#define BUTTON_1 PB1
#define BUTTON_2 PB3
#define BUTTON_3 PB2
#define BUTTON_4 PA13

// create TFT LCD object
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RES);

void setup() {
  // initialize serial monitor
  Serial.begin(115200);

  // initialize buttons as input
  pinMode(BUTTON_1, INPUT_PULLUP);
  pinMode(BUTTON_2, INPUT_PULLUP);
  pinMode(BUTTON_3, INPUT_PULLUP);
  pinMode(BUTTON_4, INPUT_PULLUP);

  // initialize backlight as output
  pinMode(TFT_BL, OUTPUT);
  digitalWrite(TFT_BL, HIGH); // turn on backlight

  // initialize TFT LCD
  tft.initR(INITR_BLACKTAB); // initialize with ST7735 black tab
  tft.fillScreen(ST77XX_BLACK);
  tft.setRotation(1); // set rotation
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(1);

  // welcome message
  tft.setCursor(0, 0);
  tft.println("TFT LCD Initialized!");
  tft.println("Buttons Ready");
}

void loop() {
  // read button states
  bool button1State = digitalRead(BUTTON_1) == LOW;
  bool button2State = digitalRead(BUTTON_2) == LOW;
  bool button3State = digitalRead(BUTTON_3) == LOW;
  bool button4State = digitalRead(BUTTON_4) == LOW;

  // display button states on TFT
  tft.fillRect(0, 20, 128, 140, ST77XX_BLACK); // clear previous text
  tft.setCursor(0, 20);

  tft.println("Button States:");
  tft.println("Button 1: "); tft.println(button1State ? "PRESSED" : "RELEASED");
  tft.println("Button 2: "); tft.println(button2State ? "PRESSED" : "RELEASED");
  tft.println("Button 3: "); tft.println(button3State ? "PRESSED" : "RELEASED");
  tft.println("Button 4: "); tft.println(button4State ? "PRESSED" : "RELEASED");

  // add a small delay to avoid flickering
  delay(100);
}

This code initializes the TFT LCD and the pushbuttons, reads the states of the pushbuttons, and displays their statuses on the TFT LCD. The backlight of the TFT LCD is also controlled by the microcontroller.