การตั้งค่าไลบรารี่ TFT_eSPI
ไลบรารี่ TFT_eSPI เป็นไลบรารี่สำหรับเขียนโปรแกรมสั่งงานหน้าจอ ที่รองรับหน้าจอหลากหลายรุ่น รวมถึงหน้าจอที่ IOXESP32 Display Adapter shield รองรับด้วย ทั้งนี้ก่อนใช้งานไลบรารี่ต้องตั้งค่าไลบรารี่ก่อน เพื่อให้ไลบราที่สื่อสารกับหน้าจอได้ถูกต้อง
ขั้นตอนการใช้งานไลบรารี่ TFT_eSPI อ่านได้ตามบทความด้านล่างนี้
จากบทความ ในหัวข้อ การตั้งค่าไลบรารี่ TFT_eSPI มีขั้นตอนที่แตกต่างจากบทความดังนี้
การตั้งค่าไลบรารี่ TFT_eSPI ใช้งานกับจอ ILI9341
จอ LCD ที่ใช้ไอซี ILI9341 มี 2 ขนาด คือ ขนาด 2.8 นิ้ว และขนาด 3.2 นิ้ว ทัชสกรีนแบบ Capacitive (บอร์ดดำ) ไอซี Touch Screen Controller เบอร์ FT6336U ให้แก้ไขไฟล์ต่าง ๆ ดังนี้
ไฟล์ User_Setup_Select.h ให้ค้นหาบรรทัด #include <user_setup.h>
แล้วเพิ่มเครื่องหมาย Comment (//
) เข้าไปที่หน้าบรรทัด
แล้วค้นหาบรรทัด #include <User_Setups/Setup1_ILI9341.h>
แล้วลบเครื่องหมาย Comment (//
) หน้าบรรทัดนั้นออก แล้วบันทึกไฟล์

จากนั้นเปิดไฟล์ Setup1_ILI9341.h ที่อยู่ในโฟลเดอร์ User_Setups ขึ้นมา แล้วคัดลอกโค้ดโปรแกรมต่อไปนี้ ไปวางทับโค้ดทั้งไฟล์ บันทึกไฟล์ให้เรียบร้อย แล้วปิดโปรแกรม Text Editor ไปได้เลย
// See SetupX_Template.h for all options available
#define ILI9341_DRIVER
#define TFT_MISO 19 // (leave TFT SDO disconnected if other SPI devices share MISO)
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS 5 // Chip select control pin D8
#define TFT_DC 2 // Data Command control pin
// #define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line)
#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V
#define TOUCH_CS -1 // Chip select pin (T_CS) of touch screen
#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
// #define SPI_FREQUENCY 27000000
#define SPI_FREQUENCY 40000000
#define SPI_READ_FREQUENCY 20000000
#define SPI_TOUCH_FREQUENCY 2500000
// #define SUPPORT_TRANSACTIONS
การตั้งค่าไลบรารี่ TFT_eSPI ใช้งานกับจอ ST7796S แบบ SPI
LCD ขนาด 3.5 นิ้ว แบบมีทัช Capacitive (บอร์ดดำ) ไอซี Touch Screen Controller เบอร์ FT6336U ให้แก้ไขไฟล์ต่าง ๆ ดังนี้
ไฟล์ User_Setup_Select.h ให้ค้นหาบรรทัด #include <user_setup.h>
แล้วเพิ่มเครื่องหมาย Comment (//
) เข้าไปที่หน้าบรรทัด
แล้วค้นหาบรรทัด #include <User_Setups/Setup43_ST7735.h>
ลบเครื่องหมาย Comment (//) หน้าบรรทัดออก แล้วบันทึกไฟล์

จากนั้นเปิดไฟล์ Setup43_ST7735.h ที่อยู่ในโฟลเดอร์ User_Setups ขึ้นมา แล้วคัดลอกโค้ดโปรแกรมต่อไปนี้ ไปวางทับโค้ดทั้งไฟล์ บันทึกไฟล์ให้เรียบร้อย แล้วปิดโปรแกรม Text Editor ไปได้เลย
// See SetupX_Template.h for all options available
#define ST7796_DRIVER
#define TFT_MISO 19 // (leave TFT SDO disconnected if other SPI devices share MISO)
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS 5 // Chip select control pin D8
#define TFT_DC 2 // Data Command control pin
#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V
#define TOUCH_CS -1 // Chip select pin (T_CS) of touch screen
#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_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
#define SMOOTH_FONT
// #define SPI_FREQUENCY 20000000
#define SPI_FREQUENCY 40000000
#define SPI_READ_FREQUENCY 20000000
#define SPI_TOUCH_FREQUENCY 2500000
// #define SUPPORT_TRANSACTIONS
Last updated
Was this helpful?