Trouble with resistive touch screen. (RA8875 tft 5 inches)

Hi, there I’m reletivly new to using arduino. Only experience I had was with MSP430s so I figure that was enough to get into it.

Anyway so I went and bought this touch screen from buydisplay, that’s configured to 4-wire SPI and has a resistive touchscreen attached, and I’m now playing with the demos they have using the Arduino Mega 2560. It works wonderfully…until I hit a snag with the touchscreen calibration test. Ijust cannot get it to respond to touch. According to the code it requires some interrupt pin? (it says RA8875_INT so I assume it meant an interrupt pin) So I looked up the Mega’s interrupt pin numbers and tried them all but no reaction. So I’m at a lost as to how to continue. What am I doing wrong? Do I need to physically hook up the touchscreen pins to the interrupt pins or something?

This is the code I’m using by the way

/* Touch screen library calibration:
 this will help you to calibrate your touch screen by modify
 4 parameters inside RA8875/_utility/RA8875Calibration.h file:
 // ---------------> http://www.buydisplay.com
 TOUCSRCAL_XLOW	//min value of x you can get
 TOUCSRCAL_XHIGH	//max value of x you can get
 TOUCSRCAL_YLOW	//min value of y you can get
 TOUCSRCAL_YHIGH	//max value of y you can get
 
 Normally those parameters are set as 0.
 
 Now run this program and open Serial Monitor, follow indications!
 Tested and worked with:
 Teensy3,Teensy3.1,Arduino UNO,Arduino YUN,Arduino Leonardo,Stellaris
 Works with Arduino 1.0.6 IDE, Arduino 1.5.8 IDE, Energia 0013 IDE
 */

#include <SPI.h>
#include <RA8875.h>

//Arduino DUE,Arduino mega2560
#define RA8875_INT 18 
#define RA8875_CS 53 

#define RA8875_RESET 24

//#if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva

//RA8875 tft = RA8875(3);//select SPI module 3
/*
for module 3 (stellaris)
SCLK:  PD_0
MOSI:  PD_3
MISO:  PD_2
SS:    PD_1
*/
//#else

RA8875 tft = RA8875(RA8875_CS,RA8875_RESET);//Teensy3/arduino's

//#endif

uint8_t samples = 20;
uint16_t tempData[20][2];
volatile int count = 0;
volatile uint8_t scount = 0;
uint16_t tx,ty;
uint16_t valx,valy;

uint16_t _XLOW_VAR;
uint16_t _YLOW_VAR;
uint16_t _XHIGH_VAR;
uint16_t _YHIGH_VAR;
bool proceed = true;


void setup() 
{
  Serial.begin(9600);
  //while (!Serial) {;}
 tft.begin(RA8875_480x272);
  tft.touchBegin(RA8875_INT);//enable touch support for RA8875


  tft.changeMode(TEXT);

  if (tft.touchCalibrated()){
    Serial.println("You have old calibration data present!\n");
    Serial.println("\nPlease open RA8875/_utility/RA8875calibration.h and put zero on the following:\n");
    Serial.println("#define TOUCSRCAL_XLOW	0");
    Serial.println("#define TOUCSRCAL_YLOW	0");
    Serial.println("#define TOUCSRCAL_XHIGH	0");
    Serial.println("#define TOUCSRCAL_YHIGH	0\n");
    Serial.println("Then save and try to run this again!");
    tft.setCursor(0,0);
    tft.setTextColor(RA8875_RED);
    tft.println("---> You have old calibration data present! <---");
    tft.setTextColor(RA8875_WHITE);
    tft.println("Please open RA8875/_utility/RA8875calibration.h");
    tft.println("and put zero on the following:");
    tft.println(" ");
    tft.println("   #define TOUCSRCAL_XLOW   0");
    tft.println("   #define TOUCSRCAL_YLOW   0");
    tft.println("   #define TOUCSRCAL_XHIGH  0");
    tft.println("   #define TOUCSRCAL_YHIGH  0");
    tft.println(" ");
    tft.print("Then save and try to run this again!");
    proceed = false;
  } 
  else {
    Serial.println("Start calibration, please follow indications...\n");
    Serial.println("\nPlease press FIRMLY the TOP/LEFT angle of your screen now!\n");
    tft.setCursor(5,tft.height()/2);
    tft.setTextColor(RA8875_WHITE);
    tft.print("Please press the TOP/LEFT angle of your screen now!    www.buydisplay.com");
  }
  tft.changeMode(GRAPHIC);
  if (proceed) tft.fillCircle(5,5,5,RA8875_RED);
}

void loop() 
{

  if(proceed && tft.touchDetect())
  {

    Serial.print("."); 
    if (count > samples-1){
      count = 0;
      tft.touchEnable(false);
      valx = 0; 
      valy = 0;
      for (uint8_t i=0;i<samples;i++){
        valx = valx+tempData[i][0];
        valy = valy+tempData[i][1];
      }
      valx = valx/samples;
      valy = valy/samples;
      if (scount >= 3){
        scount = 255;
        tft.touchEnable(false);
      } 
      else {
        scount++;
      }
      Serial.println();
      switch(scount){
      case 1:// TOP/LEFT
        tft.fillScreen(RA8875_BLACK);
        tft.changeMode(TEXT);
        tft.setCursor(20,tft.height()/2);
        tft.setTextColor(RA8875_WHITE);
        tft.print("Top/Left done. Please do not touch screen...");
        tft.setTextColor(RA8875_RED);
        tft.setFontScale(1);
        tft.setCursor(20,tft.height()/2+40);
        tft.print("Please do not touch screen!");
        tft.setFontScale(0);
        tft.changeMode(GRAPHIC);
        Serial.print("Top/Left done...");
        Serial.print("Please do not touch screen...");
        _XLOW_VAR = valx;
        _YLOW_VAR = valy;
        delay(3000);
        tft.fillScreen(RA8875_BLACK);
        tft.fillCircle(tft.width()-5,tft.height()-5,5,RA8875_RED);
        tft.changeMode(TEXT);
        tft.setCursor(20,tft.height()/2);
        tft.setTextColor(RA8875_WHITE);
        tft.print("ok, Now Touch Bottom/Right angle!");
        tft.changeMode(GRAPHIC);
        Serial.println("\nok, Now Touch Bottom/Right angle!");
        tft.touchEnable(true);
        count = -1;//it prevents a spurious read after touch enable
        break;
      case 2:// BOTTOM/RIGHT
        tft.fillScreen(RA8875_BLACK);
        tft.changeMode(TEXT);
        tft.setCursor(0,0);
        tft.setTextColor(RA8875_WHITE);
        tft.print("Calibration done...watch results!");


        Serial.println("\nCalibration done...watch results");
        _XHIGH_VAR = valx;
        _YHIGH_VAR = valy;
        tft.touchEnable(false);
        tft.setCursor(0,20);
        tft.println("Now open file RA8875/_utility/RA8875Calibration.h");
        Serial.println("\nNow open file RA8875/_utility/RA8875Calibration.h\n");
        Serial.println("Change the following:\n");
        tft.println("Change the following:");
        tft.println(" ");
        tft.setTextColor(RA8875_GREEN);
        tft.print("#define TOUCSRCAL_XLOW   ");
        tft.setTextColor(RA8875_YELLOW);
        tft.println(_XLOW_VAR,DEC);
        tft.setTextColor(RA8875_GREEN);
        tft.print("#define TOUCSRCAL_YLOW   ");
        tft.setTextColor(RA8875_YELLOW);
        tft.println(_YLOW_VAR,DEC);
        tft.setTextColor(RA8875_GREEN);
        tft.print("#define TOUCSRCAL_XHIGH  ");
        tft.setTextColor(RA8875_YELLOW);
        tft.println(_XHIGH_VAR,DEC);
        tft.setTextColor(RA8875_GREEN);
        tft.print("#define TOUCSRCAL_YHIGH  ");
        tft.setTextColor(RA8875_YELLOW);
        tft.println(_YHIGH_VAR,DEC);
        tft.setTextColor(RA8875_WHITE);
        tft.println(" ");
        tft.println("...then save file and you are calibrated!");
        tft.changeMode(GRAPHIC);
        Serial.println("#define TOUCSRCAL_XLOW	0");
        Serial.println("#define TOUCSRCAL_YLOW	0");
        Serial.println("#define TOUCSRCAL_XHIGH	0");
        Serial.println("#define TOUCSRCAL_YHIGH	0");
        Serial.println("\nInto:\n");
        Serial.print("#define TOUCSRCAL_XLOW	");
        Serial.println(_XLOW_VAR,DEC);
        Serial.print("#define TOUCSRCAL_YLOW	");
        Serial.println(_YLOW_VAR,DEC);
        Serial.print("#define TOUCSRCAL_XHIGH	");
        Serial.println(_XHIGH_VAR,DEC);
        Serial.print("#define TOUCSRCAL_YHIGH	");
        Serial.println(_YHIGH_VAR,DEC);
        Serial.println("\nSave and Have a nice day!");
        break;
      case 3:
        break;
      case 255:
        break;
      }
    } 
    else {
      delay(1);
      tft.touchReadRaw(&tx, &ty);//we using 10bit adc data here
      if (count >= 0){
        tempData[count][0] = tx;
        tempData[count][1] = ty;
      }
      count++;
    }
  }
}

