XPT2046_Touchscreen

Hello
I can compile this with the Arduino IDE

SPIClass mySpi = SPIClass(VSPI);
XPT2046_Touchscreen ts(XPT2046_CS, XPT2046_IRQ);

TFT_eSPI tft = TFT_eSPI();

void setup() {
  Serial.begin(115200);

  // Start the SPI for the touch screen and init the TS library
  mySpi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
  // ts.begin(SPI1);
  ts.begin(mySpi);

but not with PlatformIO.
I get the Error
src/main.cpp:69:17: error: no matching function for call to ‘XPT2046_Touchscreen::begin(SPIClass&)’
Any Clue ?

Some basic information are missing, such as the platform used, the board used, the version number of the framework used (both ArduinoIDE and PlatformIO).

To make a comparison, show a screenshot of your board settings in the ArduinoIDE and share the content of your platformio.ini.

; 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:esp-wrover-kit]
platform = espressif32
board = esp-wrover-kit
framework = arduino
monitor_port = COM11
upload_port = COM11
monitor_speed = 115200

lib_deps = Bodmer/TFT_eSPI
           bitbank2/PNGdec@^1.0.2
		   paulstoffregen/XPT2046_Touchscreen

build_flags =
	-DUSER_SETUP_LOADED
	-DUSE_HSPI_PORT
	-DXPT2046_IRQ=36
    -DXPT2046_MOSI=32
    -DXPT2046_MISO=39
    -DXPT2046_CLK=25
    -DXPT2046_CS=33
	-DTFT_MISO=12
	-DTFT_MOSI=13
	-DTFT_SCLK=14
	-DTFT_CS=15
	-DTFT_DC=2
	-DTFT_RST=-1
	-DTFT_BL=21
	-DTFT_SWRST=0x01
	-DTFT_PASET=0x2B
	-DTFT_INVOFF=0x20
	-DTFT_INVON=0x21
	-DTFT_INIT_DELAY=0x80
	-DTFT_RAMRD=0x2E
	-DTFT_RAMWR=0x2C
	-DTFT_CASET=0x2A
	-DTFT_HEIGHT=240
	-DTFT_WIDTH=320
	-DTFT_BACKLIGHT_ON=HIGH
	-DSPI_FREQUENCY=55000000
	-DSPI_READ_FREQUENCY=20000000
	-DSPI_TOUCH_FREQUENCY=2500000
	-DLOAD_GLCD
	-DLOAD_FONT2
	-DLOAD_FONT4
	-DLOAD_FONT6
	-DLOAD_FONT7
	-DLOAD_FONT8
	-DLOAD_GFXFF
	-DILI9341_2_DRIVER
	-DTFT_RGB_ORDER=TFT_BGR
	-DTFT_INVERSION_OFF

PlatformIO Core, version 6.1.15

Arduino IDE 2.2.1

You use different boards.
“ESP32 Dev Module” in ArduinoIDE is board = esp32dev in platformio.ini.

Please check the used Arduino versions!

PlatformIO:
Compile your project and watch the output:

PACKAGES: 
 - framework-arduinoespressif32 @ 3.20016.0 (2.0.16) 

The number in brackets is the Arduino version. (Here: 2.0.16)

ArduinoIDE:
Click “Boards Manager” on the left side.
Enter “Espressif” in the search bar:

image

In the screenshot above the Arduino version is 2.0.17.

Hello!
I solved the Problem.
This works: git@github.com:PaulStoffregen/XPT2046_Touchscreen.git
This not: paulstoffregen/XPT2046_Touchscreen

Thank you for helping @sivar2311!
Thank you very much.

Yes, it looks like the library never got an update in the PlatformIO registry.
It is still on verison 0.0.0 alpha. On github it is on version 1.4

cc @ivankravets any chance to update “paulstoffregen/XPT2046_Touchscreen” in the registry? github vs registry

See

2 Likes

I still have a problem to translate centirozo.cpp file

#include "SPI.h"
#include "SerialUSB.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "XPT2046_Touchscreen.h"

