Ili9341

Status
Not open for further replies.

sebraun

Member
So I've got a resitive touch display and a 3.6 up and running with the example sketches for both the tft and the ts. Can somebody point me in the proper direction so I can figure out how all those impossibly large numbers being returned to the p.x and p.y functions actually correlate to a 320x240 pixel screen?
 
I made a map function in posts two years ago that is posted on the forum - it doesn't seem to made it into the library or any sketches as I went. KurtE posted a similar version a couple months back.

I just did a BING search and it hits this November 2015 thread/post that may point to examples that should still be on GitHub: https://forum.pjrc.com/threads/31634-ILI9341-and-XPT2046-for-Teensy-Touchscreen-320x240-display

Indeed - here is a link to the tsMap[] array I made that works in all four rotations as 1,2,3,4 where the [0] element is the base number for the X and Y Min and Max in the default rotation on the display I had.

There may be newer versions of the display hardware out with different extents or default rotation.

Code:
TS_MAP tsMap[5] = { {200, 3700, 325, 3670 }, { 0, 319, 0, 239 }, { 319, 0, 0, 239 }, { 319, 0, 239, 0 }, { 0, 319, 239, 0 } };

This code refers to that array and for current rotation (TS_Rotate) gives X and Y from touch point pp.x and pp.y:
Code:
  xx = map(pp.x, tsMap[0].xt, tsMap[0].xb, tsMap[TS_Rotate].xt, tsMap[TS_Rotate].xb);
  yy = map(pp.y, tsMap[0].yl, tsMap[0].yr, tsMap[TS_Rotate].yl, tsMap[TS_Rotate].yr);

<edit>: hopefully that leads you to a good answer. If not check the rest of that thread or similar threads perhaps I gave more details as I evolved that code. If you find a better post please drop it here. If Kurt hasn't gotten his map code into a sample I should hook up a display and get that done. There was a recent add to the library for rotation I didn't follow - rotation was already supported as I used it - perhaps it was improved and this could find a good home in that sample.
 
In my version of the library (ili9341_t3n), I have a version of the touch paint program that was updated to use the touch controller on the PJRC display. The sources are up at: https://github.com/KurtE/ILI9341_t3n/blob/master/examples/touchpaint_xpt2046/touchpaint_xpt2046.ino
Again it is using my library, but probably just a change in include file and object name (remove the trailing n), should work as well using Pauls version.

Wow - my version is so much more :cool: --- :) It allows the map to follow any runtime orientation. The base line extent numbers you arrived at are mildly different. [hi Kurt]

sebraun - KurtE's version might make more sense and be easier to follow if you only need to support a single orientation, but the math is the same using the MAP function. Using the one example showing POINT values what I did was drag a pointer off all four edges to get the MAX and MIN numbers for both X and Y. Those are the numbers that represent the large screen response numbers that MAP down to the fewer Display pixel numbers.
 
Thanks very much to all for the rapid response. After much testing and examination of all the source code that I can find (including the Adafruit), I have determined that I am not really clear what exactly is being returned by the ts.getPoint() function. However.....
By using 3800 for the max on both the x and y axis and 0 for the min for both y axis with the map() function, dividing by 10, and then finding the reciprocal, I am able to pinpoint the box that I want to use as a selector point with a reasonable amount of accuracy. Not pretty but good enough.
I also have a capacitive touchscreen from Adafruit running on a Teensy 3.2. This one is a lot easier to figure out where the actual x and y coordinates are. Not sure why I decided to use the PJRC resistive screen on this project.
Once again, thanks for the help.
 
Status
Not open for further replies.
Back
Top