You are on page 1of 0

ht t p: / / el ect r oni cs. henni ngkar l sen.

com ( C) 2013 Henni ng Kar l sen



UTouch
Arduino and chipKit Universal TFT touchscreen library

Manual


UTouch l i br ar y Page 1

PREFACE:
Thi s l i br ar y was made t o compl ement UTFT t o pr ovi de t ouch scr een f unct i onal i t y.

You can al ways f i nd t he l at est ver si on of t he l i br ar y at
http://electronics.henningkarlsen.com/

I f you make any modi f i cat i ons or i mpr ovement s t o t he code, I woul d appr eci at e t hat you shar e
t he code wi t h me so t hat I mi ght i ncl ude i t i n t he next r el ease. I can be cont act ed t hr ough
http://electronics.henningkarlsen.com/contact.php.

For ver si on i nf or mat i on, pl ease r ef er t o version.txt.

REGARDING CALIBRATION:
Al l t ouch scr eens wi l l have sl i ght var i at i ons. I t i s t her ef or e i mpor t ant t hat you cal i br at e
your par t i cul ar t ouch scr een f or t he best possi bl e per f or mance.

To cal i br at e your t ouch scr een you wi l l need t o r un t he UTouch_Cal i br at i on sket ch suppl i ed i n
t he exampl es of t he l i br ar y.

Bef or e you compi l e and upl oad t he sket ch t her e ar e a coupl e of t hi ngs you must do.
1. Make sur e you have uncomment ed t he cor r ect sect i on f or your devel opment boar d
2. Make sur e t he UTFT di spl ay model code i s cor r ect f or your di spl ay modul e
3. Make sur e t he TOUCH_ORI ENTATI ON def i ne i s cor r ect . You can f i nd a l i st of t he cor r ect
par amet er f or al l t he t est ed di spl ays i n t he UTouch_Supported_display_modules PDF.

Fur t her i nst r uct i ons wi l l be gi ven on scr een when you r un t he sket ch.

Remember t hat i f you have mor e t han one t ouch di spl ay modul e you may have t o r un t he
cal i br at i on on each modul e.

Some touch screens, espcially the larger ones (4.3 and larger), have some flaws where they
have problems registering touch near the edges. The calibration sketch tries to take this into
account when calibrating. Because of this some calibration points takes longer to register.

I t i s al so r ecommended t hat you power your Ar dui no/ chi pKi t usi ng an ext er nal power sour ce when
r unni ng t he cal i br at i on on 4. 3 and l ar ger scr eens.
Thi s l i br ar y i s l i censed under a CC BY-NC-SA 3.0 ( Cr eat i ve Commons At t r i but i on-
NonCommer ci al - Shar eAl i ke 3. 0 Unpor t ed) Li cense.

For mor e i nf or mat i on see: http://creativecommons.org/licenses/by-nc-sa/3.0/

UTouch l i br ar y Page 2
Defined Literals:

Orientation
For use with InitTouch()

PORTRAI T:
LANDSCAPE:
0
1

Precision
For use with setPrecision()

PREC_LOW:
PREC_MEDI UM:
PREC_HI :
PREC_EXTREME:
1
2
3
4





UTouch l i br ar y Page 3
Functions:

UTouch(TCLK, TCS, TDIN, TDOUT, IRQ);
The main class of the interface.

Parameters: TCLK: Pi n f or Touch Cl ock ( D_CLK)
TCS: Pi n f or Touch Chi p Sel ect ( D_CS)
TDI N: Pi n f or Touch Dat a i nput ( D_DI N)
TDOUT: Pi n f or Touch Dat a out put ( D_OUT)
I RQ: Pi n f or Touch I RQ ( DPeni r q)
Usage: UTouch myTouch( 15, 10, 14, 9, 8) ; / / St ar t an i nst ance of t he UTouch cl ass

InitTouch([orientation]);
Initialize the touch screen and set display orientation. If the library is used together with UTFT the orientation should be set to
the same orientation for both libraries.

Parameters: or i ent at i on: <optional>
PORTRAI T
LANDSCAPE ( def aul t )
Returns: Not hi ng
Usage: myTouch. I ni t Touch( ) ; / / I ni t i al i ze t he t ouch scr een

dataAvailable();
Check to see if new data from the touch screen is waiting.

Parameters: None
Returns: Bool ean: t r ue means dat a i s wai t i ng, ot her wi se f al se
Usage: check = myTouch. dat aAvai l abl e( ) / / See i f dat a i s wai t i ng

read();
Read waiting data from the touch screen. This function should be called if dataAvailable() is true. Use getX() and getY() to get
the coordinates.

Parameters: None
Returns: Not hi ng
Usage: myTouch. r ead( ) ; / / Read dat a f r omt ouch scr een
Notes: Af t er cal l i ng r ead( ) , r aw dat a f r omt he t ouch scr een i s avai l abl e i n t he var i abl es TP_X and TP_Y. Do
not use t hese i f you do not know how t o handl e t he r aw dat a. Use get X( ) and get Y( ) i nst ead.

getX();
Get the x-coordinate of the last position read from the touch screen.

Parameters: None
Returns: I nt eger
Usage: x = myTouch. get X( ) ; / / Get t he x- coor di nat e

getY();
Get the y-coordinate of the last position read from the touch screen.

Parameters: None
Returns: I nt eger
Usage: y = myTouch. get Y( ) ; / / Get t he y- coor di nat e

setPrecision(precision);
Set the precision of the touch screen.

Parameters: pr eci si on: PREC_LOW, PREC_MEDIUM, PREC_HI, PREC_EXTREME
Returns: Not hi ng
Usage: myTouch. set Pr eci si on( PREC_MEDI UM) ; / / Set pr eci si on t o medi um
Notes: Hi gher pr eci si on dat a wi l l t ake l onger t o r ead, so t ake car e when usi ng PREC_HI or PREC_EXTREME wi t h
f ast - movi ng i nput .