// For My TFT Spi 240x320 display
#define TFT_DC 22
#define TFT_CS 17
//#define TFT_MOSI 19
//#define TFT_MISO 16
#define TFT_RST 21
#define TFT_CLK 18
#define LCD_LED 28
// For My XPT2046 Touch screen driver
#define T_CS_PIN  26
// MOSI=11, MISO=12, SCK=13
#define TIRQ_PIN  27
XPT2046_Touchscreen ts = XPT2046_Touchscreen ts(SPI);  // Param 2 - Touch IRQ Pin - interrupt enabled polling
#define ILI9341 1
#define SetColor(color) _color = (color)
unsigned int _color;
long X_value = 0;
long Y_value = 0;
long alfa_value = 0.1;
int16_t radius = 120;
voidFuncPtr* bitmap=0;
TS_Point p;

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);  // lényegesen gyorsabb!!



void display_task(void) {
  tft.fillRoundRect(0, 0, 320, 240, 20, ILI9341_RED);
  tft.drawCircle(160, 120, 119, ILI9341_BLUE);          // Óralap rajzolása
  tft.drawCircle(160, 120, 120, ILI9341_BLUE);
  tft.setCursor(20, 10);                                // felirat
  tft.setFont();
  tft.setTextSize(5);
  tft.println("centirozo");
  tft.setCursor(10, 100);
  tft.setTextSize(3);
  tft.setCursor(10, 100);
  tft.println("X ertek");
  tft.setCursor(10, 200);
  tft.println("Y ertek");
  digitalWrite(28, HIGH);
  }

void setup()
 {
  Serial.begin(115200);
  ts.begin();
  ts.setRotation(1);
  tft.setSPISpeed(1600000000L);
  pinMode(LCD_LED, OUTPUT);
  tft.begin();
  tft.setRotation(1);
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_YELLOW);
  tft.setTextSize(5);
  display_task(); 
}
void loop() {
  if (ts.touched()) {                   //  képernyő érintése
    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();
    tft.fillRoundRect(280, 0, 40, 40, 5, ILI9341_BLUE);
  }
  if (!ts.touched()){  
    tft.fillRoundRect(280, 0, 40, 40, 5, ILI9341_RED);
  }
  tft.setCursor(160, 100);                    //mutató rajzolása
  tft.println(X_value);
  tft.setCursor(160, 200);
  tft.println(Y_value);
  tft.drawLine(160, 119, X_value,Y_value, ILI9341_RED);
  X_value = 160 + radius*cos(alfa_value*M_PI/180);
  Y_value = 120 + radius*sin(alfa_value*M_PI/180);
  tft.drawLine(160, 119, X_value,Y_value, ILI9341_YELLOW);
  delay(100);
   
  tft.fillRect(160, 100, 80, 28, ILI9341_RED);      //  nyomógomb rajzolása
  tft.fillRect(160, 200, 53, 28, ILI9341_RED);
  if (alfa_value < 360)
  {
     alfa_value = alfa_value +1L;
  }
  else alfa_value = 0;
}

void loop1()
{
// tft.fillRoundRect((p.x/20-20), (p.y/20-20), 20, (20), 5, ILI9341_BLUE);
//tft.fillRoundRect((p.x/20-20), (p.y/20-20), 20, (20), 5, ILI9341_BLUE);
}

platformio.ini

[env:pico]
platform = raspberrypi
board = pico
framework = arduino
lib_deps =
  adafruit/Adafruit GFX Library@^1.11.11
  adafruit/Adafruit ILI9341@^1.6.1
  https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
  adafruit/Adafruit BusIO@^1.16.2
lib_extra_dirs = lib
debug_speed = 30000

translate error:

