Touch panel issues on mcufriend ILI9325

ok, where to begin.

i have a 2.4 lcd shield, and all of the xamples somehow run fine. so as far as i know the touch screen works. i am trying to use the adafruit touchscreen library, the paint example works, however i cannot make the link in my brain between how the adc values become p.x and p.y, running the adafruit example here:

// Touch screen library with X Y and Z (pressure) readings as well
// as oversampling to avoid 'bouncing'
// This demo code returns raw readings, public domain

#include <stdint.h>
#include "TouchScreen.h"

// These are the pins for the shield!
#define YP A1  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 7   // can be a digital pin
#define XP 6   // can be a digital pin

#define MINPRESSURE 10
#define MAXPRESSURE 1000

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

void setup(void) {
  Serial.begin(9600);
}

void loop(void) {
  // a point object holds x y and z coordinates
  TSPoint p = ts.getPoint();
  
  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
     Serial.print("X = "); Serial.print(p.x);
     Serial.print("\tY = "); Serial.print(p.y);
     Serial.print("\tPressure = "); Serial.println(p.z);
  }
}

i never get a pixle point that is in the range of my screen. so how do you make the data useable?

[code// Touch screen library with X Y and Z (pressure) readings as well
// as oversampling to avoid 'bouncing'
// This demo code returns raw readings, public domain

#include <stdint.h>
#include "TouchScreen.h"

// These are the pins for the shield!
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A1 // must be an analog pin, use "An" notation!
#define YM 6 // can be a digital pin
#define XP 7 // can be a digital pin

int x;
int y;
#define MINPRESSURE 10
#define MAXPRESSURE 1000

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 150);

void setup(void) {
Serial.begin(9600);
}

void loop(void) {
// a point object holds x y and z coordinates
TSPoint p = ts.getPoint();

pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
pinMode(XP, OUTPUT);
pinMode(YM, OUTPUT);
// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
x=map(p.x,1000,1023,0,240);
y=map(p.y,1000,1023,0,320);
Serial.print("X = "); Serial.print(x);
Serial.print("\tY = "); Serial.print(y);
Serial.print("\tPressure = "); Serial.println(p.z);
}
}][/code]

when i use utouch calibration and plug the calibration values in i still get no usable information. since its a shield its not like i can just wire the panel up direct and im not even sure that measuring the resistance will give an accurate reading based on the fact that the pins are shared with other things.

advice?

p.x has typical values between 100 and 950.
The ADC can only produce 0 .. 1023 anyway.

The map() function scales a value from one range to another. Look at the Arduino Reference.

If your input range is 1000 to 1023, a typical input value e.g. 500 is going to be mapped to a VERY large negative number.

You would normally scale the typical range e.g.

X = map(p.x, 950, 100, 0, 240);   // e.g. TS_LEFT=950,  TS_RT=100

Your 1000 .. 1023 range has got 24 discrete steps. or 10 pixels per step
My 950 .. 100 range has got 851 steps. or 0.28 pixels per step

David.

i did that because when i use it without map, say i touch the upper left corner and drag across the x axis i only have output between 700 and 996, i suppose i would say i dont have a full scale output.

example:

X:

X = 777 Y = 861 Pressure = 994
X = 777 Y = 861 Pressure = 991
X = 778 Y = 860 Pressure = 995
X = 789 Y = 853 Pressure = 956
X = 801 Y = 844 Pressure = 897
X = 812 Y = 836 Pressure = 864
X = 820 Y = 828 Pressure = 814
X = 828 Y = 824 Pressure = 794
X = 834 Y = 817 Pressure = 761
X = 843 Y = 813 Pressure = 759
X = 853 Y = 808 Pressure = 738
X = 863 Y = 801 Pressure = 704
X = 871 Y = 794 Pressure = 670
X = 879 Y = 790 Pressure = 661
X = 884 Y = 782 Pressure = 631
X = 891 Y = 780 Pressure = 628
X = 897 Y = 773 Pressure = 610
X = 903 Y = 769 Pressure = 596
X = 909 Y = 763 Pressure = 575
X = 916 Y = 759 Pressure = 569
X = 922 Y = 753 Pressure = 549
X = 931 Y = 749 Pressure = 549
X = 939 Y = 741 Pressure = 524
X = 946 Y = 736 Pressure = 514
X = 952 Y = 731 Pressure = 505
X = 959 Y = 727 Pressure = 502
X = 965 Y = 721 Pressure = 492
X = 973 Y = 721 Pressure = 499
X = 979 Y = 724 Pressure = 513
X = 985 Y = 736 Pressure = 556
X = 989 Y = 758 Pressure = 641
X = 993 Y = 794 Pressure = 797
X = 994 Y = 802 Pressure = 840
X = 996 Y = 814 Pressure = 909

