Hi all, wonder if the experts here can help me get the ILI9341 touchscreen working. I bought a couple of chinese IL9341 boards from ebay, visually pretty identical to the part sold by PJRC in the US. I checked that the board contains a 2046 touchscreen controller, it does, though its a compatible type, HR2046. The prototype setup is using wire wrap/solder, I'm still learning the technique and have gained a better strip tool since it was constructed! I've treble beep-checked all wiring and its ok, including repeated connectivity checks topside between the Teensy 4.1 and display board. There are no adjacent pin shorts either. The SPI0 interface pins are standard as per my code comments and according to the Teensy 9341 guidance on this site. Reset is via 1k/0.1u cap rather than software. The board backlight LED is wired to a Teensy pin. Default SPI0 pins are used for the ILI9341 and controller both, SPI1 is wired to a DPS310 barometric sensor breakout. The touchscreen, display and DPS310 all have individual CS pins.
I developed some DPS310 code that outputs nicely to the ILI9341 display, using the t3n library, no problems seen. I can run the display's SPI at 100MHz fine even with the touchscreen in parallel on the bus. I've slowed that rate in the test code below though. Display refresh becomes invisible when I use buffered writes with t3n screenUpdate() but I've also not used those features in the test code below. When I ran into problems adding touchscreen code to my code I switched to trying the PS library example code below instead, it doesn't set up SPI1 so that hardware should not be relevant here.
Whenever I run XPT2046 code the touchscreen acts like its being touched even when it has not been, right from startup. It opens up with a confirmed touch response, always at -4096 x/y, ts.touched() *always* returns true even when there is no touch based on adding tests to the code. See images for output. My orientation setting is 3, I tried 1, that gave be coordinates both 8191, same false touch response, coordinates now 8191 though. The LED on CLK 13 flickers pretty constantly showing the polling. I also ran the IRQ mode test code, same result, permanent false touch response from startup. This happened both within my full code and after switching to the display board only library test code below. I've pictured both my screen and serial output. I've seen threads here implying its fine to use the t3n display library version, also I cant seem to get the t3 version to compile even though the Adafruit original version is installed here also.
I'm wondering why this is happening given the basic default type hardware and use of a library combination already documented here. There are threads online mentioning similar "false touch" responses, though no clear solutions. I've tried different display SPI rates on SPI0, no effect. Looking at both libraries they appear to be transactional, cant see why there would be a hardware SPI problem, particularly given that my board seems to run fine at 100 MHz in display mode. Considered whether noise might be a problem, does anyone here have any thoughts on adding further bypass capacitors or filtering? All ideas welcomed, I really want to use the KurtE t3n library vesion in my code and it would be great to get concurrent touchscreen use,
Steve
Output from my full code:
Test code here output:
I developed some DPS310 code that outputs nicely to the ILI9341 display, using the t3n library, no problems seen. I can run the display's SPI at 100MHz fine even with the touchscreen in parallel on the bus. I've slowed that rate in the test code below though. Display refresh becomes invisible when I use buffered writes with t3n screenUpdate() but I've also not used those features in the test code below. When I ran into problems adding touchscreen code to my code I switched to trying the PS library example code below instead, it doesn't set up SPI1 so that hardware should not be relevant here.
Whenever I run XPT2046 code the touchscreen acts like its being touched even when it has not been, right from startup. It opens up with a confirmed touch response, always at -4096 x/y, ts.touched() *always* returns true even when there is no touch based on adding tests to the code. See images for output. My orientation setting is 3, I tried 1, that gave be coordinates both 8191, same false touch response, coordinates now 8191 though. The LED on CLK 13 flickers pretty constantly showing the polling. I also ran the IRQ mode test code, same result, permanent false touch response from startup. This happened both within my full code and after switching to the display board only library test code below. I've pictured both my screen and serial output. I've seen threads here implying its fine to use the t3n display library version, also I cant seem to get the t3 version to compile even though the Adafruit original version is installed here also.
I'm wondering why this is happening given the basic default type hardware and use of a library combination already documented here. There are threads online mentioning similar "false touch" responses, though no clear solutions. I've tried different display SPI rates on SPI0, no effect. Looking at both libraries they appear to be transactional, cant see why there would be a hardware SPI problem, particularly given that my board seems to run fine at 100 MHz in display mode. Considered whether noise might be a problem, does anyone here have any thoughts on adding further bypass capacitors or filtering? All ideas welcomed, I really want to use the KurtE t3n library vesion in my code and it would be great to get concurrent touchscreen use,
Steve
Code:
// Hardware:
// Teensy 4.1
//
// SPI0 interface:
// ILI9341 TFT display pins info: Vcc+5v(1), GND(2),CS(3), Reset(4) (via 1k to +3v, 0.1u cap),DC(5),SDI(6),SCK(7),Backlight LED(8),SDO(9)
// ILI9341 touch controller pins: TCLK(10), TCS(11), TDIN(12), TDO(13), TIRQ(14) // ILI9341 pin 1 is top, SD card skt uppermost
// Connections on Teensy:
// Teensy TFT pins: CLK to SCK 13, DI to MOSI 11, TDO to MISO 12, CS to i/o 10(CS only used in software), DC to i/o 9, LED to 7
// Teensy touch pins: TCLK to SCK 13, TCS to i/o 8, TDIN to MOSI 11, TDO to MISO 12, TIRQ to i/o 2
//
// SPI1 interface:
// DPS310 barometric sensor board, Vcc +5v, SCK 27, SDI 26, SDO 39, CS 38 (CS used only in software)
#include <ILI9341_t3n.h>
#include <ili9341_t3n_font_Arial.h> // from ILI9341_t3n lib
#include <XPT2046_Touchscreen.h>
#include <SPI.h>
#define LED 13 // LED is on pin 13 Teensy board
#define TFT_BACKLIGHT 7 // TFT backlight
#define TFT_RESET 255 // 255 = not controlled by library
#define TFT_MOSI 11
#define TFT_SCLK 13
#define TFT_MISO 12
#define TFT_SPI_RATE 30000000
#define CS_PIN 8
#define TFT_DC 9
#define TFT_CS 10
// MOSI=11, MISO=12, SCK=13
XPT2046_Touchscreen ts(CS_PIN);
#define TIRQ_PIN 2
//XPT2046_Touchscreen ts(CS_PIN); // Param 2 - NULL - No interrupts
//XPT2046_Touchscreen ts(CS_PIN, 255); // Param 2 - 255 - No interrupts
//XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN); // Param 2 - Touch IRQ Pin - interrupt enabled polling
// ILI9341_t3n tft = ILI9341_t3n (TFT_CS, TFT_DC, TFT_RESET, TFT_MOSI, TFT_SCLK, TFT_MISO);
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC);
void setup() {
pinMode(TFT_BACKLIGHT, OUTPUT); // TFT display backlight
digitalWrite(TFT_BACKLIGHT, 1); // On
Serial.begin(38400);
tft.begin(TFT_SPI_RATE,200000);
tft.setRotation(3);
tft.fillScreen(ILI9341_BLACK);
ts.begin();
ts.setRotation(3);
while (!Serial && (millis() <= 1000));
}
boolean wastouched = true;
void loop() {
boolean istouched = ts.touched();
if (istouched) {
TS_Point p = ts.getPoint();
if (!wastouched) {
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
tft.setFont(Arial_60);
tft.setCursor(60, 80);
tft.print("Touch");
}
tft.fillRect(100, 150, 140, 60, ILI9341_BLACK);
tft.setTextColor(ILI9341_GREEN);
tft.setFont(Arial_24);
tft.setCursor(100, 150);
tft.print("X = ");
tft.print(p.x);
tft.setCursor(100, 180);
tft.print("Y = ");
tft.print(p.y);
Serial.print(", x = ");
Serial.print(p.x);
Serial.print(", y = ");
Serial.println(p.y);
} else {
if (wastouched) {
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_RED);
tft.setFont(Arial_48);
tft.setCursor(120, 50);
tft.print("No");
tft.setCursor(80, 120);
tft.print("Touch");
}
Serial.println("no touch");
}
wastouched = istouched;
delay(100);
}
Output from my full code:
Test code here output: