HARDWARE
3.5 inch tft screen sheild for arduino uno/mega
specs of screen
|LCD Type:|TFT|
|LCD Interface:|SPI|
|LCD Controller:|ILI9486|
|Touch Screen Type:|Resistive|
|Touch Screen Controller:|XPT2046|
|Colors:|RGB, 65K colors|
|Resolution:|480x320 (Pixel)|
|Aspect Ratio:|8:5|
|I/O Voltage:|3.3V/5V|
[code]
10:19:17.512 -> TFT_eSPI ver = 2.5.23
10:19:17.512 -> Processor = ESP32
10:19:17.512 -> Frequency = 240MHz
10:19:17.512 -> Transactions = Yes
10:19:17.512 -> Interface = Parallel
10:19:17.512 -> Display driver = 9486
10:19:17.512 -> Display width = 320
10:19:17.512 -> Display height = 480
10:19:17.512 ->
10:19:17.512 -> TFT_CS = GPIO 33
10:19:17.512 -> TFT_DC = GPIO 15
10:19:17.512 -> TFT_RST = GPIO 32
10:19:17.512 -> TFT_WR = GPIO 4
10:19:17.512 -> TFT_RD = GPIO 2
10:19:17.512 ->
10:19:17.512 -> TFT_D0 = GPIO 12
10:19:17.512 -> TFT_D1 = GPIO 13
10:19:17.512 -> TFT_D2 = GPIO 26
10:19:17.512 -> TFT_D3 = GPIO 25
10:19:17.512 -> TFT_D4 = GPIO 18
10:19:17.557 -> TFT_D5 = GPIO 19
10:19:17.557 -> TFT_D6 = GPIO 27
10:19:17.557 -> TFT_D7 = GPIO 14
10:19:17.557 ->
10:19:17.557 -> Font GLCD loaded
10:19:17.557 -> Font 2 loaded
10:19:17.557 -> Font 4 loaded
10:19:17.557 -> Font 6 loaded
10:19:17.557 -> Font 7 loaded
10:19:17.557 -> Font 8 loaded
10:19:17.557 -> Smooth font enabled
10:19:17.557 ->
10:19:17.557 -> [/code]

i finally got the pressure working but after that reading the pressure and x and y coordinates the screen goes all white i bet that its due to the touchscreen library altering the pins common, but according to bodmers library there was a guide on how to work around that using GPI 37 39 to read the analog inputs i finally managed to get input after 1-2 weeks of trying but now the screen is going white, using tft.init() and tft.begin() fixes it but it reloads the whole screen and there by taking 1-2 seconds this is not possible as using this the screen will be flickering every second that too 1 second black every alternate second. if anyone one could help me where i am wrong..
boolean Touch_getXY(int *x, int *y, boolean showTouch,TouchScreen ts ) {
//TSPoint p = ts.getPoint();
//*x=p.x;
//*y=p.y;
int xmstate = digitalRead(XM);
int ymstate = digitalRead(YM);
int xpstate = digitalRead(XP);
int ypstate = digitalRead(YP);
*x = ts.readTouchX();
*y = ts.readTouchY();
int pressure = ts.pressure();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
pinMode(XP, OUTPUT); //restore shared pins
pinMode(YM, OUTPUT);
digitalWrite(YP, ypstate); //because TFT control pins
digitalWrite(XM, xmstate);
digitalWrite(XP, xpstate); //because TFT control pins
digitalWrite(YM, ymstate);
Serial.print("xmstate: ");
Serial.println(xmstate);
Serial.print("ymstate: ");
Serial.println(ymstate);
Serial.print("xpstate: ");
Serial.println(xpstate);
Serial.print("ypstate: ");
Serial.println(ypstate);
//tft.init();
//tft.begin();
makerec(200,470,220,13,0x0000,0x0000,500,0,".",1);
tft.setTextFont(1);
tft.setTextSize(1);
tft.setTextColor(titlecol);
tft.setCursor(230,470);
tft.print("X:");
tft.setCursor(230+20,470);
tft.print(*x);
tft.setCursor(230+50,470);
tft.print("Y:");tft.println(*y);
Serial.print("\tPressure = "); Serial.println(pressure);
bool pressed = (pressure > MINPRESSURE && pressure < MAXPRESSURE);
//pinMode(XM, OUTPUT);
//pinMode(YP, OUTPUT);
//digitalWrite(XP, HIGH); //because TFT control pins
//digitalWrite(YM, HIGH);
//Serial.print("X = "); Serial.print(p.x+180);
//Serial.print("\tY = "); Serial.print(p.y);
//Serial.print("\tPressure = "); Serial.println(p.z);
//Serial.print(p.z);
//if (pressed == true || (p.x<3950 & p.y <3950)){Serial.println("LMAO PRESSED AAA");}
if (pressed == true){Serial.println("LMAO PRESSED AAA");}
return pressed;
}
const int coords[] = {3900,600,3750, 400};
const int XP = 27, XM = 15, YP = 4, YM = 14; // default ESP32 Uno touchscreen pins 33 32
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
where as i am using adafruit touchscreen library to read touch
this is code from the library of how its handling the touch x and y and pressure
int TouchScreen::readTouchX(void) {
pinMode(_yp, INPUT);
pinMode(_ym, INPUT);
digitalWrite(_yp, LOW);
digitalWrite(_ym, LOW);
pinMode(_xp, OUTPUT);
digitalWrite(_xp, HIGH);
pinMode(_xm, OUTPUT);
digitalWrite(_xm, LOW);
#if defined (ESP32_WIFI_TOUCH) && defined (ESP32)
return (ADC_MAX-analogRead(aYP));
#else
return (ADC_MAX-analogRead(_yp));
#endif
}
int TouchScreen::readTouchY(void) {
pinMode(_xp, INPUT);
pinMode(_xm, INPUT);
digitalWrite(_xp, LOW);
digitalWrite(_xm, LOW);
pinMode(_yp, OUTPUT);
digitalWrite(_yp, HIGH);
pinMode(_ym, OUTPUT);
digitalWrite(_ym, LOW);
#if defined (ESP32_WIFI_TOUCH) && defined (ESP32)
return (ADC_MAX-analogRead(aXM));
#else
return (ADC_MAX-analogRead(_xm));
#endif
}
uint16_t TouchScreen::pressure(void) {
// Set X+ to ground
pinMode(_xp, OUTPUT);
digitalWrite(_xp, LOW);
// Set Y- to VCC
pinMode(_ym, OUTPUT);
digitalWrite(_ym, HIGH);
// Hi-Z X- and Y+
digitalWrite(_xm, LOW);
pinMode(_xm, INPUT);
digitalWrite(_yp, LOW);
pinMode(_yp, INPUT);
#if defined (ESP32_WIFI_TOUCH) && defined (ESP32)
Serial.println("FROM aXM aYP PRESSUREEE");
int z1 = analogRead(aXM);
int z2 = analogRead(aYP);
#else
Serial.println("FROM _XM _YP PRESSUREEE");
int z1 = analogRead(_xm);
int z2 = analogRead(_yp);
#endif
if (_rxplate != 0) {
// now read the x
float rtouch;
rtouch = z2;
rtouch /= z1;
rtouch -= 1;
rtouch *= readTouchX();
rtouch *= _rxplate;
rtouch /= ADC_MAX+1;
return rtouch;
} else {
return (ADC_MAX-(z2-z1));
}
}