Spotpear ESP32C3-1.442025/11/12

Spotpear ESP32C3-1.44

カラーLCDの使い方を調べるのに”Spotpear ESP32C3-1.44inch” をアリエクで買ってみました。¥1000くらい。 

とりあえず買ったままの状態で起動すると説明が出てくるので、
スマホでテザリング設定で"Spotpear" , password "12345678"
でWifiに接続して一応通常画面が出る。が、時間は合わないし、天気情報もでませんでした。

●Demo  CodeをArduino IDEでコンパイルする。
コンパイル方法

コードの在処
https://github.com/Spotpear/ESP32C3_1.44inch

1】以下のライブラリをインストール
 TFT_eSPI
 TJpg_ Decoder
 ArduinoJson
 Time
 HTTPClient
 lvgl

2】ライブラリ内のTFT_eSPIフォルダのUser_Setup.h を編集する
以下の設定にする
-------------------------------------------------------------------------------------------------------
#define ST7735_DRIVER

#define TFT_WIDTH  128
#define TFT_HEIGHT 128

#define ST7735_GREENTAB3

#define TFT_RGB_ORDER TFT_BGR  // Colour order Blue-Green-Red

#define TFT_INVERSION_ON

#define TFT_MOSI  4
#define TFT_SCLK  3
#define TFT_CS    2  // Chip select control pin
#define TFT_DC    0  // Data Command control pin
#define TFT_RST   5  // Reset pin (could connect to RST pin)
#define TFT_MISO -2 //dummy これ追加(重要)

#define SPI_FREQUENCY  40000000
-------------------------------------------------------------------------------------------------------
Webのspotpearの説明にはありませんが、TFT_MISO に値を入れないとTFT_INITが失敗します。
TFT_eSPI_ESP32_C3.h に不具合があります。TFT_eSPIのバージョンは2.5.43。
出所
https://github.com/Bodmer/TFT_eSPI/issues/3772

・TFT_eSPIのバグ
1,User_Setup.hでTFT_MISOを定義しない、または-1を設定すると TFT_MISI == TFT_MISO となって初期化できない。画面白いまま。
2,TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.h で
#define SPI_PORT_SPI2_HOST
 #define SPI_PORT 2
にしないとCore Dumpが出ます。

TFT_MISO に-2を入れてますが、-1ではなく、存在しないPin番号にしたかったので適当に設定しました。これが良いか不明。

--------------------------------------------------------------------------------------------------------------------------------------------
User_Setup.h
//                            USER DEFINED SETTINGS
//   Set driver type, fonts to be loaded, pins used and SPI control method etc.
//
//   See the User_Setup_Select.h file if you wish to be able to define multiple
//   setups and then easily select which setup file is used by the compiler.
//
//   If this file is edited correctly then all the library example sketches should
//   run without the need to make any more changes for a particular hardware setup!
//   Note that some sketches are designed for a particular TFT pixel width/height

// User defined information reported by "Read_User_Setup" test & diagnostics example
#define USER_SETUP_INFO "User_Setup"

// Config for two ST7735 128 x 128 displays for Animated_Eyes example
#define USER_SETUP_ID 47

#define ST7735_DRIVER     // Configure all registers

#define TFT_WIDTH  128
#define TFT_HEIGHT 128

// #define ST7735_INITB
// #define ST7735_GREENTAB
// #define ST7735_GREENTAB2
 #define ST7735_GREENTAB3
// #define ST7735_GREENTAB128    // For 128 x 128 display
// #define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset)
// #define ST7735_REDTAB
//#define ST7735_BLACKTAB
// #define ST7735_REDTAB160x80   // For 160 x 80 display with 24 pixel offset

//#define TFT_RGB_ORDER TFT_RGB  // Colour order Red-Green-Blue
#define TFT_RGB_ORDER TFT_BGR  // Colour order Blue-Green-Red

#define TFT_INVERSION_ON
//#define TFT_INVERSION_OFF

// Generic ESP32 setup

//add for spotpear esp32-c3 1.44
#define TFT_MOSI  4
#define TFT_SCLK  3
#define TFT_CS    2  // Chip select control pin
#define TFT_DC    0  // Data Command control pin
#define TFT_RST   5  // Reset pin (could connect to RST pin)
#define TFT_MISO -2 //dummy

//#define TFT_MISO 19
//#define TFT_MOSI 23
//#define TFT_SCLK 18
////#define TFT_CS    21 // Not defined here, chip select is managed by sketch
//#define TFT_DC    2
//#define TFT_RST   4  // Connect reset to ensure display initialises

#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  27000000
#define SPI_FREQUENCY  40000000

#define SPI_READ_FREQUENCY  20000000

#define SPI_TOUCH_FREQUENCY  2500000

// #define SUPPORT_TRANSACTIONS
--------------------------------------------------------------------------------------------------------------------------------------------

3】lvglライブラリの lv_conf.h の作成
 lvglライブラリは9.4.0(現時点で最新)から8.4.0にダウングレードした。lv_conf.h がだいぶ違う。9.x.xはエラーがたくさんでて面倒なので。

lv_conf_template.h をコピーして名前をlv_conf.hにしてlibrariesフォルダーに入れる
lv_conf.hを編集する
(編集されたものがDemo codeに入ってるのでそのまま使える)
●---Modify the parameter to change 0 to 1 here
/* clang-format off */
#if 1 /*Set it to "1" to enable content*/ <- 1に 

#ifndef LV_CONF_H
#define LV_CONF_H

#include <stdint.h>

/*====================
   COLOR SETTINGS
 *====================*/

/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
#define LV_COLOR_DEPTH 16

/*Swap the 2 bytes of RGB565 color. Useful if the display has an 8-bit interface (e.g. SPI)*/
#define LV_COLOR_16_SWAP 0 <- 付属のヘッダーファイルは0だが、Webの説明では1 

●--- Change 30 to 16 and 0 to 1 here
/*====================
   HAL SETTINGS
 *====================*/

/*Default display refresh period. LVG will redraw changed areas with this period time*/
#define LV_DISP_DEF_REFR_PERIOD 16      /*[ms]*/ <- 16に

/*Input device read period in milliseconds*/
#define LV_INDEV_DEF_READ_PERIOD 30     /*[ms]*/

/*Use a custom tick source that tells the elapsed time in milliseconds.
 *It removes the need to manually update the tick with `lv_tick_inc()`)*/
#define LV_TICK_CUSTOM 1 <- 1に
#if LV_TICK_CUSTOM
    #define LV_TICK_CUSTOM_INCLUDE "Arduino.h"         /*Header for the system time function*/
    #define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis())    /*Expression evaluating to current system time in ms*/
#endif   /*LV_TICK_CUSTOM*/

/*Default Dot Per Inch. Used to initialize default sizes such as widgets sized, style paddings.
 *(Not so important, you can adjust it to modify default sizes and spaces)*/
#define LV_DPI_DEF 130     /*[px/inch]*/

※ライブラリのバグにたどり着くまで、1日あまり費やしました。githubの皆さんに感謝。
これでTFT_eSPIライブラリが使えるようになりました。