Y:

X = 965 Y = 694 Pressure = 476
X = 967 Y = 695 Pressure = 476
X = 970 Y = 695 Pressure = 481
X = 973 Y = 696 Pressure = 482
X = 659 Y = 691 Pressure = 327
X = 976 Y = 694 Pressure = 481
X = 660 Y = 693 Pressure = 332
X = 981 Y = 701 Pressure = 502
X = 653 Y = 707 Pressure = 352
X = 984 Y = 713 Pressure = 539
X = 634 Y = 731 Pressure = 388
X = 995 Y = 799 Pressure = 885
X = 800 Y = 933 Pressure = 995
X = 801 Y = 933 Pressure = 996
X = 801 Y = 933 Pressure = 996
X = 807 Y = 930 Pressure = 955
X = 812 Y = 925 Pressure = 912
------------------------------------------------ truncated.....
X = 883 Y = 968 Pressure = 917
X = 884 Y = 968 Pressure = 911
X = 885 Y = 969 Pressure = 912
X = 886 Y = 970 Pressure = 921
X = 886 Y = 970 Pressure = 914
X = 889 Y = 972 Pressure = 934
X = 890 Y = 973 Pressure = 930
X = 891 Y = 973 Pressure = 917
X = 892 Y = 974 Pressure = 924
X = 897 Y = 976 Pressure = 943
X = 899 Y = 976 Pressure = 942
X = 900 Y = 977 Pressure = 925
X = 905 Y = 979 Pressure = 948
X = 909 Y = 981 Pressure = 957
X = 910 Y = 981 Pressure = 942
X = 912 Y = 982 Pressure = 943
X = 915 Y = 984 Pressure = 945
X = 917 Y = 984 Pressure = 953
X = 918 Y = 985 Pressure = 951
X = 921 Y = 987 Pressure = 957
X = 923 Y = 987 Pressure = 961
X = 927 Y = 989 Pressure = 981
X = 930 Y = 990 Pressure = 991
X = 932 Y = 992 Pressure = 992
X = 934 Y = 992 Pressure = 985
X = 939 Y = 994 Pressure = 994
X = 940 Y = 995 Pressure = 997

Y has way more values but x is pretty small in value range. these results are also using a stylus it is much much worse when you use your finger.

i read the reference for map a few days ago, but its hard to plan for the eventuality of something when you have no idea what number your going to get, i have used map before but have since triple checked to make sure my usage (where the numbers go) are correct. the numbers in the map code just happened to be the iteration of "what if" that i was currently on, i had them perfectly set with the values from the utouch calibration example and still nothing right, i have tried to rule out every thing i have removed the external wiring and put the shield right onto the mega, ive dug threw an hours worth of my storage to find an old dell axim so i could jack the resistive screen stylus, i 3d printed a nintendo ds stylus, i took the plastic cover off the screen (which i never do) but honestly i dont know what im looking at except its not pixel by pixel output, the output here is the ADC value, which i dont know how to move that to px by px values except with map. and if that is the case then how does the utouch calibration work because it doesn't use map, it tells you what to put in the rest of the map commands. Ive read up on how others are using touch screens and how all the wiring works in theory, but with the pins being shared it doesn't really apply, and alot of the documentation you can find uses touchscreen.h so pretty much all the code you can find is all the same.

wait a second....

your saying

X = map(p.x, 950, 100, 0, 240);   // e.g. TS_LEFT=950,  TS_RT=100

which is opposite of what the utouch calibration says to do:

x = map(p.x, LEFT, RT, 0, tft.width());

also different than what it says for the map documentation...

map(value, fromLow, fromHigh, toLow, toHigh)

when i take this into consideration Y works greatish:

X = 27	Y = 6	Pressure = 999
X = 27	Y = 6	Pressure = 997
X = 27	Y = 6	Pressure = 996
X = 27	Y = 6	Pressure = 996
X = 27	Y = 6	Pressure = 970
X = 27	Y = 8	Pressure = 921
X = 27	Y = 8	Pressure = 891
X = 27	Y = 8	Pressure = 893
X = 27	Y = 9	Pressure = 862
X = 27	Y = 9	Pressure = 850
X = 27	Y = 10	Pressure = 826
X = 27	Y = 10	Pressure = 802
--------------------------------------------------------truncated
X = -16	Y = 147	Pressure = 109
X = -16	Y = 147	Pressure = 110
X = -16	Y = 147	Pressure = 109
X = -17	Y = 147	Pressure = 110
X = -17	Y = 147	Pressure = 112
X = -17	Y = 146	Pressure = 113
X = -17	Y = 145	Pressure = 115
X = -17	Y = 144	Pressure = 117

x is worse

