TouchCal


TouchCal logo
TouchCal’ (Arduino Library)  -  TouchCal Mini-library for SPI touch screens (XPT2046_Touchscreen) - by GuerraTron24 By: Juan José Guerra Haba - dinertron@gmail.com  -  Oct, 2024
Web: GrTron.es , GuerraTron.github
License: Apache + Open GPL v.3. Keep credit, please.
Versión: 1.1.1
Proyect: Touch-Screen C++   Package: TouchCal.h   Namespace: tc


🏠︎ TOC 🖇️ (Contents Table)

TouchCal logo TouchCal v1.1.1 by GuerraTron-24

📋-Intro

Mini-library for SPI touchscreens (needs XPT2046_Touchscreen).

It has utilities for the TouchScreen such as screen calibration, checking valid touch based on pressure, Lissajous figures to check screen symmetry, and even “Dark-Mode” without display ..

Based on the examples from the TFT_eSPI library by bodmer; uses XPT2046_Touchscreen by Paul Stoffregen. (WHAT A WONDERFUL UTILITIES).

Although it is more visual and aesthetic to use a display, there are actually projects where they are not essential. That is why this library has NO DIRECT DEPENDENCE with TFT_eSPI, you can work without that “wonderful utility” (but you can with XPT2046_Touchscreen).

This mini-library arises from the need to obtain touch screen configuration parameters as a result of some experiments in which the original function TFT_eSPI::calibrateTouch(..) failed, the device would hang with certain screen, pin and SPI configurations.

I have made the calibration function more visual even though it increases the computational cost, since it is not supposed to be a user library in the usual sense, but rather a tool for the programmer who will surely inhibit it when the debugging is finished.

v1.1.1

🔧-Use

The main function would be “calibration(..)” which takes as parameters (POINTERS) the touchscreen and the screen (if available), as well as colors and sizes for the corner arrows (just like “TFT_eSPI::calibrateTouch(..)”). The function performs the same checks as the original plus some extra additions, but relies on the touchscreen object passed as a parameter and which is supposed to be already initialized to detect touches, instead of the default object that the original library attacks.

Thus, with this library it DOES NOT MATTER which pins the touchscreen is connected to, nor what type of SPI it uses, since this is established prior to using this library. The screen parameter (TFT_eSPI *tft) is used to display the indications and the read data, although it is not essential since the same data is being sent in parallel to the serial monitor (what a curious expression, “parallel-serial”!), and can even be obtained at runtime through the global array TC_PARS\[5\].

What is needed are the screen dimensions: TFT_HEIGHT and TFT_WIDTH, and the predefined colors, as well as the rotation TC_ROTATION; depending on this rotation the values ​​of “width” and “height” will be inverted.

ATTENTION: Define the rotation to be used with the screen and the touch in TC_ROTATION, or better in “setRotation(..)” (from 0 to 3)

✨-Improvements

Future improvements are planned in later versions, perhaps more drivers and support for more screens, new functions, perhaps change from namespace to class, separation into source files and header, … Future improvements are planned in later versions, perhaps more drivers and support for more screens, new functions, perhaps change from namespace to class, separation into source files and header, …

It has only been tested on a board with ESP32 (DOIT ESP32 DevKIT v1) and TFT-SPI 3.2” - 240x320

⌨️-Preview

TouchCal Preview 1 TouchCal Preview 2

💣-Fixs

TODO: Code improvement and refactoring, bug fixes, .. EVERYTHING HAS BEEN IMPLEMENTED IN A SINGLE “.H” HEADER FILE DUE TO NUMEROUS PROBLEMS IN THE “LINKER” WHEN SEPARATING IT INTO “.cpp” FILES

🔗-Depends

It has a direct dependency on “XPT2046_Touchscreen”
Although it does NOT have a DIRECT DEPENDENCE on “TFT_eSPI” (you can work without that “wonderful utility”) the truth is that the experience improves quite a bit with it.

🌍-Sources

TFT_eSPI de Bodmer,
XPT2046_Touchscreen de Paul Stoffregen,
https://forum.arduino.cc/, ..

🎁-Acknowledgements

Many thanks to Bodmer, Paul Stoffregen, and all those who make free code for developing super useful tools for everyone; this time also to Microsoft for its VSC, without this tool the creation of the library would have been impossible.
.. and in general to all the altruistic world that generates code and makes it open-source. Also to the world of Arduino and open-hardware.

✒️-Sign:

Enjoy using it. I hope someone finds it as useful as I did.

2024 - TouchCal logo GuerraTron-24 ® GuerraTron Github


⌨️ with ❤️ by Juan José Guerra 😊

🔝