TeensyLC to Touchscreen ILI9341 connections

AJO4

Member
Hi everybody!

First got my hands on a Teensy in 2009, but been out of the loop in recent years. Just started a new project of recent envision and am really excited about it. Got 5 new Teensies(sp?) and 4 touchscreens (so cool!), but before I can start prototyping I want a working schematic, which should include connections to the eventually implemented touchscreens.

While the page:

https://www.pjrc.com/store/display_ili9341_touch.html

does indeed state:

"We recommend using this display only with Teensy LC, 3.x, and 4.x."

in the text below the table, the table does not have a column for LC (hint, nudge, wink: Paul :). So, if I interpret correctly from the existing table and TeensyLC front image, I thought I would assign the connections thusly:

Screen -> TeensyLC
------------------
3=CS -> 10(CS0)
5=D/C -> 15(A1)
6=SDI -> 0(MOSI1) | 11(MOSI0)
7=SCK -> 13(SCK0)
9=SDO -> 1(MISO1) | 12(MISO0)
10=T_CLK -> 13(SCK0)
11=T_CS -> 6(CS1)?, 10?(in use by 3), ?
12=T_DIN -> 0(MOSI1)
13=T_DO -> 1(MISO1)
14=T_IRQ -> 2?

VCC, GND, RESET, LED _seem_ straightforward.

Just to verify my intuition, do the T_ signals represent Touch input, while the others screen output? Guess I should check the docs first, but on my mind at the moment so I ask. Either way, presume CS & T_CS cannot share a pin. And can the software use both MxSx0 and MxSx1? Figured it could, just want to make sure.

Please go easy on me - been through hell since I last worked on these but hoping to still make a difference and contribution.

Skol,
John
 
Primary SPI is the SCK0, MOSI0 and MISO0 and a CS0 pin - bold or for same SPI0 those in gray can substitute. The SPI/SPI0 non-CS are the same pin numbers [ 10,11,12,13 ] as T_3.2 and other

SPI1 and the _xx_1 pins are a second SPI bus. So not to be mixed - either the SPI0 or SPI1 pin set. AFAIK either can work.

Yes, the display "T_signal" pins are those for Touch control, and indeed the CS and T_CS must be unique pins.
 
Thank you for your quick and kind reply, defragster.

So, are you saying that the touch and screen each need their own SPI bus?

Based on your feedback, I have updated my potential table to:

Screen -> TeensyLC
col 1 | col 2
-------------------------------------------
3=CS -> 10(CS0) | 6(CS1)
5=D/C -> 15(A1)
6=SDI -> 11(MOSI0) | 0(MOSI1)
7=SCK -> 13(SCK0)
9=SDO -> 12(MISO0) | 1(MISO1)
10=T_CLK -> 13(SCK0)
11=T_CS -> 6(CS1) | 10(CS0)
12=T_DIN -> 0(MOSI1) | 11(MOSI0)
13=T_DO -> 1(MISO1) | 12(MISO0)
14=T_IRQ -> 2?

Use column 1 ex-or column 2, but do not mix and match. Note that pins [0,1,11,12] have alternatives [21,5,7.8], the *bold* ones are shown here.

It seems that SCK and T_CLK can be shared, right?

And that D/C and T_IRQ can be any digital pin, yes?

Thanks again so much for your help!

Skol,
John
 
So, are you saying that the touch and screen each need their own SPI bus?
You can use the same SPI bus for both. As Defragster mentioned, only the CS needs to be unique between them so they don't conflict when they share the same bus.

It seems that SCK and T_CLK can be shared, right?
Correct

And that D/C and T_IRQ can be any digital pin, yes?
Correct. You don't necessarily need to use T_IRQ and can just read the touch status via the library ts.touched() as part of a loop.
 
Ken is right [Hi Ken!] - SPI bus, by design, can share the main pins - it is the noted CS that determines which device is active at any given time on those common pins.

This applies to the TFT and TOUCH elements of the display where each can be used in turn.

Paul did a write up on Better SPI Bus Design in 3 Steps use that explains more on the subject.

Not all displays and devices have the proper 'tri-state' hardware noted there, but the PJRC ILI9341 does allow both to operate in turn where CS is the control and the hardware properly 'tri-states' the shared lines when not selected.
 
Wow, it is hard to believe that it has been over a year since I first posted this thread. Finally getting some time to actually engineer these days, so back to my project. A big shout out to defragster and KenHahn for your help!

After hours of work (sure, who among us has not been there, right?) modifying OnOffButton from the examples and merging in EchoBoth, I was able to get screen output, yay! However, I am still not able to read touch input. Hell, I cannot even get ts.begin() to return true. I could work around that for this project, but I would really like to get touch working on the LC.

