質問編集履歴
10
さらに修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -216,8 +216,8 @@
|
|
216
216
|
#include <TFT_eSPI.h>
|
217
217
|
|
218
218
|
// Wi-Fiの設定
|
219
|
-
const char *ssid = "
|
219
|
+
const char *ssid = "my_SSID"; // ここにSSIDを入力
|
220
|
-
const char *password = "asd
|
220
|
+
const char *password = "my_password"; // ここにWi-Fiパスワードを入力
|
221
221
|
|
222
222
|
// NTPサーバの設定
|
223
223
|
WiFiUDP ntpUDP;
|
9
補足をさらに修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -206,6 +206,8 @@
|
|
206
206
|
|
207
207
|
### 補足
|
208
208
|
なお、TFT_eSPIライブラリのみで作成した下記の画面プログラムは、タッチ操作も正常にできていることを確認しています。
|
209
|
+
なので、ESP32基板とili9488との物理的な配線やTFT_eSPIライブラリの各種設定は問題ないのでは?と思うのですが・・・
|
210
|
+
他に確認すべきことなどありますでしょうか?
|
209
211
|
```cpp
|
210
212
|
#include <Arduino.h>
|
211
213
|
#include <WiFi.h>
|
8
補足を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -205,4 +205,119 @@
|
|
205
205
|
|
206
206
|
|
207
207
|
### 補足
|
208
|
+
なお、TFT_eSPIライブラリのみで作成した下記の画面プログラムは、タッチ操作も正常にできていることを確認しています。
|
209
|
+
```cpp
|
210
|
+
#include <Arduino.h>
|
211
|
+
#include <WiFi.h>
|
212
|
+
#include <NTPClient.h>
|
213
|
+
#include <WiFiUdp.h>
|
214
|
+
#include <TFT_eSPI.h>
|
215
|
+
|
216
|
+
// Wi-Fiの設定
|
217
|
+
const char *ssid = "20230616me_IPv6"; // ここにSSIDを入力
|
218
|
+
const char *password = "asdf0616"; // ここにWi-Fiパスワードを入力
|
219
|
+
|
220
|
+
// NTPサーバの設定
|
221
|
+
WiFiUDP ntpUDP;
|
222
|
+
NTPClient timeClient(ntpUDP);
|
223
|
+
|
224
|
+
void drawButtons();
|
225
|
+
void drawButton(int buttonIndex, uint32_t color);
|
226
|
+
|
227
|
+
// TFTディスプレイの設定
|
228
|
+
TFT_eSPI tft = TFT_eSPI(); // TFT_eSPIオブジェクトの作成
|
229
|
+
|
230
|
+
void setup() {
|
231
|
+
Serial.begin(115200);
|
232
|
+
|
233
|
+
// Wi-Fi接続
|
234
|
+
WiFi.begin(ssid, password);
|
235
|
+
while (WiFi.status() != WL_CONNECTED) {
|
236
|
+
delay(500);
|
237
|
+
Serial.print(".");
|
238
|
+
}
|
239
|
+
Serial.println("WiFi Connected");
|
240
|
+
|
241
|
+
// TFTディスプレイの初期化
|
242
|
+
tft.init();
|
243
|
+
tft.setRotation(1); // 画面の向きを調整
|
244
|
+
|
245
|
+
uint16_t calData[5] = { 231, 3567, 344, 3355, 7 };
|
246
|
+
tft.setTouch(calData);
|
247
|
+
|
248
|
+
// NTPサーバに接続
|
249
|
+
timeClient.begin();
|
250
|
+
timeClient.setTimeOffset(3600 * 9); // 日本時間の場合、UTC+9時間
|
251
|
+
|
252
|
+
// ボタンの表示(一度だけ実行)
|
253
|
+
drawButtons();
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
void drawButtons() {
|
258
|
+
for (int i = 0; i < 10; i++) {
|
259
|
+
drawButton(i, TFT_BLACK); // デフォルトの色でボタンを描画
|
260
|
+
}
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
void drawButton(int buttonIndex, uint32_t color) {
|
265
|
+
int x = (buttonIndex % 5) * 80; // ボタンのX座標を更新
|
266
|
+
int y = (buttonIndex / 5) * 60 + 100; // ボタンのY座標を更新
|
267
|
+
tft.fillRect(x, y, 80, 60, color); // 新しいサイズでボタンの背景を描画
|
268
|
+
tft.drawRect(x, y, 80, 60, TFT_WHITE); // 新しいサイズでボタンの枠を描画
|
269
|
+
tft.setCursor(x + 30, y + 25); // テキストの位置を調整
|
270
|
+
tft.print(buttonIndex + 1); // ボタンの番号を描画
|
271
|
+
}
|
272
|
+
|
273
|
+
|
274
|
+
// タッチされたボタンのインデックスと時間を記録する変数
|
275
|
+
int lastButtonIndex = -1;
|
276
|
+
unsigned long lastButtonTime = 0;
|
277
|
+
|
278
|
+
// グローバル変数として前回の時刻を記録するための変数を追加
|
279
|
+
String lastTime = "";
|
280
|
+
|
281
|
+
void loop() {
|
282
|
+
timeClient.update();
|
283
|
+
|
284
|
+
String currentTime = timeClient.getFormattedTime();
|
285
|
+
if (currentTime != lastTime) {
|
286
|
+
// 時計表示エリアのみを更新
|
287
|
+
tft.fillRect(0, 0, 240, 80, TFT_BLACK); // 時計表示エリアをクリア
|
288
|
+
tft.setTextColor(TFT_WHITE);
|
289
|
+
tft.setTextSize(2);
|
290
|
+
tft.setCursor(10, 10);
|
291
|
+
tft.print("Time: ");
|
292
|
+
tft.setTextSize(3);
|
293
|
+
tft.setCursor(10, 40);
|
294
|
+
tft.print(currentTime);
|
295
|
+
|
296
|
+
lastTime = currentTime; // 現在の時刻を記録
|
297
|
+
// シリアルモニターに時刻を出力
|
298
|
+
Serial.println(timeClient.getFormattedTime());
|
299
|
+
}
|
300
|
+
|
301
|
+
// タッチ座標の変数を宣言
|
302
|
+
uint16_t t_x, t_y;
|
303
|
+
|
304
|
+
// タッチ入力の検出
|
305
|
+
if (tft.getTouch(&t_x, &t_y)) {
|
306
|
+
int buttonIndex = (t_x / 80) + (t_y - 100) / 60 * 5; // 幅80ピクセル、高さ60ピクセルに基づく計算
|
307
|
+
if (buttonIndex >= 0 && buttonIndex < 10) {
|
308
|
+
drawButton(buttonIndex, TFT_RED);
|
309
|
+
lastButtonIndex = buttonIndex;
|
310
|
+
}
|
311
|
+
} else {
|
312
|
+
// タッチが終了した場合、ボタンの色を戻す
|
313
|
+
if (lastButtonIndex != -1) {
|
314
|
+
drawButton(lastButtonIndex, TFT_BLACK);
|
315
|
+
lastButtonIndex = -1;
|
316
|
+
}
|
317
|
+
}
|
318
|
+
|
319
|
+
delay(10);
|
320
|
+
|
321
|
+
}
|
322
|
+
|
208
|
-
|
323
|
+
```
|
7
さらに修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -194,7 +194,7 @@
|
|
194
194
|
- [ ] その他
|
195
195
|
|
196
196
|
##### 上記の詳細・結果
|
197
|
-
念のため、main.cファイル
|
197
|
+
念のため、main.cファイル内の
|
198
198
|
static void button_event_handler(lv_event_t *e)
|
199
199
|
static void simple_button_event_handler(lv_event_t *e)
|
200
200
|
|
6
さらに修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -194,7 +194,15 @@
|
|
194
194
|
- [ ] その他
|
195
195
|
|
196
196
|
##### 上記の詳細・結果
|
197
|
-
|
197
|
+
念のため、main.cファイル何
|
198
|
+
static void button_event_handler(lv_event_t *e)
|
199
|
+
static void simple_button_event_handler(lv_event_t *e)
|
200
|
+
|
201
|
+
2つのハンドラーがあるので、使っていないbutton_event_handlerは削除してみましたが、不具合は解消しません。
|
202
|
+
|
203
|
+
タッチ操作によるハンドラー呼び出しでは何か特別な設定などありますでしょうか?
|
204
|
+
|
205
|
+
|
198
206
|
|
199
207
|
### 補足
|
200
208
|
特になし
|
5
さらに修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,7 +15,13 @@
|
|
15
15
|
|
16
16
|
ボタンをタッチするとモニター出力されるはずの文字列
|
17
17
|
```cpp
|
18
|
+
// シンプルなボタンイベントハンドラ
|
19
|
+
static void simple_button_event_handler(lv_event_t *e) {
|
20
|
+
lv_event_code_t code = lv_event_get_code(e);
|
21
|
+
if(code == LV_EVENT_CLICKED) {
|
18
|
-
Serial.println("Button Pressed!");
|
22
|
+
Serial.println("Simple Button Pressed!");
|
23
|
+
}
|
24
|
+
}
|
19
25
|
```
|
20
26
|
この文字列がボタンを押しても全く出力されません。
|
21
27
|
そうなると、simple_button_event_handlerという割り込み関数が全く動いていないような状態だと思いますし、なぜ動いていないのかが全然わかりません。
|
4
さらに修正。
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
Serial.println("Button Pressed!");
|
19
19
|
```
|
20
20
|
この文字列がボタンを押しても全く出力されません。
|
21
|
-
|
21
|
+
そうなると、simple_button_event_handlerという割り込み関数が全く動いていないような状態だと思いますし、なぜ動いていないのかが全然わかりません。
|
22
22
|
|
23
23
|
改善方法などありましたらご教示の程よろしくお願い致します。
|
24
24
|
|
3
さらに修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -159,6 +159,25 @@
|
|
159
159
|
|
160
160
|
//#define TFT_WR 22 // Write strobe for modified Raspberry Pi TFT only
|
161
161
|
|
162
|
+
----(中略)----
|
163
|
+
|
164
|
+
//#define SPI_FREQUENCY 1000000
|
165
|
+
// #define SPI_FREQUENCY 5000000
|
166
|
+
// #define SPI_FREQUENCY 10000000
|
167
|
+
//#define SPI_FREQUENCY 20000000
|
168
|
+
#define SPI_FREQUENCY 27000000
|
169
|
+
// #define SPI_FREQUENCY 40000000
|
170
|
+
// #define SPI_FREQUENCY 55000000 // STM32 SPI1 only (SPI2 maximum is 27MHz)
|
171
|
+
// #define SPI_FREQUENCY 80000000
|
172
|
+
|
173
|
+
// Optional reduced SPI frequency for reading TFT
|
174
|
+
#define SPI_READ_FREQUENCY 20000000
|
175
|
+
|
176
|
+
// The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here:
|
177
|
+
#define SPI_TOUCH_FREQUENCY 2500000
|
178
|
+
|
179
|
+
// The ESP32 has 2 free SPI ports i.e. VSPI and HSPI, the VSPI is the default.
|
180
|
+
|
162
181
|
```
|
163
182
|
|
164
183
|
|
2
User_Setup.hファイルの内容も追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,6 +28,7 @@
|
|
28
28
|
|
29
29
|
### 該当のソースコード
|
30
30
|
|
31
|
+
main.cファイルの内容はこちらです。
|
31
32
|
```cpp
|
32
33
|
//main.cファイル内容
|
33
34
|
|
@@ -120,8 +121,46 @@
|
|
120
121
|
tft.endWrite();
|
121
122
|
lv_disp_flush_ready(disp);
|
122
123
|
}
|
124
|
+
```
|
125
|
+
|
126
|
+
また、TFT_eSPIライブラリのUser_Setup.hファイルの編集内容はこちらです。
|
127
|
+
```cpp
|
128
|
+
----(中略)----
|
129
|
+
|
130
|
+
//#define ILI9481_DRIVER
|
131
|
+
//#define ILI9486_DRIVER
|
132
|
+
#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)
|
133
|
+
//#define ST7789_DRIVER // Full configuration option, define additional parameters below for this display
|
134
|
+
//#define ST7789_2_DRIVER // Minima
|
135
|
+
|
136
|
+
----(中略)----
|
137
|
+
|
138
|
+
// The hardware SPI can be mapped to any pins
|
139
|
+
|
140
|
+
#define TFT_MISO 19
|
141
|
+
#define TFT_MOSI 23
|
142
|
+
#define TFT_SCLK 18
|
143
|
+
#define TFT_CS 4 // Chip select control pin
|
144
|
+
#define TFT_DC 2 // Data Command control pin
|
145
|
+
//#define TFT_RST 3 // Reset pin (could connect to RST pin)
|
146
|
+
//#define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST
|
147
|
+
|
148
|
+
// For ESP32 Dev board (only tested with GC9A01 display)
|
149
|
+
// The hardware SPI can be mapped to any pins
|
150
|
+
|
151
|
+
//#define TFT_MOSI 15 // In some display driver board, it might be written as "SDA" and so on.
|
152
|
+
//#define TFT_SCLK 14
|
153
|
+
//#define TFT_CS 5 // Chip select control pin
|
154
|
+
//#define TFT_DC 27 // Data Command control pin
|
155
|
+
//#define TFT_RST 33 // Reset pin (could connect to Arduino RESET pin)
|
156
|
+
//#define TFT_BL 22 // LED back-light
|
157
|
+
|
158
|
+
#define TOUCH_CS 27 // Chip select pin (T_CS) of touch screen
|
159
|
+
|
160
|
+
//#define TFT_WR 22 // Write strobe for modified Raspberry Pi TFT only
|
123
161
|
|
124
162
|
```
|
163
|
+
|
125
164
|
|
126
165
|
### 試したこと・調べたこと
|
127
166
|
- [ ] teratailやGoogle等で検索した
|
1
一部修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,6 +12,13 @@
|
|
12
12
|
### 発生している問題・分からないこと
|
13
13
|
|
14
14
|
画面中央に大きめのボタンを1個配置して、正常にタッチ動作できるかを、chat GPTに簡単なプログラムを作ってもらって、ボタンは表示できたのですが、タッチ動作の反応が全くない状態になります。
|
15
|
+
|
16
|
+
ボタンをタッチするとモニター出力されるはずの文字列
|
17
|
+
```cpp
|
18
|
+
Serial.println("Button Pressed!");
|
19
|
+
```
|
20
|
+
この文字列がボタンを押しても全く出力されません。
|
21
|
+
|
15
22
|
|
16
23
|
改善方法などありましたらご教示の程よろしくお願い致します。
|
17
24
|
|