|-- Adafruit GFX Library @ 1.11.11
|-- Adafruit ILI9341 @ 1.6.1
|-- XPT2046_Touchscreen @ 1.4.0+sha.f956c5d
|-- Adafruit BusIO @ 1.16.2
|-- SPI
Building in release mode
Compiling .pio\build\pico\src\XPT2046_Touchscreen.cpp.o
Archiving .pio\build\pico\lib4b9\libSPI.a
Compiling .pio\build\pico\lib06d\Adafruit BusIO\Adafruit_BusIO_Register.cpp.o
Compiling .pio\build\pico\lib06d\Adafruit BusIO\Adafruit_I2CDevice.cpp.o     
Compiling .pio\build\pico\lib06d\Adafruit BusIO\Adafruit_SPIDevice.cpp.o
In file included from .pio\libdeps\pico\Adafruit BusIO\Adafruit_I2CDevice.cpp:1:
.pio\libdeps\pico\Adafruit BusIO\Adafruit_I2CDevice.h:5:10: fatal error: Wire.h: No such file or directory

**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Wire.h"
* Web  > https://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************

    5 | #include <Wire.h>
      |          ^~~~~~~~
compilation terminated.
*** [.pio\build\pico\lib06d\Adafruit BusIO\Adafruit_I2CDevice.cpp.o] Error 1
In file included from .pio\libdeps\pico\Adafruit BusIO/Adafruit_BusIO_Register.h:9,
                 from .pio\libdeps\pico\Adafruit BusIO\Adafruit_BusIO_Register.cpp:1:
.pio\libdeps\pico\Adafruit BusIO/Adafruit_I2CDevice.h:5:10: fatal error: Wire.h: No such file or directory

**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Wire.h"
* Web  > https://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************

    5 | #include <Wire.h>
      |          ^~~~~~~~
compilation terminated.
*** [.pio\build\pico\lib06d\Adafruit BusIO\Adafruit_BusIO_Register.cpp.o] Error 1
src\XPT2046_Touchscreen.cpp:33:6: error: no declaration matches 'bool XPT2046_Touchscreen::begin()'
   33 | bool XPT2046_Touchscreen::begin()
      |      ^~~~~~~~~~~~~~~~~~~
In file included from src\XPT2046_Touchscreen.cpp:23:
src\XPT2046_Touchscreen.h:57:7: note: candidate is: 'bool XPT2046_Touchscreen::begin(arduino::SPIClass&)'
   57 |  bool begin(SPIClass &wspi = SPI);
      |       ^~~~~
