B4R Question How to use getTouch from the TFT_eSPI library

Gerardo Tenreiro

Active Member
Licensed User
Hello group,

Since I'm unable to use the CANDIDO ILI9488 library, I'm trying to use the TFT_eSPI library. With this library, I was able to turn on the TFT and display objects and text.

Now I'm trying to use the touch component and I need the getTouch function, which is in the Extensions\Touch.h library.

I'm trying to load the library like this:
#include <TFT_eSPI.h>
#include <Extensions\Touch.h>


I call the function like this:
// Read if the screen has been touched and where
void ReadTouch (B4R::Object* o) {
getTouch(b4r_tft::_tft_px,b4r_tft::_tft_py,b4r_tft::_tft_touch_sense);
}

This error is generated, which cannot be resolved.
n file included from D:\TRASH\B4R\TFT_B4R\Objects\src\b4r_tft.cpp:59:
C:\Users\gtvpi\OneDrive\Documents\Arduino\libraries\TFT_eSPI/Extensions\Touch.h:4:2: error: expected unqualified-id before 'public'
4 | public:
| ^~~~~~
C:\Users\gtvpi\OneDrive\Documents\Arduino\libraries\TFT_eSPI/Extensions\Touch.h:25:2: error: expected unqualified-id before 'private'
25 | private:
| ^~~~~~~
D:\TRASH\B4R\TFT_B4R\Objects\src\b4r_tft.cpp: In function 'void ReadTouch(B4R::Object*)':
D:\TRASH\B4R\TFT_B4R\Objects\src\b4r_tft.cpp:171:27: error: invalid conversion from 'UInt' {aka 'short unsigned int'} to 'uint16_t*' {aka 'short unsigned int*'} [-fpermissive]
171 | getTouch(b4r_tft::_tft_px,b4r_tft::_tft_py,b4r_tft::_tft_touch_sense);
| ~~~~~~~~~^~~~~~~
| |
| UInt {aka short unsigned int}
C:\Users\gtvpi\OneDrive\Documents\Arduino\libraries\TFT_eSPI/Extensions\Touch.h:18:31: note: initializing argument 1 of 'uint8_t getTouch(uint16_t*, uint16_t*, uint16_t)'
18 | uint8_t getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
| ~~~~~~~~~~^
D:\TRASH\B4R\TFT_B4R\Objects\src\b4r_tft.cpp:171:44: error: invalid conversion from 'UInt' {aka 'short unsigned int'} to 'uint16_t*' {aka 'short unsigned int*'} [-fpermissive]
171 | getTouch(b4r_tft::_tft_px,b4r_tft::_tft_py,b4r_tft::_tft_touch_sense);
| ~~~~~~~~~^~~~~~~
| |
| UInt {aka short unsigned int}
C:\Users\gtvpi\OneDrive\Documents\Arduino\libraries\TFT_eSPI/Extensions\Touch.h:18:44: note: initializing argument 2 of 'uint8_t getTouch(uint16_t*, uint16_t*, uint16_t)'
18 | uint8_t getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
| ~~~~~~~~~~^
Error during build: exit status 1
Does anyone use or have they used this library?
How can I solve this problem?

I'm attaching the program I'm using; it's just for testing and to get started with the library.


Thank you very much
 

Attachments

  • TEST_TFT.zip
    4.6 KB · Views: 101

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

may be following information helps. Another discussion here, states:
B4X:
This library does not support touch screens on a parallel interface TFT. That is why the error message is generated.
This might be the case for your display, at least for the one I am using = touch not supported by this library. See below BTW.

Run the User_Setup_Sketch as suggested. See post #4 - output for my ESPCYD.

If you get it working: Think you would also need a looper to catch the touch event.

BTW
I have developed this library. May be it works for your hardware too. Look at the source how touch is implemented.
 
Last edited:
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
In the "User_Setup.h" file, I had already uncommented the TFT CS pin line. I followed the same instructions you sent me.
I think I need something else.
Any ideas?
Thanks


1742304359428.png
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Got a step further - see below - but issues
1. Touch not recognized = x,y,z remain 0
2. Your B4R program also compiles and uploads on my hardware but nothing is displayed.

Tried several but unfortunate can not get it to work = will stop here ... as using this library.
You might want read this also.

Recheck the location of the User_Setup.h.
There are probably more in various locations, like:
1 - Arduino libraries folder or
2 - c:\Users\YOURNAME\OneDrive\Docs\Arduino\libraries\TFT_eSPI\

Changed user_setup.h in location 2.
The test sketch read_user_setup compiled with info confirming touch:
B4X:
[code]
TFT_eSPI ver = 2.5.43
Processor    = ESP32
Frequency    = 240MHz
Transactions = Yes
Interface    = SPI
Display driver = 9341
Display width  = 240
Display height = 320
MOSI    = GPIO 13
MISO    = GPIO 12
SCK     = GPIO 14
TFT_CS   = GPIO 15
TFT_DC   = GPIO 2
TOUCH_CS = GPIO 33
TFT_BL           = GPIO 21
Font GLCD   loaded
Font 2      loaded
Font 4      loaded
Font 6      loaded
Font 7      loaded
Font 8      loaded
Smooth font enabled
Display SPI frequency = 27.00
Touch SPI frequency   = 2.50

