📺

黄色い液晶付きESP32をPlatformIO/Arduino_GFXで使うメモ

2024/01/02に公開

前提

  • ターゲットボード ESP32-4827S043N (8048ではないので注意。安い方)
  • ILI9485(ILI6485) を使っている。(資料によって記述が違うが互換性があるらしい)
  • 販売元(Aliexpressで↑の型番を検索するとサンプルコードが入手できる)

参考にしたサイト

サンプルコードで分からないこと

  • ArduinoGFXのバージョンが上がって、色々リファクタリングされたようで初期化パラメタが変わっている。
  • PSRAMの使い方がわからない
  • PSRAMを使わないと、WiFi接続できないくらいにメモリが足りない。(液晶パネルの都合で、すごいメモリを食う)

メモ

PSRAM 有効化

platformio.ini に以下のように記述することでPSRAMを有効にできた。

platformio.ini
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
board_build.mcu = esp32s3
monitor_speed = 115200
upload_speed = 921600
board_build.f_cpu = 80000000L  # ここは変更OK
board_build.arduino.memory_type = dio_opi
board_upload.flash_size = 16MB
lib_deps = 
    olikraus/U8g2
    moononournation/GFX Library for Arduino@^1.4.1
build_flags = 
	-Os
	-DBOARD_HAS_PSRAM

Arduino_GFX

以下で初期化できる。入手できるサンプルは、 Arduino_GFX 1.2.8 のときの記述であり、これを書いている時点では 1.4.1 にバージョンアップしている。途中、リファクタリングがあったらしくカスタム設定のやりかたがだいぶ変更されていた。
(ただし、以下のサンプルはまだバックライトの制御がON/OFFになってしまっている)

// default backlight pin, you may replace DF_GFX_BL to actual backlight pin
#define GFX_BL DF_GFX_BL
#define TFT_BL 2

Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
    40 /* DE */, 41 /* VSYNC */, 39 /* HSYNC */, 42 /* PCLK */,
    45 /* R0 */, 48 /* R1 */, 47 /* R2 */, 21 /* R3 */, 14 /* R4 */,
    5 /* G0 */, 6 /* G1 */, 7 /* G2 */, 15 /* G3 */, 16 /* G4 */, 4 /* G5 */,
    8 /* B0 */, 3 /* B1 */, 46 /* B2 */, 9 /* B3 */, 1 /* B4 */,
    0 /* hsync_polarity */, 8 /* hsync_front_porch */, 4 /* hsync_pulse_width */, 43 /* hsync_back_porch */,
    0 /* vsync_polarity */, 8 /* vsync_front_porch */, 4 /* vsync_pulse_width */, 12 /* vsync_back_porch */,
    1 /* pclk_active_neg  */, 9000000 /* prefer_speed */
);

Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
    480 /* width */, 272 /* height */, rgbpanel
);

Discussion