Check this code please
Hello,
this is my first propeller project. I try to read touch coordinates from uLCD-32PT 3.2" 240x320px LCD from 4D systems. So far I was able to control the display (write strings, images, videos etc)... But I'm straggling for 3 days now to get right XY touch coords from it. Received X coord is correct but Y is not, always about 100px more.
The datasheet says:
For serial send "cmd, mode"
CMD: 6F(hex) or o(ascii) : Command header byte
MODE:...04hex : Get Touch status, 05hex : Get Touch coordinates
Response: x_coord(msb:lsb), y_coord(msb:lsb)
For testing I create image with 3 check points,at (X-20px,Y-20px), (X-80px, Y-20px) and (X-120px, Y-60px) upload it to the display and try to read XY, than to draw the circle at that loacation.
With this code:
But as you can see at attached image, Y coordinate is always missed.
I have no idea what I'm doing wrong, can you help me?
here is debug from PST:
Thank you
this is my first propeller project. I try to read touch coordinates from uLCD-32PT 3.2" 240x320px LCD from 4D systems. So far I was able to control the display (write strings, images, videos etc)... But I'm straggling for 3 days now to get right XY touch coords from it. Received X coord is correct but Y is not, always about 100px more.
The datasheet says:
For serial send "cmd, mode"
CMD: 6F(hex) or o(ascii) : Command header byte
MODE:...04hex : Get Touch status, 05hex : Get Touch coordinates
Response: x_coord(msb:lsb), y_coord(msb:lsb)
For testing I create image with 3 check points,at (X-20px,Y-20px), (X-80px, Y-20px) and (X-120px, Y-60px) upload it to the display and try to read XY, than to draw the circle at that loacation.
With this code:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VAR
BYTE X[2],Y[2]
OBJ
disp: "Simple_Serial"
pst: "Parallax Serial Terminal"
PUB start
pst.Start(9600)
pst.Str(string("PST ready",13))
disp.init(25, 24, 9600)
waitcnt(clkfreq*2+cnt)
disp.tx($55) ' Auto baud
GET_ACK
disp.tx($45) ' Clear display
GET_ACK
GET_TOUCH_XY ' Get touch XY cordintes
PUB GET_TOUCH_XY | idx
ENABLE_TOUCH '
PUT_IMG ' Image for testing coordinates
repeat
disp.tx($6F) ' Check if
disp.tx($04) ' touch pressed cmd
GET_ACK
idx:= disp.rx
if idx==1 ' if so
disp.tx($6F) ' Get
disp.tx($05) ' x_coord(msb:lsb), y_coord(msb:lsb)
X[1] := disp.rx
X[0] := disp.rx
Y[1] := disp.rx
Y[0] := disp.rx
pst.str(string("MSB X : ")) ' Debug via PST
pst.Dec(X[1])
pst.NewLine
pst.str(string("LSB X : "))
pst.Dec(X[0])
pst.NewLine
pst.str(string("MSB Y : "))
pst.Dec(Y[1])
pst.NewLine
pst.str(string("LSB Y : "))
pst.Dec(Y[0])
pst.NewLine
pst.NewLine
pst.DEC(word[@X])
pst.str(string(", "))
pst.DEC(word[@Y])
pst.newline
disp.tx($43) ' Now draw
disp.tx(X[1]) ' circle
disp.tx(X[0])
disp.tx(Y[1]) ' to the
disp.tx(Y[0]) ' display
disp.tx($00) ' at the same XY
disp.tx($05)
disp.tx($00)
disp.tx($1F)
GET_ACK
PUB ENABLE_TOUCH
disp.tx($59)
disp.tx($05)
disp.tx($00)
GET_ACK
PUB GET_ACK | ack
ack:=disp.rx
if ack==$06
pst.Str(string(13,"ACK",13))
else
pst.Str(string("NACK",13))
PUB PUT_IMG
disp.tx($40)
disp.tx($49)
disp.tx($00)
disp.tx($00)
disp.tx($00)
disp.tx($00)
disp.tx($00)
disp.tx($F0)
disp.tx($01)
disp.tx($40)
disp.tx($10)
disp.tx($00)
disp.tx($02)
disp.tx($58)
GET_ACK
But as you can see at attached image, Y coordinate is always missed.
I have no idea what I'm doing wrong, can you help me?
here is debug from PST:
#1 dot pressed:
MSB X : 0
LSB X : 19
MSB Y : 0
LSB Y : 137
Dec values: 19, 137
#2 dot pressed:
MSB X : 0
LSB X : 77
MSB Y : 0
LSB Y : 137
Dec values: 77, 137
#3 dot pressed:
MSB X : 0
LSB X : 119
MSB Y : 0
LSB Y : 157
Dec values: 119, 157
Thank you
Comments