Waveshare ESP32-S3-Touch-LCD-4B Hello World
Basic Test run on Waveshare ESP32-S3-Touch-LCD-4B, with built-in 4inch 480 × 480 resolution ST7701 RGB interface LCD.
S3_ST7701_basictest.ino
/*
Basic test run on Waveshare ESP32-S3-Touch-LCD-4B
https://coxxect.blogspot.com/2026/06/waveshare-esp32-s3-touch-lcd-4b-hello.html
Remark about "USB CDC On Boot" option for Serial.print()
If host PC connect to USB TO UART port (lower one), select USB CDC On Boot: "Disabled".
If connect to ESP32-S3 USB Interface port (middle one), select USB CDC On Boot: "Enabled"
Otherwise, you cannot see the output by Serial.print().
*/
#include <Arduino.h>
#include "Arduino_GFX_Library.h"
#define BL 4
Arduino_XCA9554SWSPI *expander = new Arduino_XCA9554SWSPI(
7,
0,
2,
1,
&Wire,
0x20);
Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
17 /* DE */, 3 /* VSYNC */, 46 /* HSYNC */, 9 /* PCLK */,
10 /* B0 */, 11 /* B1 */, 12 /* B2 */, 13 /* B3 */, 14 /* B4 */,
21 /* G0 */, 8 /* G1 */, 18 /* G2 */, 45 /* G3 */, 38 /* G4 */, 39 /* G5 */,
40 /* R0 */, 41 /* R1 */, 42 /* R2 */, 2 /* R3 */, 1 /* R4 */,
1 /* hsync_polarity */, 10 /* hsync_front_porch */, 8 /* hsync_pulse_width */, 50 /* hsync_back_porch */,
1 /* vsync_polarity */, 10 /* vsync_front_porch */, 8 /* vsync_pulse_width */, 20 /* vsync_back_porch */);
Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
480 /* width */, 480 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */,
expander, GFX_NOT_DEFINED /* RST */, st7701_type1_init_operations, sizeof(st7701_type1_init_operations));
void setup(void) {
delay(2000);
Serial.begin(115200);
delay(1000);
Wire.begin(47, 48);
pinMode(BL, OUTPUT);
digitalWrite(BL, LOW); //Turn On Backlight
expander->pinMode(5, OUTPUT);
expander->pinMode(6, OUTPUT);
expander->digitalWrite(6, LOW);
delay(200);
expander->digitalWrite(5, LOW);
delay(200);
expander->digitalWrite(5, HIGH);
delay(200);
Serial.println("\n====================================");
Serial.println("Arduino_GFX Hello World example");
Serial.println("Waveshare ESP32-S3-Touch-LCD-4B");
Serial.println("====================================");
// Init Display
if (!gfx->begin()) {
Serial.println("gfx->begin() failed!");
}
Serial.println("gfx->begin() successed!");
gfx->fillScreen(RGB565_BLACK);
gfx->drawRect(0, 0, gfx->width()-1, gfx->height()-1, RGB565_WHITE);
gfx->setTextColor(RGB565_WHITE);
gfx->setTextSize(4 /* x scale */, 4 /* y scale */, 2 /* pixel_margin */);
//===
const char *msg = "Hello";
int16_t x1, y1; // top-left corner of bounding box
uint16_t w, h; // width and height of text
// Measure the text with current font/size
gfx->getTextBounds(msg, 0, 0, &x1, &y1, &w, &h);
// Compute centered X position
int16_t x = (gfx->width() - w) / 2;
int16_t y = 50; // vertical position you want
gfx->setCursor(x, y);
gfx->println(msg);
//===
gfx->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
gfx->println("\n Waveshare ESP32-S3-Touch-LCD-4B");
gfx->println();
gfx->setTextSize(3 /* x scale */, 3 /* y scale */, 6 /* pixel_margin */);
// Get Chip and version
Serial.printf("Chip model: %s\n", ESP.getChipModel());
Serial.printf("Chip revision: %d\n", ESP.getChipRevision());
gfx->printf(" Chip model: %s\n", ESP.getChipModel());
gfx->printf(" Chip revision: %d\n", ESP.getChipRevision());
// Get ESP-IDF Version
// This returns the version of the SDK the core was built on (e.g., "v5.1.0")
Serial.print("ESP-IDF Version: ");
Serial.println(esp_get_idf_version());
gfx->print(" ESP-IDF Version: ");
gfx->println(esp_get_idf_version());
#ifdef ESP_ARDUINO_VERSION_STR
Serial.print("Arduino-ESP32 Core Version (String): ");
Serial.println(ESP_ARDUINO_VERSION_STR);
gfx->print(" Arduino-ESP32: ");
gfx->println(ESP_ARDUINO_VERSION_STR);
#else
Serial.println("ESP_ARDUINO_VERSION_STR not defined (Legacy core).");
#endif
Serial.println("--------------------------");
delay(8000); // 8 seconds
}
#define num_of_color 5
int color[num_of_color] = {RGB565_RED, RGB565_GREEN, RGB565_BLUE, RGB565_WHITE, RGB565_BLACK};
String color_name[num_of_color] = {"RED", "GREEN", "BLUE", "WHITE", "BLACK"};
int color_index = 0;
void loop() {
unsigned long startTime, stopTime;
//
startTime = millis();
gfx->fillScreen(color[color_index]);
gfx->drawRect(0, 0, gfx->width()-1, gfx->height()-1, color[color_index]^0xFFFF);
gfx->setTextColor(color[color_index]^0xFFFF);
gfx->setCursor(100, 100);
gfx->setTextSize(5 /* x scale */, 5 /* y scale */, 5 /* pixel_margin */);
gfx->println(color_name[color_index]);
stopTime = millis();
gfx->setCursor(100, 160);
gfx->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
gfx->printf("Arduino_RGB_Display");
gfx->setCursor(100, 210);
gfx->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
gfx->printf("%i ms", stopTime-startTime);
color_index++;
if (color_index==num_of_color){
color_index = 0;
}
delay(3000);
}
Comments
Post a Comment