odd issue with an ILI9341 based screen, module is TJCTM24028-SPI 2.8" TFT SPI module, XPT2046 touch screen, nice SD card on the back.
using the adafruit libraries, connected to a 3.3v 8MHz Pro Mini, currently just playing with the screen - this has worked fine on a DUE previously.
issue is a simple programme (code below) - starts up, calibrates, then runs - draws a pixel where you touch it and shows the X,Y as text.
calibration routine is essentially the supplied one, re-written not to use UGCLib (change the drawing routines the the adafruit library, may end up going back)
problem, the touch screen works, for low values of X, goes a bit higher and it goes odd.
e.g. X,Y, reports as 56184,34, which is slightly outside the screen area.
have compared the re-written calibration routine to the UGCLib calibration routine, both output similar values and the UGCLib based touch screen drawing test has the same behaviour.
wondering, does this likely mean the touch screen is FUBAR?
have tried to "adjust" the values, basically by shifting by a constant, however the "constant" needed varies...
thoughts?
#include <Adafruit_TFTLCD.h>
#include <pin_magic.h>
#include <registers.h>
#include <XPT2046.h>
// test code, for Pro Mini, 3.3v 8MHz
// 2.8" TFT board
#define ScreenCS 4 // screen select
#define ScreenLED 5 // screen LED backlight
#define ScreenReset 6 // screen reset
#define ScreenDC 7 // screen data/command
#define SDCS 8 // SD card select
#define TouchCS 9 // touch screen select
#define TouchIRQ 3 // touch screen interrupt
// screen is ILI9341
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
Adafruit_ILI9341 tft = Adafruit_ILI9341(ScreenCS, ScreenDC);
XPT2046 touch(TouchCS, TouchIRQ);
void setup() {
// put your setup code here, to run once:
pinMode(ScreenLED, OUTPUT);
pinMode(ScreenReset, OUTPUT);
digitalWrite(ScreenLED, HIGH); // turn on backlight
digitalWrite(ScreenReset, HIGH); // screen exit reset mode
tft.begin();
tft.fillScreen(ILI9341_BLACK); // black out the screen
touch.begin(240, 320);
TouchCalibrate(); // run calibration routine
tft.setRotation(0); // 0: SD card header top, portrait, (240x320)
// 1: SD card header right, landscape
// 2: SD card header bottom, portrait
// 3: SD card header left, landscape
touch.setRotation(touch.ROT0); // ROT0, ROT90, ROT180 or ROT270
//touch.setCalibration(209, 1759, 1775, 273); // need to update these for the specific panel
// fill background black
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(5,5);
tft.setTextSize(2); // 1: small (not very readable), 2: twice the height (readable)
tft.println("Hello");
// draw a bit of a frame
tft.drawFastHLine(0, 0, tft.width(), ILI9341_WHITE); // top
tft.drawFastHLine(0, tft.height()-1, tft.width(), ILI9341_WHITE); // bottom
tft.drawFastVLine(0,0, tft.height(), ILI9341_WHITE); // left
tft.drawFastVLine(tft.width()-1, 0, tft.height(), ILI9341_WHITE); // right
}
void loop() {
// put your main code here, to run repeatedly:
// if screen is touched, draw a pixel and write out coordinates
if (touch.isTouching())
{
uint16_t x,y;
uint16_t x1,y1;
touch.getPosition(x,y);
if (x > 20)
{
x1 = x-56000;
}
else
{
x1=x;
}
//tft.drawCircle(x-1, y-1, 3, ILI9341_WHITE);
tft.drawPixel(x, y, ILI9341_WHITE);
tft.setCursor(5,25);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.print(x);
tft.print(", ");
tft.print(y);
tft.println(" "); // blank to overwrite previous if needed
tft.print(x1);
tft.print(", ");
tft.print(y1);
tft.println(" ");
}
}
static void calibratePoint(uint16_t x, uint16_t y, uint16_t &vi, uint16_t &vj) {
// Draw cross
tft.drawFastHLine(x-8, y, 16, ILI9341_WHITE);
tft.drawFastVLine(x,y-8, 16, ILI9341_WHITE);
while (!touch.isTouching()) {
delay(10);
}
touch.getRaw(vi, vj);
// Erase by overwriting with black
tft.drawFastHLine(x-8, y, 16, ILI9341_BLACK);
tft.drawFastVLine(x,y-8, 16, ILI9341_BLACK);
}
void TouchCalibrate(void)
{
uint16_t x1, y1, x2, y2;
uint16_t vi1, vj1, vi2, vj2;
touch.getCalibrationPoints(x1, y1, x2, y2);
calibratePoint(x1, y1, vi1, vj1);
delay(1000);
calibratePoint(x2, y2, vi2, vj2);
touch.setCalibration(vi1, vj1, vi2, vj2);
char buf[80];
snprintf(buf, sizeof(buf), "%d,%d,%d,%d", (int)vi1, (int)vj1, (int)vi2, (int)vj2);
// calibration results: 267,1672,1736,298
tft.setCursor(5,5);
tft.println("Screen Calibration");
tft.println(buf);
delay(5000);
}