I added a routine (based on the X / Y reading made by the Utouch library) to calculate the Z axis, but the XPT2046 datasheet is very confusing, I would like a second opinion on the XPT2046 configuration that I need to set the value correct to calculate the resistance Z.
touch_WriteData(0xB4);
pulse_high(P_CLK, B_CLK);
TP_Z1 = touch_ReadData();
touch_WriteData(0xC4);
pulse_high(P_CLK, B_CLK);
TP_Z2 = touch_ReadData();
To read the value Z1 I set the value 0xB4,
0xB4 in binary is 1 011 0 1 00:
- B7: start bit
- B6-4: channel selection bit = Z1- position
- B3: 12-bit mode
- B2: Simple connection
- B1-0: power down mode
To read the value Z2 I set the value 0xC4,
0xB4 in binary is 1 100 0 1 00:
- B7: start bit
- B6-4: channel selection bit = Z2- position
- B3: 12-bit mode
- B2: Simple connection
- B1-0: power down mode
But in some codes that I found on the internet, the setting value is not always the same, some codes use different values (from the value I used: 0xB4 / 0xC4).
Although the value I got is very comfortable, but I need to confirm if it is the correct value, my touch plate results in a value close to 500 for the Z axis when touched by a pen.
Note: the Utouch library is obsolete, and has been replaced by the URtouch library, it is not free for commercial use:
/*
URTouch.h - Arduino/chipKit library support for Color TFT LCD Touch screens
Copyright (C)2016 Rinky-Dink Electronics, Henning Karlsen. All right reservedBasic functionality of this library are based on the demo-code provided by
ITead studio.You can find the latest version of the library at
http://www.RinkyDinkElectronics.com/This library is free software; you can redistribute it and/or
modify it under the terms of the CC BY-NC-SA 3.0 license.
Please see the included documents for further information.Commercial use of this library requires you to buy a license that
will allow commercial use. This includes using the library,
modified or not, as a tool to sell products.The license applies to all part of the library including the
examples and tools supplied with the library.
*/
XPT2046.zip (1.94 KB)