ILI9341 display with Adafruit_STMPE610_RK touch library

Apologies in advance if this post is a bit long-winded…

Goal: Use a 2.8" 240X320 ILI9341 display plus touch with photon.
Status: Display is working perfectly
Issue: Unable to get touch to work
Libraries: Adafruit/-ILI9341 and Adafruit_mfGFX (display); Adafruit_STMPE610_RK (touch)
Pinout from ILI9341 (see attached photo):
a. display: CS->A2; RESET->D5; D/C->A4; SD (MOSI)->A5; SCK->A3; SDO(MISO)->not conneccted
b. touch: T_CLK->A3; T_CS->D6; T_DIN->A5; T_OUT->A4; IRQ->not connected

I am stuck at this point, and would really appreciate some help.

relevant code for display:

//my code
Adafruit_ILI9341 tft = Adafruit_ILI9341(A2, D4, D5);  

Note that the (A2, D4, D5) amps to pins for CS, DC, RST respectively; SPI is standard

This works fine for the display.

The problem arise with touch. The STMP is not recognized.

Code (sorry for the verbose nature; I have included all comments from the test code):

//my code
/*************************************************** 
  This is an example for the Adafruit STMPE610 Resistive
  touch screen controller breakout
  ----> http://www.adafruit.com/products/1571
 
  Check out the links above for our tutorials and wiring diagrams
  These breakouts use SPI or I2C to communicate

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/

#include <SPI.h>
#include <Wire.h>

#include <Adafruit_STMPE610_RK.h>

// Pick one of three wiring options below!

// Option #1 - uses I2C, connect to hardware I2C port only!
// SCL to I2C clock (#A5 on Uno) and SDA to I2C data (#A4 on Uno)
// tie MODE to GND and POWER CYCLE (there is no reset pin)
//Adafruit_STMPE610 touch = Adafruit_STMPE610();

// Option #2 - use hardware SPI, connect to hardware SPI port only!
// SDI to MOSI, SDO to MISO, and SCL to SPI CLOCK
// on Arduino Uno, that's 11, 12 and 13 respectively
// Then pick a CS pin, any pin is OK but we suggest #10 on an Uno
// tie MODE to 3.3V and POWER CYCLE the STMPE610 (there is no reset pin)
const int STMPE_CS = D6;
const int STMPE_MOSI = A5;
const int STMPE_MISO = A4;
const int STMPE_CLK = A3;
Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS, STMPE_MOSI, STMPE_MISO, STMPE_CLK);

// Option #3 - use software SPI, connect to *any* 4 I/O pins!
// define the following pins to whatever 4 you want and wire up!
// Tie MODE to 3.3V and POWER CYCLE the STMPE610 (there is no reset pin)
// Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS, STMPE_SDI, STMPE_SDO, STMPE_SCK);

/******************/

void test() {  
// Pick one of three wiring options below!

// Option #1 - uses I2C, connect to hardware I2C port only!
// SCL to I2C clock (#A5 on Uno) and SDA to I2C data (#A4 on Uno)
// tie MODE to GND and POWER CYCLE (there is no reset pin)
//Adafruit_STMPE610 touch = Adafruit_STMPE610();

// Option #2 - use hardware SPI, connect to hardware SPI port only!
// SDI to MOSI, SDO to MISO, and SCL to SPI CLOCK
// on Arduino Uno, that's 11, 12 and 13 respectively
// Then pick a CS pin, any pin is OK but we suggest #10 on an Uno
// tie MODE to 3.3V and POWER CYCLE the STMPE610 (there is no reset pin)
const int STMPE_CS = D6;
const int STMPE_MOSI = A5;
const int STMPE_MISO = A4;
const int STMPE_CLK = A3;
Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS, STMPE_MOSI, STMPE_MISO, STMPE_CLK);

// Option #3 - use software SPI, connect to *any* 4 I/O pins!
// define the following pins to whatever 4 you want and wire up!
// Tie MODE to 3.3V and POWER CYCLE the STMPE610 (there is no reset pin)

//I AM USING THIS OPTION
// Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS, STMPE_SDI, STMPE_SDO, STMPE_SCK);

/******************/


  Serial.println("Adafruit STMPE610 example");
  Serial.flush();

  // if using hardware SPI on an Uno #10 must be an output, remove line
  // if using software SPI or I2C
  //pinMode(10, OUTPUT);

  // If using I2C you can select the I2C address (there are two options) by calling
  // touch.begin(0x41), the default, or touch.begin(0x44) if A0 is tied to 3.3V
  // If no address is passed, 0x41 is used
  if (! touch.begin()) {
    Serial.println("STMPE not found!");     //This is where my code fails; STMPE is not found
    //while(1);
  }
  Serial.println("Waiting for touch sense");

  uint16_t x, y;
  uint8_t z;
  unsigned long end = millis();
  unsigned long begin = millis();
  
  while (end - begin < 10000) {   //this just provides some time to play with the touch and ensure it's working
    if (touch.touched()) {
      // read x & y & z;
      while (! touch.bufferEmpty()) {
        Serial.print(touch.bufferSize());
        touch.readData(&x, &y, &z);
        Serial.print("->("); 
        Serial.print(x); Serial.print(", "); 
        Serial.print(y); Serial.print(", "); 
        Serial.print(z);
        Serial.println(")");
      }
    touch.writeRegister8(STMPE_INT_STA, 0xFF); // reset all ints
    }
    delay(10);
    end = millis();
  }
}

Thanks so much - David

Sorry - here is the photo of the board with pins labelled
David

This configuration is for software SPI. I never tested this and I’m not sure it works.

Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS, STMPE_MOSI, STMPE_MISO, STMPE_CLK);

Try using hardware SPI instead. The pins should be the same, but you only pass in CS

Adafruit_STMPE610 touch(STMPE_CS);

Rick,

Thanks so much; actually, I tried that first, before coding in the software pins. No luck.

Thanks - David

Wait…spoke too soon. I am seeing a response: it is all (0,0,0) for the location.

But it’s a start. Thanks!

David

Well…the screen does recognize touch.
The output makes little sense.
In the code above, the x, y and z coordinates are printed out.
I changes the code slightly to also print out the coordinates from a call to:
touch.getPoint(), which itself uses touch.readData(&x, &y, &z)
The results are (for example):

0->(0, 0, 0)
point->(256, 0, 0)
0->(0, 0, 0)
point->(0, 0, 0)
0->(0, 0, 0)
point->(896, 0, 0)
0->(0, 0, 0)
point->(0, 0, 0)
0->(0, 0, 0)
point->(2048, 0, 0)
0->(0, 0, 0)
point->(0, 0, 0)
0->(0, 0, 0)
point->(0, 0, 0)
0->(0, 0, 0)
point->(0, 0, 0)
0->(0, 0, 0)
point->(2048, 0, 0)

…note that all the x coordinates from point are divisible by 128.
So it looks very much like the library is reading/shifting the registers wrong.

Any suggestions?

Thanks - David

Why are you instantiating touch twice - once globally and once locally inside test()?

1 Like

FONF

Removed the global declaration; no change in output

thanks - D

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.