最近買了一塊圓形螢幕,驅動IC是GC9A01,自己參考淘寶給的stm32的驅動例程,
在ubuntu下使用IDF開發ESP32,也在windows的vscode內安裝IDF開發ESP32,雖然都做到了能顯示圖片,但是總有一塊暗紫色的偏差陰影,也嘗試了移植LVGL,都遇到了問題。
如上圖,在網上看到有Arduino的一個TFT LCD的驅動庫,已經包含了對該型號螢幕IC的驅動,所以轉戰Arduino環境,來驅動這塊圓形螢幕。
1. 下載Arduino_GFX庫
https://github.com/moononournation/Arduino_GFX
下載好該庫後,放置到Arduino的library目錄下,如下圖所示。這是Arduino的庫的預設路徑。
2.Arduino GFX庫測試
Arduino 的library目錄,這個路徑內的專案檔案都是隻讀的,不便於我們直接開啟內部的示例專案燒錄和測試。
將Arduino GFX庫內的example資料夾內的HelloWorld資料夾複製到其他路徑下,我是複製到了桌面上的smart_screen_001資料夾內,然後開啟專案工程HelloWorld.ino檔案。
修改三處程式碼,分別修改DC 以及SPI等腳位,以及RST腳,和背光腳DF_GFX_BL。
上述Arduino+ESP32,驅動GC9A01的原始檔:
/*******************************************************************************
* Start of Arduino_GFX setting
*
* Arduino_GFX try to find the settings depends on selected board in Arduino IDE
* Or you can define the display dev kit not in the board list
* Defalult pin list for non display dev kit:
* Arduino Nano, Micro and more: CS: 9, DC: 8, RST: 7, BL: 6
* ESP32 various dev board : CS: 5, DC: 27, RST: 33, BL: 22
* ESP32-C3 various dev board : CS: 7, DC: 2, RST: 1, BL: 3
* ESP32-S2 various dev board : CS: 34, DC: 26, RST: 33, BL: 21
* ESP8266 various dev board : CS: 15, DC: 4, RST: 2, BL: 5
* Raspberry Pi Pico dev board : CS: 17, DC: 27, RST: 26, BL: 28
* RTL8720 BW16 old patch core : CS: 18, DC: 17, RST: 2, BL: 23
* RTL8720_BW16 Official core : CS: 9, DC: 8, RST: 6, BL: 3
* RTL8722 dev board : CS: 18, DC: 17, RST: 22, BL: 23
* RTL8722_mini dev board : CS: 12, DC: 14, RST: 15, BL: 13
* Seeeduino XIAO dev board : CS: 3, DC: 2, RST: 1, BL: 0
* Teensy 4.1 dev board : CS: 39, DC: 41, RST: 40, BL: 22
******************************************************************************/
#include <Arduino_GFX_Library.h>
/* More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration */
#if defined(DISPLAY_DEV_KIT)
Arduino_GFX *gfx = create_default_Arduino_GFX();
#else /* !defined(DISPLAY_DEV_KIT) */
/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
#if 0
Arduino_DataBus *bus = create_default_Arduino_DataBus();
#else
Arduino_DataBus *bus = new Arduino_ESP32SPI(12 /* DC */, 15 /* CS */, 14 /* SCK */, 13 /* MOSI */, -1 /* MISO */, HSPI /* spi_num */);
#endif
/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
#if 0
Arduino_GFX *gfx = new Arduino_ILI9341(bus, DF_GFX_RST, 0 /* rotation */, false /* IPS */);
#else
Arduino_GFX *gfx = new Arduino_GC9A01(bus, 2 /* RST */, 0 /* rotation */, true /* IPS */);
#endif
#endif /* !defined(DISPLAY_DEV_KIT) */
/*******************************************************************************
* End of Arduino_GFX setting
******************************************************************************/
#define DF_GFX_BL 16
void setup(void)
{
gfx->begin();
gfx->fillScreen(BLACK);
#ifdef DF_GFX_BL
pinMode(DF_GFX_BL, OUTPUT);
digitalWrite(DF_GFX_BL, HIGH);
#endif
gfx->setCursor(10, 10);
gfx->setTextColor(RED);
gfx->println("Hello World!");
delay(5000); // 5 seconds
}
void loop()
{
gfx->setCursor(random(gfx->width()), random(gfx->height()));
gfx->setTextColor(random(0xffff), random(0xffff));
gfx->setTextSize(random(6) /* x scale */, random(6) /* y scale */, random(2) /* pixel_margin */);
gfx->println("Hello World!");
delay(1000); // 1 second
}
實驗現象:
隨機彈出了很多不同大小,不同色彩的Hello world,符合示例程式碼的實現。
這樣,Arduino_GFX庫就順利移植好了。
.