娇小w搡bbbb搡bbb,《第一次の人妻》,中国成熟妇女毛茸茸,边啃奶头边躁狠狠躁视频免费观看

玩轉 ESP32 + Arduino(二十八) TFT_eSPI庫驅動ST7789(SPI接口)

發布者:MysticGarden最新更新時間:2025-04-02 來源: jianshu關鍵字:ESP32  Arduino  SPI接口 手機看文章 掃描二維碼
隨時隨地手機看文章

我們用到的庫 TFT_eSPI

一. 硬件接線

這里我們使用了中景園的ST7789

一般屏幕的引腳定義如下:

接線: 我們直接用VSPI接線

ESP32引腳ST7789引腳功能
GNDGND接地
3V3VCC電源
(VCLK)18SCLSPI時鐘
(VMOSI)23SDASPI主出從入線
26RES復位引腳
27DC數據/命令選擇線
(VCS0)5CSSPI片選線
沒接BLK背光控制線

如何在TFT_eSPI中設置引腳??

首先, 我們打開 User_Setup.h, 具體位置在(platformIO平臺):

然后根據文件中的提示設置就可以了, 對于ESP32 + ST7789來說, 具體修改了如下內容:

第一步: 修改自定義驅動文件

在眾多的驅動文件中,選擇適合自己屏幕的, 注釋掉不用的

設置寬高

對ST7789 ST7735 ILI9163來說, 要設置寬高

第二步: 引腳定義

注釋掉其他的定義, 定義自己的引腳

第三步.第四步保持默認, 需要時再修改就可以

第三步是配置字庫, ESP32內存足夠, 不用配置了,都帶著就行
第四步是 配置SPI的頻率 / 配置用VSPI(默認)還是HSPI /

額外的一步: User_Setup_Select.h中選擇用戶自定義配置

因為上面我們的設置是自定義設置, 所以在User_Setup_Select.h中, 應啟用自定義配置, 注釋其他配置文件

二. 顏色和字體

1.關于顏色

關于顏色值, TFT一般都使用16位的RGB565顏色,在本庫中, 典型顏色已經定義好了:


/***************************************************************************************

*                         Section 6: Colour enumeration

***************************************************************************************/// Default color definitions#define TFT_BLACK       0x0000      /*   0,   0,   0 */#define TFT_NAVY        0x000F      /*   0,   0, 128 */#define TFT_DARKGREEN   0x03E0      /*   0, 128,   0 */#define TFT_DARKCYAN    0x03EF      /*   0, 128, 128 */#define TFT_MAROON      0x7800      /* 128,   0,   0 */#define TFT_PURPLE      0x780F      /* 128,   0, 128 */#define TFT_OLIVE       0x7BE0      /* 128, 128,   0 */#define TFT_LIGHTGREY   0xD69A      /* 211, 211, 211 */#define TFT_DARKGREY    0x7BEF      /* 128, 128, 128 */#define TFT_BLUE        0x001F      /*   0,   0, 255 */#define TFT_GREEN       0x07E0      /*   0, 255,   0 */#define TFT_CYAN        0x07FF      /*   0, 255, 255 */#define TFT_RED         0xF800      /* 255,   0,   0 */#define TFT_MAGENTA     0xF81F      /* 255,   0, 255 */#define TFT_YELLOW      0xFFE0      /* 255, 255,   0 */#define TFT_WHITE       0xFFFF      /* 255, 255, 255 */#define TFT_ORANGE      0xFDA0      /* 255, 180,   0 */#define TFT_GREENYELLOW 0xB7E0      /* 180, 255,   0 */#define TFT_PINK        0xFE19      /* 255, 192, 203 */ //Lighter pink, was 0xFC9F      #define TFT_BROWN       0x9A60      /* 150,  75,   0 */#define TFT_GOLD        0xFEA0      /* 255, 215,   0 */#define TFT_SILVER      0xC618      /* 192, 192, 192 */#define TFT_SKYBLUE     0x867D      /* 135, 206, 235 */#define TFT_VIOLET      0x915C      /* 180,  46, 226 */

