Ili9341 Touchscreen registers input when not pressed

Hi Arduino-Community,

I'm working in a project with an ILI9341-Touchscreen (Adafruit 2.8" TFT LCD with resistive touchscreen (1770)). I followed the HowTo-Guide and everything worked perfectly so far.

The project is supposed to monitor some environmental data, show them on screen and save them to SD-Card( MicroSD card breakout board+ (254)). A RTC (Adafruit DS3231 Precision RTC Breakout (3013) keeps track of time. The touchscreen is also used for configuration purposes. When the screen is touched anywhere a menu opens and gives the user some options.

When I did a 24h test, I detected some strange behaviour. Every couple of hours the menu opens without any touch input. Because this happens so few I find it difficult to debug. I've searched the web for a couple of hours now and came up with nothing related to my problem.
Do you have an idea how I could investigate this bug or has this happend to you also?

Additional Information:

  • An Arduino Mega 2560 is used
  • I did a calibration by measunging the resistance between X+ and X- and put it in the code (345 Ohms).
  • I tried to play with the MIN- and MAXPRESSURE values to no avail.
  • As of now I did a workaround to close the menu after 5 min, but I would like to do it propper :-).
  • I used this code in my loop function to detect if the screen was pressed:
if (ts.pressure() > minPressure) {
  configurationMenu();  //opens configuration menu
}

My suggestions so far:

  • some mixup between the SD-Card-Reader and the screen because both use the SPI-Interface
  • accessing the touchscreen ts without using a TSPoint
  • I've done something stupid :slight_smile:

I'm very thankful for your input and suggestions.

Because my code has a couple of thousand lines, I cut it to the relevant parts. If you need more please ask.

//==============================================
//LIBRARIES
//==============================================
//ili9341 Touchscreen
#include <Adafruit_GFX.h> //look at this library for drawing and text commands
#include <Adafruit_ILI9341.h>
#include <TouchScreen.h>

//==============================================
//VARIABLES and CONSTANTS
//==============================================
/*TOUCH*/
//Pins for reading the touchscreen
#define YP A2  // must be an analog pin, use "An" notation!
#define XM A3  // must be an analog pin, use "An" notation!
#define YM 9   // can be any digital pin
#define XP 8   // can be any digital pin

//Calibration data to convert raw touch data to screen coordinates. If touchscreen readings are inaccurate these need to be changed. A good way to adjust these is to look at the breakouttouchpaint example.
#define TS_MINX 120
#define TS_MINY 80
#define TS_MAXX 900
#define TS_MAXY 904

//define min/max pressure of the touchscreen
#define MINPRESSURE 10
#define MAXPRESSURE 1000

/*SCREEN*/
//Pins for the screen
#define TFT_CS 46
#define TFT_DC 48

//Calibration for pressure detection on the touchscreen. If calibration is necessary replace number value with the resistance between X+ and X- on the touchscreen breakout (use a multimeter for measuring)
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 345);
unsigned int minPressure = 100; //minimal pressure to detect a screen press

//Create touchscreen object
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

//==============================================
//SETUP
//==============================================
void setup() {
  Serial.begin(9600);

  //DISPLAY
  tft.begin();  //Start screen
  tft.fillScreen(ILI9341_BLACK); //make screen black to overwrite anything shown before
  tft.setRotation(1); //set screen to landscape
}

//==============================================
//LOOP
//==============================================
void loop() {  
  if (ts.pressure() > minPressure) {
    configurationMenu();  //opens configuration menu
  }
}
//do other stuff

Tonight I logged values for ts.pressure() on the serial monitor. Three events have taken place, values vary over a wide range and are mostly in the negative thousands. I don't know why they can be negative, but with that I'm able to filter most false events.

I've changed:

to

unsigned int preassure = ts.pressure();
if (preassure  > 100 && preassure  < 500) {
  configurationMenu();
}

So far no false screen presses have been detected, but I'll do some further testing.

I'll make an update to this post in a few days :-). Wish me luck!!!

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