Now the screen is in portrait position meaning that x should be 240 and y 320 max. Below are the logs of each corner
LEFT-UP 235,15 (lets skip the fact that it should be 240,0, as ther can be +- 15pixels difference)
RIGHT-UP 230, 330
LEFT-BOTTOM 0,9
RIGHT-BOTTOM 0,355
The problem in PORTRAIT mode are:
x is longer than y it is reverted
touching LEFT-UP corner prints RIGHT-UP coordinates
touching RIGHT-UP corner prints RIGHT-BOTTOM coordinates
touching LEFT-BOTTOM corner prints LEFT-UP coordinates
touching RIGHT-BOTTOM corner prints LEFT-BOTTOM coordinates
in LANDSCAPE mode it is even worse
also x is longer than y (xmax = 380, ymax = 240
points are about half screen away, looks like screen ends 1,5cm above the real end and bottom 1,5 cm of the screen gives the same coordinates as 1,5 above
Moreover it doesnt work every restart - sometimes turning power of doesnt help, after some restarts / uploading from Arduino IDE 1.5.5 r2 it works but then it prints wrong coordonates.
I´m used voltage dividers, made it with 1K and 2K resistors in this lines: TFT_CS, TFT_D/C, TFT_RESET, TFT_MOSI, TFT_SCK. All soldered on proto-shield for arduino UNO, and some pins and proto-wires recycled. It´s some... ugly thing..., but it´s efficient
i got problems with utouch and getting the right coardinates too, so i am working on getting spi work for that chip. Why spend a lot of pins and waste time on bit banging?
This is how far i hawe come:
on 8 mhz i need "SPI.setClockDivider(SPI_CLOCK_DIV4);" to get it work, if you running a 16 mhz chip you vill need to add SPI.setClockDivider(SPI_CLOCK_DIV8);. ili9341 should handel a spi clock divider of two. So add clock divider by 8 in beginning of touch commands and clock divider by 2 before tft commands.
for exemple: if the lowest reading in x is 440. then remove 440 from ttx. the highest is 3560, remove 440 from that and divide it into the pixels and you get 13.
This simple touch library for the 2046 touch screen driver may be of interest and is usable with any graphics library.
The example in the library reports raw and transformed x,y touch coords via the Serial port at 38400 baud, it does not plot/draw anything on the screen as that needs a graphics library and not everyone uses the same library set.
By setting the screen resolution to a low value say 3,4 the display will be divided into a grid of 12 touch zones. It is also possible to define the touch rectangle to be anywhere and any size on the screen so for example the valid touch zones can be over a 4 x 4 key pad matrix, and reading back Zone() will report which zone was touched, this avoids tedious checking of coordinate ranges. More examples will follow.
This is a library that is being developed further so it is quite simple and does not include touch filtering at the moment. The aim is to store calibration values in the Arduino's EEPROM so that the libraries do not have to be tweaked with calibration values for each different display you have.
Control signals are bit bashed but reading x and y values only takes just over 1 millisecond.