how to wait for input on touch panel, MIO283QT

hi,
I bought a display MIO283QT with ARM controller on a SD-card shield from Watterott.
The example sketches for display, Dispal_SPI.ino, and touch panel, Touch_SPI.ino are working.
Both sketches are using base commands like CMD_LCD_CLEAR, CMD_LCD_DRAWLINE and so on.

Now I want to combine both. I added code to the function “wait_for_input()” to wait for input from the touch panel TP (see code later).
I tried it with CMD_TP_WAITPRESS but the code does not wait for touching the TP.
I also tried it like in the example code with waiting for the pressing level z>0. Now the code is waiting but touching/pressing the TP does not finish waiting, i.e. the code is waiting for ever.

Original code:

void wait_for_input(void)
{
  Serial.println("Wait for input!");
  while(Serial.available() == 0);
  while(Serial.available() != 0){ Serial.read(); };
}

My version should wait for input on serial monitor or TP:

void wait_for_input(byte ser_tp)
{
  uint16_t x, y, z=0;
  
  if (ser_tp ==2) {
    Serial.println("Wait for input on TP");
    digitalWrite(cs_pin, LOW);
//    SPI.transfer(CMD_TP_CALIBRATE);
//    delay(10);
//    SPI.transfer(0xFF); //read response
//    delay(10);
//    z=0;
    while (z == 0) {  // here the code should wait for pressing the TP
      SPI.transfer(CMD_TP_POS);
      delay(1);
      x  = SPI.transfer(0xFF)<<8;
      x |= SPI.transfer(0xFF)<<0;
      y  = SPI.transfer(0xFF)<<8;
      y |= SPI.transfer(0xFF)<<0;
      z  = SPI.transfer(0xFF)<<8;
      z |= SPI.transfer(0xFF)<<0; 
      delay(2);    
    }
    digitalWrite(cs_pin, HIGH);
    Serial.print("TP response: ");
    Serial.print(x); Serial.print(" ");
    Serial.println(y);
  }
  else {
    Serial.println("Wait for input on serial monitor");
    while(Serial.available() == 0);
    while(Serial.available() != 0){ Serial.read(); };
  }
  
}

The call wait_for_input(2) is used after all initializations of the display.

Ha somebody experience using this type of display?

Hi,

Do you have activated the touch panel?

//enable touchpanel
digitalWrite(cs_pin, LOW);
SPI.transfer(CMD_CTRL);
SPI.transfer(CMD_CTRL_FEATURES);
SPI.transfer(FEATURE_TP);
digitalWrite(cs_pin, HIGH);


uint16_t x=0, y=0, z=0;
while (z == 0)
{
  //read data
  digitalWrite(cs_pin, LOW);
  SPI.transfer(CMD_TP_POS);
  delay(1);
  x  = SPI.transfer(0xFF)<<8;
  x |= SPI.transfer(0xFF)<<0;
  y  = SPI.transfer(0xFF)<<8;
  y |= SPI.transfer(0xFF)<<0;
  z  = SPI.transfer(0xFF)<<8;
  z |= SPI.transfer(0xFF)<<0;
  digitalWrite(cs_pin, HIGH);

  delay(20);
}

You can also use our Arduino Library: DisplayI2C or DisplaySPI + GraphicsLib.

Here is an example for the lib:

Regards
Andreas