Arduinewblet: So I looked up the Mega's interrupt pin numbers and tried them all but no reaction. So I'm at a lost as to how to continue. What am I doing wrong? Do I need to physically hook up the touchscreen pins to the interrupt pins or something?

Yes you need to physically change the pin from 23 to an interrupt pin to try them. I have not tried that screen to know if it will fix the problem but since you changed the define to 18 from 23 you also need to move the wire also. Let me know how it works out. it looks like an awesome screen for cheap. BTW How fast does the screen refresh data is it comparable to a utft screen or slower.

Ah, I see. I guess because the touchscreen in hooked up the the LCD's chip I didn't think about wiring the touchscreen panel to the arduino itself. :blush: :cold_sweat: Maybe I should have played with those "plug n play" LCD screens I've been seeing first. Alright I'll ask my friend to help solder some wires and give this touch screen when I get the chance and share the results.

As for the Library. Well I haven't tried using UTFT before so I wouldn't know but from what I'm seeing so far the RA8875 Library seems pretty fast in my opinion. Though from what I seen flooding the screen with pixels all at once slows it down a bit so I don't think it great with processing photos quickly it seems. Also I believe it's only limited to 4 wire SPI at the moment but the library is still a work in progress from what I read in the documentation. Here's a video demoing it.

https://www.youtube.com/embed/WbFOsxjFCL8

Edit: Yeah that certainly did the trick the touchscreen is working. Thank you so much. :)

I know this is almost a year late but it might help someone with this problem. I use the controller board from EastRising that uses the RA8875 chip. I don't make any changes to the hardware. Their documentation is awful. Once you get it functional, you have to tweak it in your code. For the Arduino 2560 and UNO here's what works for me:

#if defined(__AVR_ATmega2560__)
#define ARDUINO_BRD ("Mega-2560")
#define RA8875_INT 4 // only needed for touchscreen
#define RA8875_RESET    9
#define RA8875_CS   10 
#else // assume UNO
#define ARDUINO_BRD ("UNO")
#define RA8875_INT 3 // only needed for touchscreen
#define RA8875_RESET 9
#define RA8875_CS 10
#endif

Also I had to add this line before trying to read the touchscreen.

changeMode(GRAPHIC);

I also had to reverse x & y in my code, the #defines didn't work. For touch data, I just accumulated all the hits and then divided by the # of hits to get the center of the touch. For buttons needing immediate touch, I accumulated 20 hits then averaged.

Their calibration example is poorly documented and I ended up re-writing it from scratch once I figured out all the gotcha's.

Much of this might be fixed by now (my version was 0.50)

Even with all this complaining, I love these LCD packages. They are low cost and easy to use once you know the gotcha's. The RA8875 library is easy to use despite the lack of understandable comment.

I'm just rambling now so hopefully this helps somebody skip the week it cost me figuring all this out.

Good luck.