Mcufriend.com TFT Touchscreen Problems

Hello,
I purchased a 2.8" Touchscreen from Mcufriend.com on ebay sent from china. I know it isn't the best board but it was just to learn about the process. After some adjustments to the library I have been able to get the LCD to work and display items off the SD card. The touchscreen however is giving me problems. Currently I am able to read an inaccurate X value, no Y value because its stuck at 1023, and a semi accurate Z value. Everything seems to be pinned correctly to my knowledge but I'm hoping someone can shed some light on this.
Here is what I'm using:
Arduino UNO Rv3
Mcufriend.com 2.8" Touchscreen (looks like this http://www.ebay.com/itm/2-8-Inch-TFT-LCD-Display-Touch-Screen-Module-with-SD-Slot-For-Arduino-UNO-FE-/121440152660?pt=LH_DefaultDomain_0&hash=item1c4665ac54)

Any insight on this would be great.

Thank you!

What library are you using?

Here is the library that the seller sent me. I had to adjust the TFT library a bit to get it to work but included is also a Touchscreen library from him.

Working TFT Lib.zip (262 KB)

I can't do any tests to confirm this, but the getPoint() function in the TouchScreen.cpp file doesn't look correct.

Point TouchScreen::getPoint(void) {
int x, y, z;
int samples[NUMSAMPLES];
uint8_t i, valid;

uint8_t xp_port = digitalPinToPort(_xp);
uint8_t yp_port = digitalPinToPort(_yp);
uint8_t xm_port = digitalPinToPort(_xm);
uint8_t ym_port = digitalPinToPort(_ym);

uint8_t xp_pin = digitalPinToBitMask(_xp);
uint8_t yp_pin = digitalPinToBitMask(_yp);
uint8_t xm_pin = digitalPinToBitMask(_xm);
uint8_t ym_pin = digitalPinToBitMask(_ym);

valid = 1;

pinMode(_yp, INPUT);
pinMode(_ym, INPUT);

*portOutputRegister(yp_port) &= ~yp_pin; // this should not be here, this sets the pin you want to read (A2) to low
*portOutputRegister(ym_port) &= ~ym_pin;
//digitalWrite(_yp, LOW);
//digitalWrite(_ym, LOW);

pinMode(_xp, OUTPUT);
pinMode(_xm, OUTPUT);
//digitalWrite(_xp, HIGH);
//digitalWrite(_xm, LOW);
*portOutputRegister(xp_port) |= xp_pin;
*portOutputRegister(xm_port) &= ~xm_pin;

for (i=0; i<NUMSAMPLES; i++) {
samples = analogRead(_yp);[/b] <- Then tries to read the low pin
* }*
#if NUMSAMPLES > 2
* insert_sort(samples, NUMSAMPLES);
__
#endif*__
#if NUMSAMPLES == 2
* if (samples[0] != samples[1]) { valid = 0; }*
#endif
_ x = (1023-samples[NUMSAMPLES/2]); // 1023 - 0 is going to return 1023_
* pinMode(_xp, INPUT);
pinMode(_xm, INPUT);
portOutputRegister(xp_port) &= ~xp_pin;
//digitalWrite(_xp, LOW);

* pinMode(yp, OUTPUT);
portOutputRegister(yp_port) |= yp_pin;
//digitalWrite(_yp, HIGH);

* pinMode(ym, OUTPUT);
portOutputRegister(ym_port) &= ~ym_pin; <- this is needed to properly read _xm, without this, _xm will always be high
__
for (i=0; i<NUMSAMPLES; i++) {

samples = analogRead(_xm);[/b]
* }*
#if NUMSAMPLES > 2
* insert_sort(samples, NUMSAMPLES);
__#endif*

#if NUMSAMPLES == 2
* if (samples[0] != samples[1]) { valid = 0; }
#endif*

_ y = (1023-samples[NUMSAMPLES/2]); <- 1023 - "aprox" 1023 = 0 or 1_
* // Set X+ to ground*__

* pinMode(_xp, OUTPUT);
portOutputRegister(xp_port) &= ~xp_pin;
//digitalWrite(_xp, LOW);

* // Set Y- to VCC*
portOutputRegister(ym_port) |= ym_pin;
//digitalWrite(_ym, HIGH);*

* // Hi-Z X- and Y+*
portOutputRegister(yp_port) &= ~yp_pin;
//digitalWrite(_yp, LOW);
pinMode(_yp, INPUT);*

* int z1 = analogRead(_xm);
int z2 = analogRead(yp);
if (rxplate != 0) {
__ // now read the x*

* float rtouch;
rtouch = z2;
rtouch /= z1;
rtouch -= 1;*__

rtouch *= x;

rtouch = _rxplate;
__ rtouch /= 1024;*__

* z = rtouch;*
* } else {*
* z = (1023-(z2-z1));*
* }*
* if (! valid) {*
* z = 0;*
* }*
* return Point(x, y, z);*
}[/quote]
Make those changes and it should work like normal.

Im sorry Im a little new with library altercations. Would you be able to upload that as a file that I can import into my library please? Additionally will I need to change my coding at all?

Thank you so much

Try this. Change just the TouchScreen.cpp file and DO NOT DELETE THE ONE YOU HAVE NOW!!! Simply rename your current TouchScreen.cpp file to TouchScreen**_old**.cpp (I don't think it will give any errors) and copy & paste in this new one.

TouchScreen.cpp (5.31 KB)

Ok I'm going to try it right now and ill post back in just a moment
Thank you

Ok so I tried that and here has been no change in the results. This is what the serial out put is giving me

X1002 Y = 1023 Pressure = 1614
X = 1001 Y = 1023 Pressure = 977
X = 1000 Y = 1023 Pressure = 1757
X = 1023 Y = 1023 Pressure = 1648
X = 1006 Y = 1023 Pressure = 1620
X = 1005 Y = 1023 Pressure = 981
X = 1002 Y = 1023 Pressure = 1076
X = 1000 Y = 1023 Pressure = 1757
X = 1001 Y = 1023 Pressure = 977
X = 1002 Y = 1023 Pressure = 1761
X = 1002 Y = 1023 Pressure = 978
X = 1002 Y = 1023 Pressure = 978
X = 1001 Y = 1023 Pressure = 1759

This is without me touching the screen at all.

I did say I couldn't test it, sorry.

Just delete that file and change the old file back to the way it was.

Perhaps someone else had that issue before and found a solution. Do a search in the forum.

Hm Ill look around and hopefully someone else has an answer :slight_smile: Thank you so much for your time though in checking it out. I appreciate it!

Question, what did it return if you touched the screen in the corners? Was it correct?

When I press on the screen the x value does not display any correlating change and the z value shows a change in pressure. The Y value does not change at all

Hi speedscater1,

Is your 2.8TFT LCD working with the code you have posted?

I also bought the LCD with the same marking.

So far I could not make it work.

I did try the one you posted here but did not work.
In your post you mentioned that you did some modification then worked.

Can you pls post the final working one with all the files.

Thanks.