Xiao ESP32S3 display on 240*240 ST7789 SPI LCD/FT6236U cap. touch using TFT_eSPI in Arduino Framework.
This video show steps how Xiao ESP32S3 display on 1.54" 240*240 ST7789 SPI LCD using TFT_eSPI in Arduino Framework.
Connection:
TFT_eSPI https://github.com/Bodmer/TFT_eSPI
To setup, scroll down to "Tips" section:
XS3_ST7789_TFT_eSPI_color_touch.ino, Xiao ESP32S3 display on 240*240 ST7789 SPI LCD/FT6236U cap. touch using TFT_eSPI in Arduino Framework.
Related:
~ 240x240 ST7789V2 SPI IPS with FT6236 cap touch on XIAO ESP32S3 using GFX Library for Arduino.
Connection:
ST7789V2 Xiao ESP32S3
----------------------------
GND GND
VCC 3V3
SCL GPIO7
SDA GPIO9
RES GPIO1
DC GPIO2
CS GPIO3
BLK GPIO4
FT6236
----------------------------
SCL GPIO6
SDA GPIO5
INT GPIO43 (Not used)
RST GPIO44
Library used:TFT_eSPI https://github.com/Bodmer/TFT_eSPI
To setup, scroll down to "Tips" section:
Create a new folder in your Arduino library folder called "TFT_eSPI_Setups".
You then place your custom setup.h files in there.
Edit the User_Setup_Select.h file to point to your custom setup file.
Create my custom setup file, Setup_ST7789_XIAOESP32S3.h, under TFT_eSPI_Setups folder.
You then place your custom setup.h files in there.
Edit the User_Setup_Select.h file to point to your custom setup file.
Create my custom setup file, Setup_ST7789_XIAOESP32S3.h, under TFT_eSPI_Setups folder.
// Setup_ST7789_XIAOESP32S3.h in
// ..\Arduino\libraries\TFT_eSPI_Setups\
//
// Modify
// ..\Arduino\libraries\TFT_eSPI\User_Setup_Select.h to load it.
// #include <../TFT_eSPI_Setups/Setup_ST7789_XIAOESP32S3.h>
#define ST7789_DRIVER
#define TFT_WIDTH 240
#define TFT_HEIGHT 240
// TFT_MOSI/TFT_SCLK for default SPI pin assignment
#define TFT_MISO -1
#define TFT_MOSI 9
#define TFT_SCLK 7
#define TFT_CS 3
#define TFT_DC 2
#define TFT_RST 1
#define TFT_BL 4 // LED back-light control pin
#define TFT_BACKLIGHT_ON HIGH // Level to turn ON back-light (HIGH or LOW)
//#define SPI_FREQUENCY 27000000
#define SPI_FREQUENCY 40000000
// In my test on Xiao ESP32S3, have to define USE_HSPI_PORT.
//
// The ESP32 has 2 free SPI ports i.e. VSPI and HSPI, the VSPI is the default.
// If the VSPI port is in use and pins are not accessible (e.g. TTGO T-Beam)
// then uncomment the following line:
#define USE_HSPI_PORT
////////////////////////////////////////////////////////////////////////////////////////////
// Fonts to be available
////////////////////////////////////////////////////////////////////////////////////////////
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
#define SMOOTH_FONT
Edit the User_Setup_Select.h file to point to your custom setup file.#include <../TFT_eSPI_Setups/Setup_ST7789_XIAOESP32S3.h>
XS3_ST7789_TFT_eSPI_color_touch.ino, Xiao ESP32S3 display on 240*240 ST7789 SPI LCD/FT6236U cap. touch using TFT_eSPI in Arduino Framework.
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
#include <Wire.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define CTP_INT 43
#define CTP_RST 44
#define FT6236U_ADDR 0x38
#define DISP_WIDTH 240
#define DISP_HEIGHT 240
void setup() {
tft.init();
tft.fillScreen(TFT_WHITE);
tft.fillRect(5, 5, tft.width()-10, tft.height()-10, TFT_DARKGREY);
// Hardware Reset on CTP_RST
Wire.begin(); // I2C
delay(100);
pinMode(CTP_RST, OUTPUT);
digitalWrite(CTP_RST, HIGH);
delay(100);
digitalWrite(CTP_RST, LOW);
delay(100);
digitalWrite(CTP_RST, HIGH);
delay(100);
}
void loop() {
if (get_touch_count() > 0) {
int x, y;
get_touch_point(&x, &y);
tft.fillCircle(x, y, 1, TFT_YELLOW);
}
delay(10);
}
int get_touch_count() {
// Register 0x02
// Touch count, max 2.
Wire.beginTransmission(FT6236U_ADDR);
Wire.write(0x02);
Wire.endTransmission();
Wire.requestFrom(FT6236U_ADDR, 1);
return (Wire.read());
}
// Read x, y
// May be have to exchange/adjust x, y according to screen rotation.
void get_touch_point(int *x, int *y) {
// Read X:
// Register 0x03
// bit7-bit6 Touch event of the 1st touch point
// bit3-bit0 Hight 4 bit of the 1st touch point
// Register 0x04
// Low 8 bit of the 1st touch point
Wire.beginTransmission(FT6236U_ADDR);
Wire.write(0x03);
Wire.endTransmission();
Wire.requestFrom(FT6236U_ADDR, 2);
*x = (Wire.read() & 0x0f) << 8 | Wire.read();
*x = DISP_WIDTH - *x;
// Read Y:
// Register 0x05
// bit7-bit6 ID of the 1st touch point
// bit3-bit0 Hight 4 bit of the 1st touch point
// Register 0x06
// Low 8 bit of the 1st touch point
Wire.beginTransmission(FT6236U_ADDR);
Wire.write(0x05);
Wire.endTransmission();
Wire.requestFrom(FT6236U_ADDR, 2);
*y = (Wire.read() & 0x0f) << 8 | Wire.read();
*y = DISP_WIDTH - *y;
}
Related:
~ 240x240 ST7789V2 SPI IPS with FT6236 cap touch on XIAO ESP32S3 using GFX Library for Arduino.
Comments
Post a Comment