2. RGB顏色轉565顏色 tft.color565()

uint16_t red =    tft.color565(255, 0, 0);uint16_t green =  tft.color565(0, 255, 0);uint16_t blue =   tft.color565(0, 0, 255);uint16_t yellow = tft.color565(255, 255, 0);tft.fillScreen(tft.color565(128, 0, 128));  //使用

3. 關于半透明 tft.alphaBlend()

在填入顏色的地方填入此函數可以開啟alpha半透明通道


  for (uint16_t a = 0; a < 255; a++) // Alpha 0 = 100% background, alpha 255 = 100% foreground

  {

    //tft.drawFastHLine(192, a, 12, tft.alphaBlend(a, TFT_BLACK, TFT_WHITE));

    tft.drawFastHLine(204, a, 12, tft.alphaBlend(a, TFT_RED,   TFT_WHITE));

    tft.drawFastHLine(216, a, 12, tft.alphaBlend(a, TFT_GREEN, TFT_WHITE));

    tft.drawFastHLine(228, a, 12, tft.alphaBlend(a, TFT_BLUE,  TFT_WHITE));

  }

4. 關于默認字體

編號范圍是 1、2、4、6、7、8,不同的編號代表不同的字體, 不同的字體由于分辨率不同, 基本大小不同


// Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH#define LOAD_GLCD// Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters#define LOAD_FONT2// Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters#define LOAD_FONT4// Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm#define LOAD_FONT6// Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.#define LOAD_FONT7// Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.#define LOAD_FONT8// Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT//#define LOAD_FONT8N// FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts#define LOAD_GFXFF// Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded// this will save ~20kbytes of FLASH#define SMOOTH_FONT

5. 關于自定義字體

TFT_eSPI自帶了很多自定義庫, 而且也可以自己去生成新的自定義庫.


默認的自定義字體庫在:

如果想學習自定義字庫用法, 請參看例程:

三. 相關API

1. tft.init(); //初始化

初始化屏幕, 如果是ST7735,可以往里面傳一個參數, 具體用到時再看


2. tft.fillScreen(TFT_BLACK); //填充全屏幕

填充全屏幕, 后面是顏色值,


tft.fillScreen(uint32_t color);

3. 屏幕旋轉

// 設置屏幕顯示的旋轉角度,參數為:0, 1, 2, 3// 分別代表 0°、90°、180°、270°void setRotation(uint8_t r); 

4. 屏幕反色

//反轉顯示顏色i = 1反轉,i = 0正常tft.invertDisplay(bool i);

四. 文字相關API

1. tft.setCursor(20, 10, 4); //設置打字起始坐標位置和字號

 // 設置文本顯示坐標,默認以文本左上角為參考點,可以改變參考點void setCursor(int16_t x, int16_t y);// 設置文本顯示坐標,和文本的字體void setCursor(int16_t x, int16_t y, uint8_t font); 

2. tft.setTextColor(2); //設置字體顏色

// 設置文本顏色void setTextColor(uint16_t color);// 設置文本顏色與背景色void setTextColor(uint16_t fgcolor, uint16_t bgcolor);

設置背景顏色可以有效的防止數字疊在一起


3. tft.setTextSize(2); //設置字體大小

設置文本大小可以放大字體的顯示,但是字體的'分辨率'是不會變的


// 設置文本大小,文本大小范圍為 1~7 的整數void setTextSize(uint8_t size);

4. tft.print('Hello World!'); // 顯示字體

tft.print('Hello World!');

5.  tft.printf,  tft.println  //顯示字體

特別注意: 字庫7是仿7段數碼屏的樣式


五. 繪制文字相關API

1. 繪制字符串(居左)

int16_t drawString(const String &string, int32_t x, int32_t y)int16_t drawString(const char *string, int32_t x, int32_t y)int16_t drawString(const String &string, int32_t x, int32_t y, uint8_t font)int16_t drawString(const char *string, int32_t x, int32_t y, uint8_t font)

2. 繪制字符串(居中)

int16_t drawCentreString(const char *string, int32_t x, int32_t y, uint8_t font)int16_t drawCentreString(const String &string, int32_t x, int32_t y, uint8_t font)