X = -19	Y = -11	Pressure = 750
X = -19	Y = -11	Pressure = 743
X = -19	Y = -11	Pressure = 736
X = -17	Y = -8	Pressure = 321
X = -17	Y = -7	Pressure = 273
---------------------------------------------------------truncated
X = 4	Y = 124	Pressure = 179
X = 4	Y = 125	Pressure = 182
X = 4	Y = 124	Pressure = 188
X = 3	Y = 121	Pressure = 197
X = 3	Y = 121	Pressure = 199
X = 3	Y = 119	Pressure = 205

-T

code that was used for previous post

#include <stdint.h>
#include "TouchScreen.h"

// These are the pins for the shield!
#define YP A2  // must be an analog pin, use "An" notation!
#define XM A1  // must be an analog pin, use "An" notation!
#define YM 6   // can be a digital pin
#define XP 7   // can be a digital pin

int x;
int y;
#define MINPRESSURE 10
#define MAXPRESSURE 1000

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 150);

void setup(void) {
  Serial.begin(9600);
}

void loop(void) {
  // a point object holds x y and z coordinates
  TSPoint p = ts.getPoint();

    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
    pinMode(XP, OUTPUT);
    pinMode(YM, OUTPUT);
  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    x=map(p.x,946,94,0,239);
    y=map(p.y,981,146,0,319);
     Serial.print("X = "); Serial.print(x);
     Serial.print("\tY = "); Serial.print(y);
     Serial.print("\tPressure = "); Serial.println(p.z);
  }
}

Are you related to someone called Bob from Orlando ?
He writes continuous text in a single sentence too.

Your tp.x values seem unusual. i.e. 777 -> 996
Your tp.y values are also unusual. i.e. 694 -> 997

Most screens would give 150 -> 950.
In fact I just tried one that is on my desk with the touchscreendemo sketch from the TouchScreen Library examples.

My range is 915 -> 152 (left to right)
And 1006 -> 160 (top to bottom).

Personally, I think that the TouchScreen library is just badly written. But this is a third party library that is nothing to do with me.

i took the plastic cover off the screen (which i never do) but honestly i dont know what im looking at

I have no idea what this means. If you have dismantled the Glass Touch Panel from the TFT Panel, it will be irretrievably damaged. (the two panels are glued together). Even unpeeling the bare screen module from the pcb is likely to damage something. (the double-sided sticky pads are quite strong)

David.

tbillion:
code that was used for previous post

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {

x=map(p.x,946,94,0,239);
    y=map(p.y,981,146,0,319);
    Serial.print("X = "); Serial.print(x);
    Serial.print("\tY = "); Serial.print(y);
    Serial.print("\tPressure = "); Serial.println(p.z);

That is crazy. The purpose of the touchscreendemo sketch is to give you the RAW values.

If you want to investigate how the map() function works, you either put some hard values into a sketch or you get out your pencil and paper and calculate by hand.

David.

bob from orlando? not that i know of, is he rich, retired, and has good working code for this junk? if so i will work on becoming related, haha.

the plastic piece i took off is the protective screen cover that ships with the device. i never take them off normally i have ST7735 screens that still have them on them after 6 or 7 years.

"Your tp.x values seem unusual. i.e. 777 -> 996
Your tp.y values are also unusual. i.e. 694 -> 997

Most screens would give 150 -> 950."

i just checked it again and stil 776 to 1023 on x and about 650 to 1023 on y ..

i tiik the shield off and ohmed it out. I have no clue how much this makes a difference on shared pins, but, XM and XP come out to be 917 ohms, YM and YP 393 ohms, given this sort of variance wouldnt i have to come up with my own touch panel whatever(library, code, function)? becasue touchscreen.h only has one value that you input when i average the two and put 655 in the touchscreen declaration i get 400 to 900 on the y and 600 to 1000 on x, so maybe this is where i am getting the hang up ?

if touchscreen.h sucks so bad would would be the best touch library that is not ridiculously complicated? ur touch or u touch or is there a better alternative?

this is just flat stupid. there is no reasonable explanation for this;

When i use the utouch calibration sketch from mcufriend kbv, when it is done my results in serial terminal are this

UTouch_Calibr_kbv

cx=155 cy=158
cx=159 cy=467
cx=153 cy=873
cx=463 cy=250
cx=518 cy=706
cx=827 cy=263
cx=879 cy=542
cx=889 cy=839

but whenever i use the standard touchscreen shield demo i can never see a value below bleeping 700!!! why is this so **** complicated?

David,

its something you did in mcufriend kbv that makes it work. because if i use it in my code it gives the same values as when i use the adafruit demo, but if i use the utouch calibrate in mcufriend kbv it works as directed. advice?

i have no clue what i did but i got it to actually work... poked alot of things. :slight_smile: still cant get the touchshield example to work right no matter what though... idk/c

-T