src\XPT2046_Touchscreen.h:50:7: note: 'class XPT2046_Touchscreen' defined here
   50 | class XPT2046_Touchscreen {
      |       ^~~~~~~~~~~~~~~~~~~
*** [.pio\build\pico\src\XPT2046_Touchscreen.cpp.o] Error 1

This line is wrong. The variable name ts appears twice, plus it doesn’t call the right constructor. It should be

XPT2046_Touchscreen ts = XPT2046_Touchscreen(T_CS_PIN, TIRQ_PIN);  // Param 2 - Touch IRQ Pin - interrupt enabled polling

You should not include individual headers from the Arduino core… always just #include <Arduino.h>. This can have otherwise have unforeseen consequences.

Either the platformio.ini you provided is incomplete or wrong – since it’s referencing SerialUSB.h, you seem to want to use the Arduino-Pico core, which either needs an additional board_build.core = earlephilhower or just board = rpipico (and an updated platform = https://github.com/maxgerhardt/platform-raspberrypi.git setting).

Makes no sense. lib/ already is the default library folder, so putting at as an extra directory doesn’t make a difference. Also it’s deprecated.

I can your code there perfectly fine when I chose my platformio.ini as

[env:pico]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git 
board = rpipico
framework = arduino
lib_deps =
  adafruit/Adafruit GFX Library@^1.11.11
  adafruit/Adafruit ILI9341@^1.6.1
  https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
  adafruit/Adafruit BusIO@^1.16.2
debug_speed = 30000

and apply the code fix mentioned above.

I did the changes. Thanks for your kindness.

Still have:

|-- Adafruit GFX Library @ 1.11.11
|-- Adafruit ILI9341 @ 1.6.1      
|-- XPT2046_Touchscreen @ 1.4.0+sha.f956c5d
|-- Adafruit BusIO @ 1.16.2
|-- SPI @ 1.0
Building in release mode
Compiling .pio\build\pico\src\XPT2046_Touchscreen.cpp.o
Compiling .pio\build\pico\lib06d\Adafruit BusIO\Adafruit_BusIO_Register.cpp.o
Compiling .pio\build\pico\lib06d\Adafruit BusIO\Adafruit_I2CDevice.cpp.o
Compiling .pio\build\pico\libd4f\Adafruit GFX Library\Adafruit_GFX.cpp.o
In file included from .pio\libdeps\pico\Adafruit BusIO\Adafruit_I2CDevice.cpp:1:
.pio\libdeps\pico\Adafruit BusIO\Adafruit_I2CDevice.h:5:10: fatal error: Wire.h: No such file or directory

**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Wire.h"
* Web  > https://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************

    5 | #include <Wire.h>
      |          ^~~~~~~~
compilation terminated.
In file included from .pio\libdeps\pico\Adafruit GFX Library\Adafruit_GFX.h:12,
                 from .pio\libdeps\pico\Adafruit GFX Library\Adafruit_GFX.cpp:34:
.pio\libdeps\pico\Adafruit BusIO/Adafruit_I2CDevice.h:5:10: fatal error: Wire.h: No such file or directory

**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Wire.h"
* Web  > https://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************

    5 | #include <Wire.h>
      |          ^~~~~~~~
compilation terminated.
In file included from .pio\libdeps\pico\Adafruit BusIO/Adafruit_BusIO_Register.h:9,
                 from .pio\libdeps\pico\Adafruit BusIO\Adafruit_BusIO_Register.cpp:1:
.pio\libdeps\pico\Adafruit BusIO/Adafruit_I2CDevice.h:5:10: fatal error: Wire.h: No such file or directory

**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Wire.h"
* Web  > https://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************

    5 | #include <Wire.h>
      |          ^~~~~~~~
compilation terminated.
*** [.pio\build\pico\lib06d\Adafruit BusIO\Adafruit_I2CDevice.cpp.o] Error 1
*** [.pio\build\pico\libd4f\Adafruit GFX Library\Adafruit_GFX.cpp.o] Error 1
*** [.pio\build\pico\lib06d\Adafruit BusIO\Adafruit_BusIO_Register.cpp.o] Error 1
src\XPT2046_Touchscreen.cpp:33:6: error: no declaration matches 'bool XPT2046_Touchscreen::begin()'
   33 | bool XPT2046_Touchscreen::begin()
      |      ^~~~~~~~~~~~~~~~~~~
In file included from src\XPT2046_Touchscreen.cpp:23:
src\XPT2046_Touchscreen.h:57:14: note: candidate is: 'bool XPT2046_Touchscreen::begin(arduino::SPIClass&)'
   57 |         bool begin(SPIClass &wspi = SPI);
      |              ^~~~~
src\XPT2046_Touchscreen.h:50:7: note: 'class XPT2046_Touchscreen' defined here
   50 | class XPT2046_Touchscreen {
      |       ^~~~~~~~~~~~~~~~~~~
*** [.pio\build\pico\src\XPT2046_Touchscreen.cpp.o] Error 1

platformio.ini

[env:pico]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git 
board = rpipico
framework = arduino
lib_deps =
  adafruit/Adafruit GFX Library@^1.11.11
  adafruit/Adafruit ILI9341@^1.6.1
  https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
  adafruit/Adafruit BusIO@^1.16.2
debug_speed = 30000

This should not happen if the main header for each library was properly included. Can you post the full project into Github, Google drive or similiar?

You probably meant to sent the project files here instead of in the other thread (https://community.platformio.org/t/using-an-raspberry-pico-as-picoprobe-debugger-for-another-rp2040-based-board/38568/15?u=maxgerhardt).

The problem is exactly I’ve said above:

You lib_deps all these different libraries

lib_deps =
  adafruit/Adafruit GFX Library@^1.11.11
  adafruit/Adafruit ILI9341@^1.6.1
  https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
  adafruit/Adafruit BusIO@^1.16.2

but you only ever

#include "XPT2046_Touchscreen.h"

PlatformIO will not properly resolve library dependencies if you don’t include them into your project. Hence, the build for Adafruit ILI9341, Adafruit BusIO etc fails horribly.

But, the problem is a while different one. You just copy-pasted the contents of the XPT2046_Touchscreen.cpp and XPT2046_Touchscreen.h file from the XPT2046_Touchscreen library into your project. That makes no sense. You already include the library’s code in lib_deps = https://github.com/PaulStoffregen/XPT2046_Touchscreen.git. Copying the files of that library again in your project makes no sense.

I would advise to just delete src/XPT2046_Touchscreen.cpp and src/XPT2046_Touchscreen.h, create a new file src/main.cpp and use this content

#include <Arduino.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "XPT2046_Touchscreen.h"

// For My TFT Spi 240x320 display
#define TFT_DC 22
#define TFT_CS 17
//#define TFT_MOSI 19
//#define TFT_MISO 16
#define TFT_RST 21
#define TFT_CLK 18
#define LCD_LED 28
// For My XPT2046 Touch screen driver
#define T_CS_PIN  26
// MOSI=11, MISO=12, SCK=13
#define TIRQ_PIN  27
XPT2046_Touchscreen ts = XPT2046_Touchscreen(T_CS_PIN, TIRQ_PIN);  // Param 2 - Touch IRQ Pin - interrupt enabled polling
#define ILI9341 1
#define SetColor(color) _color = (color)
unsigned int _color;
long X_value = 0;
long Y_value = 0;
long alfa_value = 0.1;
int16_t radius = 120;
voidFuncPtr* bitmap=0;
TS_Point p;

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);  // lényegesen gyorsabb!!



void display_task(void) {
  tft.fillRoundRect(0, 0, 320, 240, 20, ILI9341_RED);
  tft.drawCircle(160, 120, 119, ILI9341_BLUE);          // Óralap rajzolása
  tft.drawCircle(160, 120, 120, ILI9341_BLUE);
  tft.setCursor(20, 10);                                // felirat
  tft.setFont();
  tft.setTextSize(5);
  tft.println("centirozo");
  tft.setCursor(10, 100);
  tft.setTextSize(3);
  tft.setCursor(10, 100);
  tft.println("X ertek");
  tft.setCursor(10, 200);
  tft.println("Y ertek");
  digitalWrite(28, HIGH);
  }

void setup()
 {
  Serial.begin(115200);
  ts.begin();
  ts.setRotation(1);
  tft.setSPISpeed(1600000000L);
  pinMode(LCD_LED, OUTPUT);
  tft.begin();
  tft.setRotation(1);
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_YELLOW);
  tft.setTextSize(5);
  display_task(); 
}
void loop() {
  if (ts.touched()) {                   //  képernyő érintése
    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();
    tft.fillRoundRect(280, 0, 40, 40, 5, ILI9341_BLUE);
  }
  if (!ts.touched()){  
    tft.fillRoundRect(280, 0, 40, 40, 5, ILI9341_RED);
  }
  tft.setCursor(160, 100);                    //mutató rajzolása
  tft.println(X_value);
  tft.setCursor(160, 200);
  tft.println(Y_value);
  tft.drawLine(160, 119, X_value,Y_value, ILI9341_RED);
  X_value = 160 + radius*cos(alfa_value*M_PI/180);
  Y_value = 120 + radius*sin(alfa_value*M_PI/180);
  tft.drawLine(160, 119, X_value,Y_value, ILI9341_YELLOW);
  delay(100);
   
  tft.fillRect(160, 100, 80, 28, ILI9341_RED);      //  nyomógomb rajzolása
  tft.fillRect(160, 200, 53, 28, ILI9341_RED);
  if (alfa_value < 360)
  {
     alfa_value = alfa_value +1L;
  }
  else alfa_value = 0;
}

void loop1()
{
// tft.fillRoundRect((p.x/20-20), (p.y/20-20), 20, (20), 5, ILI9341_BLUE);
//tft.fillRoundRect((p.x/20-20), (p.y/20-20), 20, (20), 5, ILI9341_BLUE);
}