3. 繪制字符串(居右)

int16_t drawRightString(const char *string, int32_t x, int32_t y, uint8_t font)int16_t drawRightString(const String &string, int32_t x, int32_t y, uint8_t font)

4. 繪制字符

int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y)int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font)void drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size)

5. 繪制浮點數

int16_t TFT_eSPI::drawFloat(float floatNumber, uint8_t decimal, int32_t x, int32_t y)int16_t TFT_eSPI::drawFloat(float floatNumber, uint8_t decimal, int32_t x, int32_t y, uint8_t font)

  tft.drawFloat(3.124, 4, 0,0,4);

6. 繪制數字

int16_t drawNumber(long intNumber, int32_t x, int32_t y)int16_t drawNumber(long intNumber, int32_t x, int32_t y, uint8_t font)

7. 繪制

六. 繪制幾何圖形

1. 畫點

void drawPixel(int32_t x, int32_t y, uint32_t color)

2.畫線

void drawLine(int32_t xs, int32_t ys, int32_t xe, int32_t ye, uint32_t color)

3.畫橫線(快速)

void drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color)

4.畫豎線(快速)

void drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color)

5. 畫空心圓

tft.drawCircle(100,100,50,TFT_RED);

6. 畫實心圓

void fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color)

7. 畫空心橢圓

tft.drawEllipse(100,100,100,60,TFT_GREENYELLOW);

8. 畫實心橢圓

void drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)

9. 畫空心矩形

void drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)

10. 畫實心矩形

void fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)

11. 畫空心圓角矩形

void drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color)

12. 畫實心圓角矩形

void fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color)

13. 畫空心三角形

void drawTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, uint32_t color)

14. 畫實心三角形

void fillTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, uint32_t color)

七. 圖片顯示相關

1. 顯示BMP圖片

void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor)void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor)

2. XBM

xbm是一種簡單的雙色圖片位圖格式,在早期的cgi中運用較多,目前多用于計數器


這里TFT_eSPI推薦了一個在線XBM制作工具:

https://www.online-utility.org/image/convert/to/XBM

實測非常好用


void drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor)void drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor)

3. 顯示圖片

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data)void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data)void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transparent)void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data, uint16_t transparent)void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, bool bpp8 = true, uint16_t *cmap = (uint16_t *)nullptr)void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, uint8_t transparent, bool bpp8 = true, uint16_t *cmap = (uint16_t *)nullptr)



關鍵字:ESP32  Arduino  SPI接口 引用地址:玩轉 ESP32 + Arduino(二十八) TFT_eSPI庫驅動ST7789(SPI接口)

上一篇:玩轉 ESP32 + Arduino(二十九) TFT_eSPI庫驅動ST7789之動畫專題
下一篇:玩轉 ESP32 + Arduino(二十七) ESP對象

推薦閱讀最新更新時間:2025-04-09 10:05

