@mjs513 - A couple of things so far...
I have hacked up the library a little, and added a function to allow me to currently turn off the calibration, and later should be good to allow you to
set one per display...
tft.setTouchCalibrationData(0,0,0,0);
Code:
/**************************************************************************/
/*! A way to have different calibrations for different displays and
a way to force the system to act like uncalibrated, so you don't have
to edit header file, rebuild, edit header again ...
*/
/**************************************************************************/
void RA8875::setTouchCalibrationData(uint16_t minX, uint16_t maxX, uint16_t minY, uint16_t maxY)
{
_tsAdcMinX = minX;
_tsAdcMaxX = maxX;
_tsAdcMinY = minY;
_tsAdcMaxY = maxY;
// Lets guess at setting is calibrated.
_calibrated = ((minX >= maxX) || (minY >= maxY)) ? false : true;
}
I have that one in place to clear out the values and you can also do by simply deleting the calibration information and rebuilding...
I then changed the touchReadAdc and touchReadPixel to just give me the raw data if not calibrated:
Code:
void RA8875::touchReadAdc(uint16_t *x, uint16_t *y)
{
uint16_t tx,ty;
readTouchADC(&tx,&ty);
if (_calibrated) {
#if (defined(TOUCSRCAL_XLOW) && (TOUCSRCAL_XLOW != 0)) || (defined(TOUCSRCAL_XHIGH) && (TOUCSRCAL_XHIGH != 0))
*x = map(tx,_tsAdcMinX,_tsAdcMaxX,0,1024);
#else
*x = tx;
#endif
#if (defined(TOUCSRCAL_YLOW) && (TOUCSRCAL_YLOW != 0)) || (defined(TOUCSRCAL_YHIGH) && (TOUCSRCAL_YHIGH != 0))
*y = map(ty,_tsAdcMinY,_tsAdcMaxY,0,1024);
#else
*y = ty;
#endif
} else {
*x = tx;
*y = ty;
}
_checkInterrupt(2);
}
/**************************************************************************/
/*!
Returns pixel x,y data with SCREEN scale (screen width, screen Height)
Parameters:
x: out 0...screen width (pixels)
Y: out 0...screen Height (pixels)
Check for out-of-bounds here as touches near the edge of the screen
can be safely mapped to the nearest point of the screen.
If the screen is rotated, then the min and max will be modified elsewhere
so that this always corresponds to screen pixel coordinates.
/M.SANDERSCROCK added constrain
*/
/**************************************************************************/
void RA8875::touchReadPixel(uint16_t *x, uint16_t *y)
{
uint16_t tx,ty;
readTouchADC(&tx,&ty);
if (_calibrated) {
*x = constrain(map(tx,_tsAdcMinX,_tsAdcMaxX,0,_width-1),0,_width-1);
//*y = map(ty,_tsAdcMinY,_tsAdcMaxY,0,_height-1);
*y = constrain(map(ty,_tsAdcMinY,_tsAdcMaxY,0,_height-1),0,_height-1);
//*x = map(tx,_tsAdcMinX,_tsAdcMaxX,0,_width-1);
} else {
*x = tx;
//*y = map(ty,_tsAdcMinY,_tsAdcMaxY,0,_height-1);
*y = ty;
}
_checkInterrupt(2);
}
Also I know that telling the display at 12mhz instead of 22mhz helps...
Also I am getting better results now when I don't have touched call the
Code:
#elif defined(USE_RA8875_TOUCH)
_RA8875_INTS &= ~(1 << 0);//clear
//_checkInterrupt(2);//clear internal RA int to re-engage
#endif
I also have a complete mucked up version of touch test, which prints out data:
Like tx, ty to terminal and tries to keep a min max values for these,
if you type in anything in terminal window it will print out min/max values.
if you enter 0-3 it will change rotation, and screen color and reset mins/maxs...
Code:
/* Testing Resistive Touch Screen
*/
#include <SPI.h>
#include <RA8875.h>
/*
Teensy3.x
You are using 4 wire SPI here, so:
MOSI: 11//Teensy3.x
MISO: 12//Teensy3.x
SCK: 13//Teensy3.x
the rest of pin below:
*/
#define RA8875_INT 3 //any pin that have an INT
#define RA8875_CS 10 //see below...
/*Teensy 3.x can use: 2,6,9,10,15,20,21,22,23 */
#define RA8875_RESET 23//any pin or nothing!
static uint16_t tx, ty;//used as temp
uint16_t txPrev = 0xffff;
uint16_t tyPrev = 0xffff;
uint16_t minX = 0xffff;
uint16_t maxX = 0;
uint16_t minY = 0xffff;
uint16_t maxY = 0;
uint16_t rotation_colors[4] = {RA8875_RED, RA8875_GREEN, RA8875_BLUE, RA8875_YELLOW};
RA8875 tft = RA8875(RA8875_CS, RA8875_RESET);//Teensy3/arduino's
void setup() {
Serial.begin(38400);
long unsigned debug_start = millis ();
while (!Serial && ((millis () - debug_start) <= 5000)) ;
// begin display: Choose from: RA8875_480x272, RA8875_800x480, RA8875_800x480ALT, Adafruit_480x272, Adafruit_800x480
tft.begin(RA8875_480x272, 16, 10000000);//initialize RA8875
/* Adafruit_480x272 Adafruit_800x480 RA8875_480x272 RA8875_800x480 */
tft.useINT(RA8875_INT);//We use generic int helper for Internal Resistive Touch
tft.touchBegin();//enable touch support for RA8875
if (!tft.touchCalibrated()) {//already calibrated?
Serial.println("Maybe better you calibrate first!");
Serial.println("Clearing it out");
tft.setTouchCalibrationData(0,0,0,0);
}
//this enable an ISR on CPU and RA8875 INT
tft.enableISR(true);
//You can avoid ISR by simple ignore the line above
//it will use the slower digitalRead(pin) alternative internally
tft.fillWindow(rotation_colors[0]);
}
void loop() {
if (tft.touched()) {
//if you are here means that you touched screen
tft.touchReadPixel(&tx,&ty);//read directly in pixel
if ((tx != txPrev) || (ty != tyPrev)) {
tft.fillCircle(tx,ty,5,0xFFFF);
Serial.printf("TX: %u TY: %u\n", tx, ty);
if (tx < minX) minX = tx;
if (tx > maxX) maxX = tx;
if (ty < minY) minY = ty;
if (ty > minY) maxY = ty;
}
}
if (Serial.available()) {
Serial.printf("X Range: %u %u Y Range: %u %u\n", minX, maxX, minY, maxY);
uint8_t rot = Serial.read();
if ((rot >= '0') && (rot <= '3')) {
rot -= '0';
tft.setRotation(rot);
tft.fillWindow(0);
Serial.printf("\n\n*** Set Rotation(%d) ***\n", rot);
tft.setTouchCalibrationData(0,0,0,0);
tft.fillWindow(rotation_colors[rot]);
minX = 0xffff;
maxX = 0;
minY = 0xffff;
maxY = 0;
}
while (Serial.read() != -1) ; // clear out rest of data
}
}
Again nothing special, but at least you can start to see how the numbers change...
Edit: with running at 12mhz and remove that call to clear out stuff in the touched member, The easyPaint program sort of works. There looks like some of the data is sort of non-consistent. Probably would need/want some of the filtering stuff, but probably good enough for now... I might even be able to hack in the stuff to try out to the two resistive displays I have (one BuyDisplay one Adafruit).