Tested the sketch test_touch_controller
Issue: touch is not recognized.
 
Last edited:
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
I'll tell you.
1. In the "User_Setup_Select.h" file, comment out the line:
//#include <User_Setup.h> // Default setup is root library folder
and uncomment the line:
#include <User_Setups/Setup21_ILI9488.h> // Setup file for ESP32 and ILI9488 SPI bus TFT
This is because my TFT uses the ILI9488 and I have an ESP32.
2. In the "Setup21_ILI9488.h" file, assign the pins I have connected from the ESP32 to the TFT. The image is attached.
1742313751164.png

3. In the "Setup21_ILI9488.h" file, include the line:
#define TOUCH_CS 13
I added this line because it is the way the library recognizes that I want to use the TOUCH

4.- Now I want to create the function call:
uint8_t getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
and I write it like this:

// Lee si se toco la pantalla y donde
void LeeTactil (B4R::Object* o) {
tft.getTouch(b4r_tft::_tft_px,b4r_tft::_tft_py,b4r_tft::_tft_touch_sense);
}
5.- The three variables are defined as "INT"
Public TFT_Px As Int = 0 ' Touch X del TFT
Public TFT_Py As Int = 0 ' Touch Y del TFT
Public TFT_Touch_Sense As Int = 600 ' Sensibilidad del Touch
6.- When compiling in B4R this error appears:
B4R Versión: 4.00
Parseando código. (0.02s)
Building folders structure. (0.00s)
Compilando código. (0.01s)
Compilando proyecto (0.01s)
Compiling (ESP32 Dev Module) Error
D:\BASURA\B4R\TFT_B4R\Objects\src\b4r_tft.cpp: In function 'void LeeTactil(B4R::Object*)':
D:\BASURA\B4R\TFT_B4R\Objects\src\b4r_tft.cpp:171:31: error: invalid conversion from 'Int' {aka 'short int'} to 'uint16_t*' {aka 'short unsigned int*'} [-fpermissive]
171 | tft.getTouch(b4r_tft::_tft_px,b4r_tft::_tft_py,b4r_tft::_tft_touch_sense);
| ~~~~~~~~~^~~~~~~
| |
| Int {aka short int}
In file included from C:\Users\gtvpi\OneDrive\Documentos\Arduino\libraries\TFT_eSPI/TFT_eSPI.h:969,
from D:\BASURA\B4R\TFT_B4R\Objects\src\b4r_tft.cpp:59:
C:\Users\gtvpi\OneDrive\Documentos\Arduino\libraries\TFT_eSPI/Extensions/Touch.h:18:31: note: initializing argument 1 of 'uint8_t TFT_eSPI::getTouch(uint16_t*, uint16_t*, uint16_t)'
18 | uint8_t getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
| ~~~~~~~~~~^
D:\BASURA\B4R\TFT_B4R\Objects\src\b4r_tft.cpp:171:48: error: invalid conversion from 'Int' {aka 'short int'} to 'uint16_t*' {aka 'short unsigned int*'} [-fpermissive]
171 | tft.getTouch(b4r_tft::_tft_px,b4r_tft::_tft_py,b4r_tft::_tft_touch_sense);
| ~~~~~~~~~^~~~~~~
| |
| Int {aka short int}
C:\Users\gtvpi\OneDrive\Documentos\Arduino\libraries\TFT_eSPI/Extensions/Touch.h:18:44: note: initializing argument 2 of 'uint8_t TFT_eSPI::getTouch(uint16_t*, uint16_t*, uint16_t)'
18 | uint8_t getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
| ~~~~~~~~~~^
Error during build: exit status 1

Any ideas or solutions?

By the way, I can't find the read_user_setup script. What folder is it in or where can I find it?

Thank you very much.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

Error
B4X:
 'Int' {aka 'short int'} to 'uint16_t*' {aka 'short unsigned int*'}
In B4R: uint16_t (unsigned integer of length 16 bits, range 0..65535) = UInt
Solution
Define your vars as UInt.

read_user_setup sketch
In the Arduino examples for the TFT_eSPI library:
Files > Examples > TFT_eSPI > Test and Diagnostic folder
There is also the touch test sketch.