玩轉 ESP32 + Arduino (十四) HTTPClient訪問網絡資源
我們使用ESP32_Arduino自帶庫: HTTPClient 一. 請求相關API函數 首先,創建一個客戶端對象 1. 初始化HTTP客戶端 http_client.begin() /** * 解析url以獲得所有參數,默認port是80端口 * @param url String */bool begin(String url);/** * 解析url以獲得所有參數,默認port是80端口 * @param client : 傳入一個網絡連接客戶端 * @param url String */bool begin(WiFiClient &client, String url);/** * 設置host
[單片機]
25.SPI接口原理與配置
一。 SPI接口原理 主機給從機發送8個位的同時,從機也給主機傳回8個位,即一個字節 時鐘信號的相位和極性由SPI_CR寄存器的CPOL和CPHA位來控制,能夠組成4種時序關系。 CPHA控制在時鐘的第幾個邊沿數據被采集。 CPOL= 1 說明時鐘信號在空閑時是高電平。 CPOL= 0 說明時鐘信號在空閑時是低電平。 CPHA= 1,在時鐘信號的第二個邊沿數據被采集。 CPHA= 0 時表示數據在時鐘信號的第一個邊沿被采集。 注:要根據從機的相位和極性來配置主機的相位和極性。主機要與從機匹配。 SPI引腳配置模式: 二。 SPI寄存器函數配置 1.
[單片機]
25.<font color='red'>SPI接口</font>原理與配置
基于ESP32構建一個具有3.5英寸大顯示屏的互聯網廣播設備
在這個項目中,我將使用便宜的 ESP32 板構建一個具有 3.5 英寸大顯示屏的互聯網廣播設備。 你可能不太相信,在這個項目,我們能夠以不到 10 分鐘的時間內并且用不到 30 美元的成本構建一個網絡收音機。接下來讓我們開始吧! 幾個月前,我完成了一個Arduino FM Radio 項目,效果很好。問題是,雖然那臺收音機看起來很酷,但它并不實用,我住的地方發射信號并不好。所以,我在筆記本電腦或平板電腦上在線收聽我最喜歡的收音機,但這也不太實用。所以,今天我要構建一個網絡廣播設備,以便能夠收聽來自世界各地的我最喜歡的廣播電臺! 我已經收聽了真正的 FM 廣播電臺,通過使用這些按鈕,我們可以更改我們正在收聽的廣播電臺。我
[嵌入式]
基于<font color='red'>ESP32</font>構建一個具有3.5英寸大顯示屏的互聯網廣播設備
w806(基于Arduino)——點亮LED燈
一、搭建Arduino環境 1、安裝Arduino IDE 1)下載Arduino IDE Arduino官網地址:Arduino Docs | Arduino Documentation | Arduino Documentation 2)安裝Arduino IDE 打開安裝包一路next即可。 2、在Arduino IDE上安裝W806庫 1)添加開發板管理器網址 打開Arduino IDE,依次打開 文件 - 首選項,在“附加開發板管理器網址”一欄添加以下網址。 https://cdn.jsdelivr.net/gh/Hi-LinkDuino/w80x_arduino/package_w80x_proxy_ind
[單片機]
w806(基于<font color='red'>Arduino</font>)——點亮LED燈
Arduino最小系統板作AVR單片機的編程器
用Arduino編程具有簡單易學的特點,但要配合Arduino控制板使用,使得成本比較高,體積也大,而且除單片機電路以外的大部分電路只在編程時有用,在電子制作上使用后就是多余的了,造成了浪費。能不能不用Arduino控制板,直接想辦法用Arduino給單片機編程呢?答案是肯定的,只要做一個Arduino最小系統板,配合ISP下載線USBtinyISP或USBasp 就可以給AVR單片機下載程序了,Arduino最小系統板有一個鎖緊座,方便單片機插上和取下,下載好程序的單片機就可以取下裝到目標板上去使用了。 Arduino最小系統板電路見下圖,適用于對ATmega8、ATmega168、ATmega328等型號的單片機編程
[單片機]
用<font color='red'>Arduino</font>最小系統板作AVR單片機的編程器
小廣播
設計資源 培訓 開發板 精華推薦

最新單片機文章
何立民專欄 單片機及嵌入式寶典

北京航空航天大學教授,20余年來致力于單片機與嵌入式系統推廣工作。

 
EEWorld訂閱號

 
EEWorld服務號

 
汽車開發圈

 
機器人開發圈

電子工程世界版權所有 京ICP證060456號 京ICP備10001474號-1 電信業務審批[2006]字第258號函 京公網安備 11010802033920號 Copyright ? 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
主站蜘蛛池模板: 克东县| 天全县| 丹寨县| 双流县| 海城市| 德化县| 漯河市| 十堰市| 区。| 康乐县| 洛南县| 菏泽市| 遵义市| 称多县| 阜南县| 新竹县| 凉城县| 龙口市| 桑植县| 石门县| 郯城县| 湖北省| 贵溪市| 香港| 安远县| 长汀县| 彰武县| 横峰县| 勐海县| 乌鲁木齐县| 景德镇市| 武义县| 英德市| 临潭县| 比如县| 英德市| 吴桥县| 无棣县| 天长市| 苏尼特左旗| 神池县|