Closed ryanaukes closed 7 months ago
This is not a behaviour I have seen before. Can you try reducing the touch SPI frequency to 1MHz.
#define SPI_TOUCH_FREQUENCY 1000000
Another option is to try this library: https://github.com/achillhasler/TFT_eTouch
Hi ,yanaukes, have you tried with MISO connected to nothing (on the air),even if the setup shows pin0?
This is not a behaviour I have seen before. Can you try reducing the touch SPI frequency to 1MHz.
#define SPI_TOUCH_FREQUENCY 1000000
@Bodmer Thanks for the answer! Unfortunately that does not solve my proble. Is there anything else I can do to debug this problem? Just to be sure: the pins are referring to the GP pins (in green), so not the numbers in the gray squares, according to this picture?
Hi ,yanaukes, have you tried with MISO connected to nothing (on the air),even if the setup shows pin0?
@copyCATandpasteDOG Thanks for the suggestion. I tried disconnecting the MISO pin, but then I get no response at all from the touchscreen.
Maybe it is helpfull. This is a part of the serial output of the "Test_Touch_Controller" sketch:
x: 0 y: 7936 z: 4863
x: 0 y: 7936 z: 4607
x: 0 y: 7936 z: 62463
x: 0 y: 7936 z: 65535
x: 0 y: 7936 z: 767
x: 0 y: 7936 z: 62463
x: 0 y: 7936 z: 2559
x: 2560 y: 7936 z: 64255
x: 0 y: 7936 z: 3583
x: 0 y: 7936 z: 65023
x: 0 y: 7936 z: 62719
x: 0 y: 7936 z: 62463
x: 0 y: 7936 z: 62463
x: 0 y: 7936 z: 1535
x: 0 y: 7936 z: 511
x: 0 y: 7936 z: 62719
x: 0 y: 7936 z: 62207
x: 0 y: 7936 z: 62207
x: 0 y: 7936 z: 62207
x: 0 y: 7936 z: 1279
x: 0 y: 7936 z: 5119
x: 0 y: 7936 z: 62463
x: 0 y: 7936 z: 62463
x: 0 y: 7936 z: 62463
x: 0 y: 7936 z: 62463
x: 0 y: 7936 z: 62719
x: 0 y: 7936 z: 3071
x: 0 y: 7936 z: 64767
x: 0 y: 7936 z: 3327
x: 0 y: 7936 z: 3071
x: 0 y: 7936 z: 62207
x: 0 y: 7936 z: 64767
x: 0 y: 7936 z: 4607
x: 0 y: 7936 z: 64255
x: 0 y: 7936 z: 511
x: 4864 y: 7936 z: 62463
x: 0 y: 7936 z: 1023
x: 0 y: 7936 z: 1023
x: 0 y: 7936 z: 62463
x: 0 y: 7936 z: 1791
x: 0 y: 7936 z: 2815
x: 0 y: 7936 z: 767
x: 0 y: 7936 z: 62463
x: 0 y: 7936 z: 65535
x: 0 y: 7936 z: 62463
x: 0 y: 7936 z: 4607
x: 0 y: 7936 z: 3071
x: 0 y: 7936 z: 62719
x: 0 y: 7936 z: 64255
x: 0 y: 7936 z: 5631
x: 0 y: 7936 z: 62207
x: 7168 y: 7936 z: 62207
ryanaukes wrote: "Thanks for the suggestion. I tried disconnecting the MISO pin, but then I get no response at all from the touchscreen."
of course TFT T_DO -> pin 0, even if MISO is disconnected
Which version of TFT_eSPI is being used?
Have you tried the suggested TFT_eTouch library?
Maybe the pico has specifics pins that don't work in some cases, This setup works well for me:
// Stripped down User_Setup.h version for the Pico-Matrix-Touch-Keyboard //
#define ILI9341_DRIVER
#define TFT_MISO 0
#define TFT_MOSI 3
#define TFT_SCLK 2
#define TFT_CS 20 // Chip select control pin
#define TFT_DC 22 // Data Command control pin
#define TFT_RST 21 // Reset pin (could connect to Arduino RESET pin)
#define TOUCH_CS 14 // Chip select pin (T_CS) of touch screen
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
// Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded
// this will save ~20kbytes of FLASH
#define SMOOTH_FONT
#define SPI_FREQUENCY 27000000
// Optional reduced SPI frequency for reading TFT
#define SPI_READ_FREQUENCY 20000000
// The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here:
#define SPI_TOUCH_FREQUENCY 2500000
The sketch that works for me with pico: "Big keypad" from TFT e_spi (keypad) :
//Big keypad
#include "Arduino.h"
#include "LittleFS.h"
#include <SPI.h>
#include <TFT_eSPI.h>
// Name of the Touch calibration file
#define CALIBRATION_FILE "/TouchCalData2"
// Define our filesystem
#define FILESYSTEM LittleFS
// Set to tru if you want the calibration to run on each boot
#define REPEAT_CAL false
// Keypad start position, key sizes and spacing
#define KEY_W 95 // Key width
#define KEY_H 95 // Key height
#define KEY_SPACING_X 20 // X gap
#define KEY_SPACING_Y 10 // Y gap
#define KEY_X (KEY_W/2) + KEY_SPACING_X // X-axis centre of the first key
#define KEY_Y (KEY_H/2) + KEY_SPACING_Y // Y-axis centre of the first key
#define KEY_TEXTSIZE 3 // Font size multiplier
// Choose the font you are using
#define LABEL1_FONT &FreeSansOblique12pt7b // Key label font
// Adding a delay between keypressing to give our OS time to respond
uint8_t keydelay = 100;
// Create the screen object
TFT_eSPI tft = TFT_eSPI();
// Creating the labels for the buttons
// <name>[<number-of-lables>][<number-of-chars-per-label]
// The number of chars per label should include the termination \0.
char keyLabel[12][3] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};
// Setting the colour for each button
// You can use the colours defined in TFT_eSPI.h
uint16_t keyColor[12] = {TFT_BLUE, TFT_RED, TFT_DARKCYAN, TFT_NAVY,
TFT_MAROON, TFT_MAGENTA, TFT_ORANGE, TFT_SKYBLUE,
TFT_PURPLE, TFT_ORANGE, TFT_PINK, TFT_DARKCYAN
};
// Create 12 'keys' to use later
TFT_eSPI_Button key[12];
void setup() {
Serial.begin(115200);
Serial.println("");
// Initialise the TFT screen
tft.init();
// Set the rotation before we calibrate
tft.setRotation(1);
touch_calibrate();
// Clear the screen
tft.fillScreen(TFT_BLACK);
// Begin the Keyboard
// Draw the keys ( 3 times 4 loops to create 12)
for (uint8_t row = 0; row < 3; row++) { // 3 rows
for (uint8_t col = 0; col < 4; col++) { // of 4 buttons
uint8_t b = col + row * 4; // The button number is the column we are on added to the row we are on
// multiplied by the number of buttons per row. C++ uses the Order of operations
// you are used to so first the row is multiplied by 4 and then the col is added.
// The first button is 0.
// Example. col = 2 (third column), row = 1 (second row), becomes: 1 * 4 = 4 --> 4 + 2 = 6. This is the 7th button.
key[b].initButton(&tft, KEY_X + col * (KEY_W + KEY_SPACING_X),
KEY_Y + row * (KEY_H + KEY_SPACING_Y), // x, y, w, h, outline, fill, text
KEY_W, KEY_H, TFT_WHITE, keyColor[b], TFT_WHITE,
keyLabel[b], KEY_TEXTSIZE);
key[b].drawButton();
}
}
}
void loop() {
uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
// Pressed will be set true is there is a valid touch on the screen
bool pressed = tft.getTouch(&t_x, &t_y);
// Check if any key coordinate boxes contain the touch coordinates
for (uint8_t b = 0; b < 12; b++) {
if (pressed && key[b].contains(t_x, t_y)) {
key[b].press(true); // tell the button it is pressed
} else {
key[b].press(false); // tell the button it is NOT pressed
}
}
// Check if any key has changed state
for (uint8_t b = 0; b < 12; b++) {
if (key[b].justReleased()) key[b].drawButton(); // draw normal again
if (key[b].justPressed())
{
key[b].drawButton(true); // draw invert (background becomes text colour and text becomes background colour
buttonpress(b); // Call the button press function and pass the button number
}
}
}
void buttonpress(int button)
{
//Handle a button press. Buttons are 0 indexed, meaning that the first button is button 0.
switch(button){
case 0:
Serial.println("Button 1 pressed");
break;
case 1:
Serial.println("Button 2 pressed");
break;
case 2:
Serial.println("Button 3 pressed");
break;
case 3:
Serial.println("Button 4 pressed");
break;
case 4:
Serial.println("Button 5 pressed");
break;
case 5:
Serial.println("Button 6 pressed");
break;
case 6:
Serial.println("Button 7 pressed");
break;
case 7:
Serial.println("Button 8 pressed");
break;
case 8:
Serial.println("Button 9 pressed");
break;
case 9:
Serial.println("Button 10 pressed");
break;
case 10:
Serial.println("Button 11 pressed");
break;
case 11:
Serial.println("Button 12 pressed");
break;
}
}
void touch_calibrate()
{
uint16_t calData[5];
uint8_t calDataOK = 0;
// check file system exists
if (!FILESYSTEM.begin()) {
Serial.println("Formating file system");
FILESYSTEM.format();
FILESYSTEM.begin();
}
// check if calibration file exists and size is correct
if (FILESYSTEM.exists(CALIBRATION_FILE)) {
if (REPEAT_CAL)
{
// Delete if we want to re-calibrate
FILESYSTEM.remove(CALIBRATION_FILE);
}
else
{
File f = FILESYSTEM.open(CALIBRATION_FILE, "r");
if (f) {
if (f.readBytes((char *)calData, 14) == 14)
calDataOK = 1;
f.close();
}
}
}
if (calDataOK && !REPEAT_CAL) {
// calibration data valid
tft.setTouch(calData);
} else {
// data not valid so recalibrate
tft.fillScreen(TFT_BLACK);
tft.setCursor(20, 0);
tft.setTextFont(2);
tft.setTextSize(1);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.println("Touch corners as indicated");
tft.setTextFont(1);
tft.println();
if (REPEAT_CAL) {
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.println("Set REPEAT_CAL to false to stop this running again!");
}
tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.println("Calibration complete!");
// store data
File f = FILESYSTEM.open(CALIBRATION_FILE, "w");
if (f) {
f.write((const unsigned char *)calData, 14);
f.close();
}
}
}
Hope you'll find something to do with
ryanaukes wrote: "Thanks for the suggestion. I tried disconnecting the MISO pin, but then I get no response at all from the touchscreen."
of course TFT T_DO -> pin 0, even if MISO is disconnected
I quickly tried that, but then I get the same results from the touch screen (high Z values). I will try the code you posted when I have some more time, thanks!
Which version of TFT_eSPI is being used?
Have you tried the suggested TFT_eTouch library?
I am using version 2.5.0. Unfortunately I have not had the time to test the TFT_eTouch library. I will let you know if it works when I have time to test it.
Today I had some time to do some more testing. It seems that the problem is related to the Arduino-mbed RP2040 core I am using. I installed the arduino-pico core by Earle Philhower using the board manager and now everything seems to work!
Thanks again for your help!
Good news, i always thought you were using the Philhower library :)
Thanks for the update, glad to hear it is working now.
The TFT_eSPI library functions have worked with the Arduino-mbed RP2040 core in the past with the exception that the hardware PIO capabilities are not supported by the mbed core. I will investigate further, it may be the case that the mbed core has been updated and the compatibility has been lost or that a TFTeSPI library update has introduced an incompatibility.
The Philhower library is a better choice in most cases due to the enhanced capabilites and regular support updates.
I have tested this and it is working now with the latest Github master (not released yet).
I have not made any changes specific to this issue but maybe some other updates fixed this.
Hello,
I am trying to use this library with my RP2040 microcontroller and ILI9341 screen with touchscreen and SD card reader. Currently I only connected the TFT screen and touchscreen pins.
Connected as follows: TFT VCC -> 5V of PSU TFT VCC -> GND of PSU and RP2040 TFT CS -> pin 20 TFT RESET -> pin 19 TFT DC -> pin 18 TFT MOSI -> pin 3 TFT SCK -> pin 2 TFT LED -> 5V of PSU TFT MISO -> pin 0 TFT T_CLK -> pin 2 TFT T_CS -> pin 21 TFT T_DIN -> pin 3 TFT T_DO -> pin 0
This is what the file called 'User_Setup_Select.h' looks like:
This is what the file called 'Setup60_RP2040_ILI9341.h' looks like:
When I upload the example sketch called 'TFT_Rainbow_one_lib', the screen works fine.
When I upload the example sketch called 'Touch_calibrate', the text and arrows pointing to the corners are displayed shortly, but it quickly continues to the part where it shows the text 'Touch screen to test!'. It seems like the screen is pressed, without me doing anything.
When I run the example sketch called 'Test_Touch_Controller', I can see that the Z values are always really high (fluctuating between 500 and 70000, but mostly above 60000).
When I run the same test sketches on a ESP32, everything works fine, and I can calibrate the screen succesfully. The Z values in this case are below 30 when not touching the screen. So the screen seems to be working fine. I hope someone can help me find the problem. Thanks in advance!
(Edit: code blocks were not working, fixed that)