Hi,
When compiling Lolin’s example for [TFT 2.4], I witness a problem. When same code is compiled and uploaded via Arduino IDE, screen works as expected. But when trying to use SAME code, and same libraries, I get a blank screen. Even the Touch basic example does not yeild XY coordinates of touch location.
/***************************************************
1. !!!Make sure you using lastest ESP8266 core for Arduino, otherwise it may not work properly.
https://github.com/esp8266/Arduino
(The pin D0(GPIO16) will be not work when you use older version ESP8266 core for Arduino,
because the older version ESP8266 core for Arduino's digitalPinToBitMask(), portOutputRegister(),
portInputRegister() and portModeRegister() fuction have some bugs which Adafruit_ILI9341 Library will use.
This bug was fixed after commit: https://github.com/esp8266/Arduino/commit/799193888a553de8876052019842538396f92194 )
2. Setup latest Adafruit_GFX, Adafruit_ILI9341 and XPT2046_Touchscreen Library first:
https://github.com/adafruit/Adafruit-GFX-Library
https://github.com/adafruit/Adafruit_ILI9341
https://github.com/PaulStoffregen/XPT2046_Touchscreen
****************************************************/
#include <Arduino.h>
#include <SPI.h>
#include <XPT2046_Touchscreen.h>
#define TS_CS D3 //for D1 mini or TFT I2C Connector Shield (V1.1.0 or later)
// #define TS_CS 12 //for D32 Pro
XPT2046_Touchscreen ts(TS_CS);
void setup()
{
Serial.begin(115200);
ts.begin();
ts.setRotation(1);
while (!Serial && (millis() <= 1000))
;
}
void loop()
{
if (ts.touched())
{
TS_Point p = ts.getPoint();
Serial.print("Pressure = ");
Serial.print(p.z);
Serial.print(", x = ");
Serial.print(p.x);
Serial.print(", y = ");
Serial.print(p.y);
delay(30);
Serial.println();
}
}
.ini file:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:d1]
platform = espressif8266
board = d1
framework = arduino
lib_deps = paulstoffregen/XPT2046_Touchscreen@0.0.0-alpha+sha.26b691b2c8
monitor_speed = 115200
(https://www.wemos.cc/en/latest/d1_mini_shield/tft_2_4.html)
board = d1 uses the d1 variant in Arduino-ESP8266 while board = d1_mini uses d1_mini (see above linked board definitions.
Each of these have their own pin definitions
So what specifically makes your sketch fail is because you’re using Dx references in your sketch instead of direct GPIO numbers:
And for board = d1 we have D3 = 5 (GPIO5) but for d1_mini we have D3 = 0 (GPIO0).
If the code said #define TS_CS 0 instead it would have still worked when a different board was used - - but of course would have been harder to translate to the “D” name on the actual physical board.