以前
https://qiita.com/Mobu_Kyoto/items/59446b99353b50ac6b1f
のものを、次のボード
ESP32-S3-DevKitC-1 (秋月電子より購入)
Arduino IDE 2.2.0 では「ESP32S3 Dev Module」
に移植した製作物です。このボードの詳細を "esptool.py" で見ると次のようになります。
"Arduino IDE 2.2.0" の "Tools" で
としてみました。
接続するジャンパー線がうるさかったので、出来るだけ線が交差しないよう工夫しました。次の接続で動作しました。
ILI9488 | ESP32-S3-DevKitC-1 |
---|---|
T_IRQ | |
T_DO | 14 |
T_DIN | 11 |
T_CS | 13 |
T_CLK | 12 |
SDO(MISO) | |
LED | 3V3 |
SCK | 12 |
SDI(MOSI) | 11 |
DC/RS | 10 |
RESET | 9 |
CS | 46 |
GND | GND |
VCC | 3V3 |
Arduino IDE 2.2.0 のライブラリ "TFT_eSPI" を利用したので、ピンの設定やSPIの設定は "libraries/TFT_eSPI/User_Setup.h" にて次のように行いました。
libraries/TFT_eSPI/User_Setup.h
(約50行目)
#define ILI9488_DRIVER // WARNING: Do not connect ILI9488 display SDO to MISO if other devices share the SPI bus (TFT SDO does NOT tristate when CS is high)
(約210行目)
#define TFT_MISO 14
#define TFT_MOSI 11
#define TFT_SCLK 12
#define TFT_CS 46 // Chip select control pin
#define TFT_DC 10 // Data Command control pin
#define TFT_RST 9 // Reset pin (could connect to RST pin)
//#define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST
// For ESP32 Dev board (only tested with GC9A01 display)
// The hardware SPI can be mapped to any pins
//#define TFT_MOSI 15 // In some display driver board, it might be written as "SDA" and so on.
//#define TFT_SCLK 14
//#define TFT_CS 5 // Chip select control pin
//#define TFT_DC 27 // Data Command control pin
//#define TFT_RST 33 // Reset pin (could connect to Arduino RESET pin)
//#define TFT_BL 22 // LED back-light
#define TOUCH_CS 13 // Chip select pin (T_CS) of touch screen
(約360行目)
#define SPI_FREQUENCY 40000000
// #define SPI_FREQUENCY 55000000 // STM32 SPI1 only (SPI2 maximum is 27MHz)
//#define SPI_FREQUENCY 80000000 A little Miss
// Optional reduced SPI frequency for reading TFT
#define SPI_READ_FREQUENCY 10000000 //20000000
// The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here:
#define SPI_TOUCH_FREQUENCY 2000000
次にスケッチ本体を示します。
9488_ESPS3_TouchPen.ino
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
char KindLabel[8][12] = { "Clear.Scr", "Free Dot",
"Draw Line", "D.Triangl",
"D.Ellipse", "F.Ellipse",
"D.Rectang", "F_Rectang" };
uint8_t Shape[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
uint16_t Color[8] = { TFT_BLACK, TFT_MAGENTA, TFT_RED, TFT_YELLOW,
TFT_GREEN, TFT_BLUE, TFT_CYAN, TFT_WHITE };
void setup() {
Serial.begin(115200);
tft.init(); // DisplayとTouchは同じSPIを使用
// T_DOのみMISOと接続し、SDO(MISO)はMISOと接続しない。
// T_DIN、SDI(MOSI)はMOSIと接続する。
tft.setRotation(1);
InitScreen();
}
void InitScreen() {
// Clear the screen
tft.fillScreen(TFT_WHITE);
for (int x = 0; x < 8; x++) {
if (x % 2 == 1) {
tft.fillRect(60 * x, 0, 60, 25, TFT_DARKGREY);
tft.setTextColor(TFT_WHITE);
} else {
tft.fillRect(60 * x, 0, 60, 25, 0xF777);
tft.setTextColor(TFT_BLACK);
}
tft.drawRect(60 * x, 0, 60, 25, TFT_WHITE);
tft.drawString(KindLabel[x], 60 * x + 2, 4, 2);
tft.fillRect(60 * x, 25, 60, 25, Color[x]);
}
tft.setTextColor(TFT_WHITE);
tft.drawString("Black", 12, 29, 2);
tft.drawRect(420, 25, 60, 25, TFT_BLACK);
tft.setTextColor(TFT_BLACK);
tft.drawString("White", 432, 29, 2);
}
int pCol;
int shapeK;
uint16_t t_x; // To store the touch coordinates
uint16_t t_y;
bool pressed;
uint16_t x2;
uint16_t y2;
bool pressed2;
uint16_t x3;
uint16_t y3;
bool pressed3;
void loop(void) {
// Pressed will be set true as there is a valid touch on the screen
pressed = false;
while (!pressed) {
t_x = 0;
t_y = 0;
pressed = tft.getTouch(&t_x, &t_y);
delay(1);
}
delay(10);
Serial.printf("First Point\r\n");
if (t_y >= 319 - 25) { // shape choose & clear screen
shapeK = t_x / 60; // shape kind
if (shapeK == 0) InitScreen();
}
if (t_y < 319 - 25 && t_y >= 319 - 25 * 2) { // color choose
pCol = Color[t_x / 60];
}
if (t_y < 319 - 25 * 2 - 5) {
if (shapeK == 1) {
tft.fillEllipse(t_x, 319 - t_y, 3, 3, pCol);
} else {
tft.fillEllipse(t_x, 319 - t_y, 2, 2, pCol);
x2 = 0;
y2 = 319;
pressed2 = false;
while (!pressed2 && y2 > 319 - 25 * 2 - 5) {
pressed2 = tft.getTouch(&x2, &y2);
delay(1);
}
delay(10);
Serial.printf(" Second Point\r\n");
if (y2 < 319 - 25 * 2 - 5) {
switch (shapeK) {
case 2:
tft.drawLine(t_x, 319 - t_y, x2, 319 - y2, pCol);
break;
case 3:
x3 = 0;
y3 = 319;
pressed3 = false;
while (!pressed3 && y3 > 319 - 25 * 2 - 5) {
pressed3 = tft.getTouch(&x3, &y3);
delay(1);
}
delay(10);
Serial.printf(" Third Point\r\n");
tft.drawTriangle(t_x, 319 - t_y, x2, 319 - y2, x3, 319 - y3, pCol);
break;
case 4:
tft.drawEllipse(t_x, 319 - t_y, abs(x2 - t_x), abs(y2 - t_y), pCol);
break;
case 5:
tft.fillEllipse(t_x, 319 - t_y, abs(x2 - t_x), abs(y2 - t_y), pCol);
break;
case 6:
tft.drawRect(min(t_x, x2), min(319 - t_y, 319 - y2), abs(x2 - t_x), abs(y2 - t_y), pCol);
break;
case 7:
tft.fillRect(min(t_x, x2), min(319 - t_y, 319 - y2), abs(x2 - t_x), abs(y2 - t_y), pCol);
break;
default:
break;
}
}
}
}
}
最後まで見て頂きありがとうございました。