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);
}
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