Is anyone still watching this thread? If so, I can post my entire code and photos upon request. If not, I hope you all do not mind if I start a new thread, just sayin'.
 
Wow indeed, another year ...

Not sure about use here on T_LC ... in any case not played with Touch on the ILI9341 for some time.

Seems there should be a fitting example with Touch - TouchPaint was it? that should work with T_LC.
 
Hay defragster!

In OnOffButton, it first defined an Adafruit_STMPE610 for touch, then an Adafruit_ILI9341 for display. Actually, it started with an ILI9341_t3 (the example section namesake), and since I was compiling for the LC got the message saying I needed "ILI9341," which I eventually figured was Adafruit_ILI9341, and then that I had to rearrange the parameter list. Then that I had to use a different Adafruit_STMPE610 constructor. But then I instantiate one called "ts."

I looked at what I think is the proper docs for that:
http://adafruit.github.io/Adafruit_...p_e610.html#a0953655da3c21c909c85cd9f1ff1f474

Do you, defragster, or anyone, know what it means by i2caddr, or STMPE_ADDR for that matter? I mean, I know that it is assigning a default value for the parameter and all, but what is an I2C address, exactly? Can I get more info from ts.begin() as to why it fails?
 
Indeed, the ILI9341_t3 code doesn't work for T_LC.

The Touchscreen on the PJRC ILI9341 units worked with here - as the Interrupt Response code was added was always: XPT2046_Touchscreen

C:\T_Drive\arduino-1.8.19\hardware\teensy\avr\libraries\XPT2046_Touchscreen\examples\ILI9341Test\ILI9341Test.ino

The other linked Touch uses analog pins - where the expected displays use SPI to the touch with the unique CS as noted above.
 
I am unclear as to which touch controller you have. If you are using an ILI9341 with the XPT2046 touch controller like you linked to on the PJRC website, here is a simple program that should work on the LC. You will need to install the XPT2046_Touch library using the IDE library manager if it is not already installed. The TOUCH_CS is on pin 8, though that can be moved if needed. There is no need to hook up the T_IRQ line.

Code:
[code]
/*
  Exercise the 240x360 ILI9341 TFT LCD with touch  
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "XPT2046_Touchscreen.h"

#define TFT_CS   10
#define TFT_DC   9
#define TOUCH_CS 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
XPT2046_Touchscreen ts(TOUCH_CS);

boolean istouched = false;
int screenColor = -1;
//===============================================================================
//  Initialization
//===============================================================================
void setup(void) {
  Serial.begin(9600);
  Serial.println("Touch Test");

  tft.begin();  // Init TFT LCD screen
  tft.setRotation(1);
  tft.fillScreen(ILI9341_BLUE);
  ts.begin();   // Init Touch
  ts.setRotation(3);
}
//===============================================================================
//  Main
//===============================================================================
void loop() {
  istouched = ts.touched();
  if (istouched) {    
    screenColor++;
    Serial.println(screenColor);
    if (screenColor == 0){
      tft.fillScreen(ILI9341_BLACK);
      }
    else if (screenColor == 1){
      tft.fillScreen(ILI9341_BLUE);
      }
      else if (screenColor == 2){
        tft.fillScreen(ILI9341_WHITE);
        screenColor = -1;
        }

   TS_Point p = ts.getPoint();    // Send touch info out to serial monitor
    Serial.print("Pressure = ");
    Serial.print(p.z);
    Serial.print(", x = ");
    Serial.print(p.x);
    Serial.print(", y = ");
    Serial.println(p.y);

   istouched = false;   // Reset touch flag
   }
}
[/CODE]
 
That #include <XPT2046_Touchscreen.h> library is the one Paul created for Teensy and is included with TeensyDuino install.
 
OK. Thanks for pointing me to XPT2046_, defragster. I tried modifying the test I was previously using to use XPT instead of STMPE, both with and without an IRQ. Unfortunately that seemed to make it worse, as the tft does not seem to work now. Then, I found ILI9341Test and modified to use Adafruit_ILI9341 instead of ILI9341_t3, and that does not even seem to compile for the LC (why this error?):

(after seeing the error message in detail, noticing the <font...> was from _t3 lib, //'ing it and font refs out, then it compiled...)

WooHoo!

KenHahn, I am pretty sure I got the ILI9341, know I got it from the PJRC store (so cool that they are a "stone's throw away" from me!), but I did not know which controller my screen had either. However, Thank You so much for your sample code. I pasted it exactly, and it seems to work as well. Another WooHoo! Not sure that the numbers make sense on either example yet, but I am definitely monitoring something. Looks like I will be busy, "thIS weekend" (Chandlerized).

You people are SO great! If I have more questions, hope I can reply to this thread again.
 
Back
Top