• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ST7796S MSP4021 320 x 480 TFT

Q&A Forum › Category: ESP32 › ST7796S MSP4021 320 x 480 TFT
0 Vote Up Vote Down
David Fenner asked 1 week ago

I have a ST7796S MSP4021 320 x 480 TFT resistive touch screen being controlled by a ESP32
Could you help with the following problem:-
I thought it would be a could idea to use the following very basic example to test out a new display.
But I am having trouble with getting the LCD to display the correct colours, while it displays a rectangle it is not in red but yellow, Black is white and Blue is displayed as Cyan.
I have used RGB and BGR commands that did not sort the problems out.
Note1:- The screen resolution, rectangle and display orientation can all be adjusted correctly.
Note2;- I did think that this board had a 4-wire SPI interface but the example uses 3
Example
#include <Adafruit_GFX.h>    // Graphics library
// #include <Adafruit_ST7796.h> // ST7796 driver library
#include <Adafruit_ST7796S.h> // ST7796 driver library
// #include <Adafruit_ST77xx.h> // just for colo defs
 
// Define pin connections
#define TFT_CS    15  
#define TFT_RST   4
#define TFT_DC    2  
// #define TFT_MOSI  23  // SDA // HW MOSI
// #define TFT_SCLK  18  // SCL // HW SCLK
// #define TFT_MISO  19  // HW MISO
 
// Create an instance of the ST7796 display
 
Adafruit_ST7796S tft = Adafruit_ST7796S(TFT_CS, TFT_DC, TFT_RST);
void setup() {
  // Initialize serial communication for debugging
  Serial.begin(9600);
  Serial.println(“Initializing ST7796…”);
 
  // Initialize the display
 
  tft.init(320, 480); // Set resolution (e.g., 240×320)
 // tft.init(320, 480, ST7796S_RGB); // Set resolution (e.g., 240×320)
 // tft.init(320, 480, ST7796S_BGR); // Set resolution (e.g., 240×320)
  tft.setRotation(1); // Set display orientation (0-3)
 
  // Fill the screen with a color
  tft.fillScreen(ST77XX_BLUE);
 
  Serial.println(“Display initialized!”);
}
 
void loop() {
  // Draw a red rectangle
  tft.fillRect(50, 50, 100, 100, ST77XX_RED);
 
  // Add a delay
  delay(2000);
 
  // Clear the screen
  tft.fillScreen(ST77XX_BLACK);
 
  delay(2000);
}

1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 days ago

Hi.
The TFT_esPI library has a sample code to test and diagnose the display.
In your Arduino IDE, if you go to File > Examples > TFT_eSPI > Test and Diagnostics, there are several diagnostic tests. One of them is related to color.
 
You can run that example and see if you get more information that can help you diagnose the issue.
 
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn LVGL: Build GUIs for ESP32 Projects – Version 1.5 July 7, 2025
  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.