Platformio tft_espi and xpt2046

I have used Bodmers TFT_eSPI libraries with 2.8" ILI9341 TFT displays & 3.5" ILI9488 TFT displays for some time and the are just great !!

This time I am trying to put all variables as build_flags in platformio.ini, so I dont have to worry about settings in user_setup.h

This works fine for the display part

build_flags =
  -D ILI9488_DRIVER=1
  -D TFT_WIDTH=320
  -D TFT_HEIGHT=480 
  -D SPI_FREQUENCY=27000000
  -D TFT_CS=5
  -D TFT_DC=2
  -D TFT_RST=33

but when I try to compile the TFTe_SPI examplefile :


i get an error saying the touch.h file is missing :

src/main.cpp:26:10: fatal error: touch.h: No such file or directory

How can I make the program aware of the touch-library ??

Hm there should be no need to include touch.h, it already gets included in TFT_eSPI.h through the

directive as part of the TFT_eSPI class.

The TFT_eSPI/Keypad_480x320.ino at 4e8497c159449ba7dc02dc8b9bb6164e5b048bc1 · Bodmer/TFT_eSPI · GitHub also doesn’t di a #include <Touch.h>.

String escaping needs special care. What happens when you delete this line?

I removed the UNIT_NAME line but no change…

Here is the first part of the source for Keypad_480x320.ino (I have made a copy/paste of the content into main.cpp):

#include "FS.h"

#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library

TFT_eSPI tft = TFT_eSPI(); // Invoke custom library

// This is the file name used to store the calibration data
// You can change this to create new calibration files.
// The SPIFFS file name must start with "/".
#define CALIBRATION_FILE "/TouchCalData2"

// Set REPEAT_CAL to true instead of false to run calibration
// again, otherwise it will only be done once.
// Repeat calibration if you change the screen rotation.
#define REPEAT_CAL false

// Keypad start position, key sizes and spacing
#define KEY_X 40 // Centre of key
#define KEY_Y 96
#define KEY_W 62 // Width and height
#define KEY_H 30
#define KEY_SPACING_X 18 // X and Y gap
#define KEY_SPACING_Y 20
#define KEY_TEXTSIZE 1 // Font size multiplier

// Using two fonts since numbers are nice when bold
#define LABEL1_FONT &FreeSansOblique12pt7b // Key label font 1
#define LABEL2_FONT &FreeSansBold12pt7b    // Key label font 2

// Numeric display box size and location
#define DISP_X 1
#define DISP_Y 10
#define DISP_W 238
#define DISP_H 50
#define DISP_TSIZE 3

// Number length, buffer for storing it and character index
#define NUM_LEN 12
char numberBuffer[NUM_LEN + 1] = "";
uint8_t numberIndex = 0;

// We have a status line for messages
#define STATUS_X 120 // Centred on this
#define STATUS_Y 65

// Create 15 keys for the keypad
char keyLabel[15][5] = {"New", "Del", "Send", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "0", "#"};
uint16_t keyColor[15] = {TFT_RED, TFT_DARKGREY, TFT_DARKGREEN,
                         TFT_BLUE, TFT_BLUE, TFT_BLUE,
                         TFT_BLUE, TFT_BLUE, TFT_BLUE,
                         TFT_BLUE, TFT_BLUE, TFT_BLUE,
                         TFT_BLUE, TFT_BLUE, TFT_BLUE};

// Invoke the TFT_eSPI button class and create all the button objects
TFT_eSPI_Button key[15];


void setup()
  // Use serial port

  // Initialise the TFT screen

  // Set the rotation before we calibrate

  // Calibrate the touch screen and retrieve the scaling factors

  // Clear the screen

  // Draw keypad background
  tft.fillRect(0, 0, 240, 320, TFT_DARKGREY);

  // Draw number display area and frame
  tft.fillRect(DISP_X, DISP_Y, DISP_W, DISP_H, TFT_BLACK);
  tft.drawRect(DISP_X, DISP_Y, DISP_W, DISP_H, TFT_WHITE);

  // Draw keypad

And here is part of the output...
 ( the first two error messages (line 94 & line 107) are in the setup-part of the program...)

Archiving .pio\build\wemos_d1_mini32\lib6b2\libSPI.a
src/main.cpp: In function ‘void setup()’:
src/main.cpp:94:3: error: ‘touch_calibrate’ was not declared in this scope touch_calibrate();
src/main.cpp:94:3: note: suggested alternative: ‘touch_pad_t’
src/main.cpp:107:3: error: ‘drawKeypad’ was not declared in this scope
src/main.cpp: In function ‘void loop()’:
src/main.cpp:157:9: error: ‘status’ was not declared in this scope
status(""); // Clear the old status
src/main.cpp:157:9: note: suggested alternative: ‘stat’
status(""); // Clear the old status
src/main.cpp:169:9: error: ‘status’ was not declared in this scope
status(""); // Clear the old status
src/main.cpp:169:9: note: suggested alternative: ‘stat’
status(""); // Clear the old status
src/main.cpp:174:9: error: ‘status’ was not declared in this scope
status(“Sent value to serial port”);
src/main.cpp:174:9: note: suggested alternative: ‘stat’
status(“Sent value to serial port”);
src/main.cpp:181:9: error: ‘status’ was not declared in this scope
status(“Value cleared”);
src/main.cpp:181:9: note: suggested alternative: ‘stat’
status(“Value cleared”);
Compiling .pio\build\wemos_d1_mini32\FrameworkArduino\HWCDC.cpp.o
Compiling .pio\build\wemos_d1_mini32\FrameworkArduino\HardwareSerial.cpp.oCompiling .pio\build\wemos_d1_mini32\FrameworkArduino\IPAddress.cpp.o
Compiling .pio\build\wemos_d1_mini32\FrameworkArduino\IPv6Address.cpp.o
*** [.pio\build\wemos_d1_mini32\src\main.cpp.o] Error 1
======================= [FAILED] Took 8.80 seconds =======================```

Looks to me like you didn’t do the .ino.cpp conversion.

Please rename main.cppmain.ino and recompile.

If I add

#include “Extensions/Touch.h”
to my main.cpp-file i get these errors:

Compiling .pio\build\wemos_d1_mini32\src\main.cpp.o
In file included from src/main.cpp:26:
.pio/libdeps/wemos_d1_mini32/TFT_eSPI/Extensions/Touch.h:4:2: error: expected unqualified-id before 'public'
.pio/libdeps/wemos_d1_mini32/TFT_eSPI/Extensions/Touch.h:22:2: error: expected unqualified-id before 'private'

before the errors in the previous post..

Thank you Max, I followed your instructions and recompiled and IT WORKS !!
Very grateful for such a fast answer and a professional advise !!!

PS. Whats the differerence between copy/paste the contents of an .ino file into main.cpp
and recompiling it (as per your instructions) ??

/Regards Gurra

No that header file is special because if has no class definition but just the function prototypes that get injected inside the opened class TFT_eSPI declaration – you can’t include that from the outside.

A .ino file is not a valid .cpp file because it’s missing #include <Arduino.h> and all function prototype declarations. Please see FAQ for conversion.