You will still need a looper to recognize touch events. See my library.
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
I defined the variables as "UINT" like this:
Public TFT_Px As UInt = 0 ' Touch X del TFT
Public TFT_Py As UInt = 0 ' Touch Y del TFT
Public TFT_Touch_Sense As UInt = 600 ' Sensibilidad del Touch
This error is generated
B4R Versión: 4.00
Parseando código. (0.03s)
Building folders structure. (0.00s)
Compilando código. (0.01s)
Compilando proyecto (0.01s)
Compiling (ESP32 Dev Module) Error
D:\BASURA\B4R\TFT_B4R\Objects\src\b4r_tft.cpp: In function 'void LeeTactil(B4R::Object*)':
D:\BASURA\B4R\TFT_B4R\Objects\src\b4r_tft.cpp:171:31: error: invalid conversion from 'UInt' {aka 'short unsigned int'} to 'uint16_t*' {aka 'short unsigned int*'} [-fpermissive]
171 | tft.getTouch(b4r_tft::_tft_px,b4r_tft::_tft_py,b4r_tft::_tft_touch_sense);
| ~~~~~~~~~^~~~~~~
| |
| UInt {aka short unsigned int}
In file included from C:\Users\gtvpi\OneDrive\Documentos\Arduino\libraries\TFT_eSPI/TFT_eSPI.h:969,
from D:\BASURA\B4R\TFT_B4R\Objects\src\b4r_tft.cpp:59:
C:\Users\gtvpi\OneDrive\Documentos\Arduino\libraries\TFT_eSPI/Extensions/Touch.h:18:31: note: initializing argument 1 of 'uint8_t TFT_eSPI::getTouch(uint16_t*, uint16_t*, uint16_t)'
18 | uint8_t getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
| ~~~~~~~~~~^
D:\BASURA\B4R\TFT_B4R\Objects\src\b4r_tft.cpp:171:48: error: invalid conversion from 'UInt' {aka 'short unsigned int'} to 'uint16_t*' {aka 'short unsigned int*'} [-fpermissive]
171 | tft.getTouch(b4r_tft::_tft_px,b4r_tft::_tft_py,b4r_tft::_tft_touch_sense);
| ~~~~~~~~~^~~~~~~
| |
| UInt {aka short unsigned int}
C:\Users\gtvpi\OneDrive\Documentos\Arduino\libraries\TFT_eSPI/Extensions/Touch.h:18:44: note: initializing argument 2 of 'uint8_t TFT_eSPI::getTouch(uint16_t*, uint16_t*, uint16_t)'
18 | uint8_t getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
| ~~~~~~~~~~^
Error during build: exit status 1

Run the Arduino example "Read_User_Setup.ino" and this output is generated via serial port:
B4X:
TFT_eSPI ver = 2.5.43
Processor    = ESP32
Frequency    = 240MHz
Transactions = Yes
Interface    = SPI
Display driver = 9488
Display width  = 320
Display height = 480
MOSI    = GPIO 23
MISO    = GPIO 19
SCK     = GPIO 18
TFT_CS   = GPIO 5
TFT_DC   = GPIO 2
TOUCH_CS = GPIO 13
Font GLCD   loaded
Font 2      loaded
Font 4      loaded
Font 6      loaded
Font 7      loaded
Font 8      loaded
Smooth font enabled
Display SPI frequency = 40.00
Touch SPI frequency   = 2.50

What could be happening?
I'm surprised you have * in the variables in the TOUCH.H library. What are they?
uint8_t getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
Is my definition correct in B4R?
// Lee si se toco la pantalla y donde
void LeeTactil (B4R::Object* o) {
tft.getTouch(b4r_tft::_tft_px,b4r_tft::_tft_py,b4r_tft::_tft_touch_sense);
}
Thank you very much for your help and time.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
These are pointers. You have to use like ...

B4X:
void GetTouchTFT(B4R::Object* o) {
    uint16_t x, y;

    tft.getTouch(&x, &y, b4r_tft::_tft_touch_sense);

    b4r_tft::_tft_px = x;
    b4r_tft::_tft_py = y;
}
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
Correct, now the program compiles and runs, but the results aren't correct. I use this ADDLOOP loop to continuously read the Touch, but without touching it, it's already displaying strange values.

' Lee el Tactil del TFT
Sub Lee_Touch
RunNative("GetTouchTFT",Null)
If TFT_M_Px <> TFT_Px Then
Log("Cambio X ",TFT_Px," ... ",TFT_Touch_Sense)
TFT_M_Px = TFT_Px
End If
If TFT_M_Py <> TFT_Py Then
Log("Cambio Y ",TFT_Py," ... ",TFT_Touch_Sense)
TFT_M_Py = TFT_Py
End If
End Sub
Cambio X 10 ... 3600
Cambio X 0 ... 3600
Cambio X 10 ... 3600
00:03:05
Cambio X 0 ... 3600
Cambio X 10 ... 3600
Cambio X 0 ... 3600
Cambio X 10 ... 3600
Cambio X 0 ... 3600
Cambio X 10 ... 3600
Cambio X 0 ... 3600
Cambio X 10 ... 3600
Cambio X 0 ... 3600
Cambio X 10 ... 3600
Cambio X 0 ... 3600
Cambio X 10 ... 3600
Cambio X 0 ... 3600
Cambio X 10 ... 3600
Cambio X 0 ... 3600
Cambio X 10 ... 3600
Cambio X 0 ... 3600
Cambio X 10 ... 3600
Cambio X 0 ... 3600
Cambio X 10 ... 3600
Cambio X 0 ... 3600
Cambio X 10 ... 3600
Cambio X 0 ... 3600
Cambio X 10 ... 3600

I need to check the library further to see what's going on.
Thank you very much for your invaluable help.

Is the Touch working fine for you?
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Good to hear it is compiling.

I have not further tested because I am using this library (developed by me). Touch can be enabled or disabled.
The library is working fine and I am developing it further.
 
Upvote 0
Top