Aargh:
I turned on the T4 with the adafruit one 480x272... And tried doing a calibration and I am seeing Strange values....
I mucked up the calibrate sketch to print out more data and to allow me to run it on one that has calibration data...
Code:
/* Simply Touch screen library calibration V2:
this will help you to calibrate your touch screen by modify
4 parameters inside RA8875/_utility/RA8875Calibration.h file:
TOUCSRCAL_XLOW //min value of x you can get
TOUCSRCAL_XHIGH //max value of x you can get
TOUCSRCAL_YLOW //min value of y you can get
TOUCSRCAL_YHIGH //max value of y you can get
Normally those parameters are set as 0.
Only for RESISTIVE TOUCH SCREEN!
It's not a bullet-proof scientist alghorithm but calibrate
using this method will be fast and enough accurate for basic
touch screen operations like buttons, etc. If you need more
precision and you don't want waste resources consider a capacitive touch!
Now run this program and open Serial Monitor or follow screen instrunctions.
Works with Arduino 1.0.6 IDE, Arduino 1.6.x IDE
*/
#include <SPI.h>
#include <RA8875.h>
/*
Arduino's
You are using 4 wire SPI here, so:
MOSI: 11//DUE refere to arduino site
MISO: 12//DUE refere to arduino site
SCK: 13//DUE refere to arduino site
the rest of pin below:
*/
#define RA8875_INT 3 //any pin
#define RA8875_CS 10 //see below...
/* DUE: should be any but not sure */
#define RA8875_RESET 9//any pin or nothing!
RA8875 tft = RA8875(RA8875_CS, RA8875_RESET); //arduino's
const uint8_t samples = 20;
uint16_t tempData[samples][2];
volatile int count = 0;
uint16_t tx, ty;//used as temp
uint16_t _XLOW_VAR;
uint16_t _YLOW_VAR;
uint16_t _XHIGH_VAR;
uint16_t _YHIGH_VAR;
bool proceed;
int scount = 0;
#if !defined(USE_RA8875_TOUCH) || defined(_AVOID_TOUCHSCREEN)
#error "you need to enable resistive touchscreen by uncommenting USE_RA8875_TOUCH in settings!"
#endif
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(Adafruit_480x272, 16, 12000000);//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?
if (tft.width() > 480) tft.setFontScale(1);
Serial.println("You have old calibration data present!\n");
Serial.println("Will temporarliy clear it!\n");
tft.setTouchCalibrationData(0,0,0,0);
tft.setCursor(0, 0);
tft.setTextColor(RA8875_RED);
tft.println("---> You have old calibration data present! <---");
tft.setTextColor(RA8875_WHITE);
tft.println("Will temporarily remove it\n");
}
Serial.println("Start calibration, please follow indications...\n");
Serial.println("\nPlease press FIRMLY the TOP/LEFT angle of your screen now!\n");
if (tft.width() > 480) tft.setFontScale(1);
tft.setCursor(CENTER, CENTER);
tft.setTextColor(RA8875_WHITE);
tft.print("Please press the TOP/LEFT angle now!");
tft.fillCircle(5, 5, 5, RA8875_RED);
proceed = true;
//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
}
void loop() {
if (proceed) {
if (tft.touched()) {
if (count >= samples) {
tft.touchEnable(false);
count = 0;//reset counts
uint32_t valx = 0;
uint32_t valy = 0;
if (scount < 1) {
for (uint8_t i = 0; i < samples; i++) {
valx += tempData[i][0];
valy += tempData[i][1];
}
valx = valx / samples;
valy = valy / samples;
tft.fillWindow();
if (tft.width() > 480) tft.setFontScale(1);
tft.setCursor(CENTER, CENTER);
tft.setTextColor(RA8875_WHITE);
tft.println("Top/Left done. Please do not touch screen...");
tft.setTextColor(RA8875_RED);
tft.setFontScale(1);
tft.print("Please do not touch screen!");
tft.setFontScale(0);
Serial.print("Top/Left done...");
Serial.print("Please do not touch screen...");
_XLOW_VAR = valx;
_YLOW_VAR = valy;
delay(3000);
tft.fillWindow();
tft.fillCircle(tft.width() - 5, tft.height() - 5, 5, RA8875_RED);
if (tft.width() > 480) tft.setFontScale(1);
tft.setCursor(CENTER, CENTER);
tft.setTextColor(RA8875_WHITE);
tft.print("ok, Now Touch Bottom/Right angle!");
Serial.println("\n...done, Now Touch Bottom/Right angle!");
delay(2000);
tft.touchEnable(true);
scount++;
} else if (scount >= 1) {
for (uint8_t i = 0; i < samples; i++) {
valx += tempData[i][0];
valy += tempData[i][1];
}
valx = valx / samples;
valy = valy / samples;
tft.fillWindow();
tft.setCursor(0, 20);
tft.setTextColor(RA8875_WHITE);
tft.println("Calibration done...watch results!");
Serial.println("\nCalibration done...watch results");
_XHIGH_VAR = valx;
_YHIGH_VAR = valy;
tft.println("Now open file:");
tft.setTextColor(RA8875_YELLOW);
tft.println("RA8875/_utility/RA8875Calibration.h");
tft.setTextColor(RA8875_WHITE);
Serial.println("\nNow open file RA8875/_utility/RA8875Calibration.h\n");
Serial.println("Change the following:\n");
tft.println("Change the following:");
tft.println(" ");
tft.setTextColor(RA8875_GREEN);
tft.print("#define TOUCSRCAL_XLOW ");
tft.setTextColor(RA8875_YELLOW);
tft.println(_XLOW_VAR, DEC);
tft.setTextColor(RA8875_GREEN);
tft.print("#define TOUCSRCAL_YLOW ");
tft.setTextColor(RA8875_YELLOW);
tft.println(_YLOW_VAR, DEC);
tft.setTextColor(RA8875_GREEN);
tft.print("#define TOUCSRCAL_XHIGH ");
tft.setTextColor(RA8875_YELLOW);
tft.println(_XHIGH_VAR, DEC);
tft.setTextColor(RA8875_GREEN);
tft.print("#define TOUCSRCAL_YHIGH ");
tft.setTextColor(RA8875_YELLOW);
tft.println(_YHIGH_VAR, DEC);
tft.setTextColor(RA8875_WHITE);
tft.println(" ");
tft.println("...then save file and you are calibrated!");
Serial.println("#define TOUCSRCAL_XLOW 0");
Serial.println("#define TOUCSRCAL_YLOW 0");
Serial.println("#define TOUCSRCAL_XHIGH 0");
Serial.println("#define TOUCSRCAL_YHIGH 0");
Serial.println("\nInto:\n");
Serial.print("#define TOUCSRCAL_XLOW ");
Serial.println(_XLOW_VAR, DEC);
Serial.print("#define TOUCSRCAL_YLOW ");
Serial.println(_YLOW_VAR, DEC);
Serial.print("#define TOUCSRCAL_XHIGH ");
Serial.println(_XHIGH_VAR, DEC);
Serial.print("#define TOUCSRCAL_YHIGH ");
Serial.println(_YHIGH_VAR, DEC);
Serial.println("\nSave and Have a nice day!");
proceed = false;
tft.touchEnable(false);
}
} else {//continue get samples
delay(1);
tft.touchReadAdc(&tx, &ty);//we using 10bit adc data here
if (count >= 0) {
tempData[count][0] = tx;
tempData[count][1] = ty;
Serial.printf("count: %d x:%u y:%u\n", count, tx, ty);
}
count++;
}
}
}//proceed
}
And I am getting weird values...
Code:
You have old calibration data present!
Will temporarliy clear it!
Start calibration, please follow indications...
Please press FIRMLY the TOP/LEFT angle of your screen now!
count: 0 x:1036 y:975
count: 1 x:1043 y:978
count: 2 x:1038 y:974
count: 3 x:1042 y:974
count: 4 x:1037 y:1069
count: 5 x:1041 y:982
count: 6 x:1043 y:864
count: 7 x:1038 y:979
count: 8 x:1044 y:985
count: 9 x:1041 y:982
count: 10 x:1043 y:978
count: 11 x:1037 y:1079
count: 12 x:1036 y:982
count: 13 x:1037 y:902
count: 14 x:1038 y:985
count: 15 x:1039 y:981
count: 16 x:1041 y:985
count: 17 x:1039 y:984
count: 18 x:1043 y:1036
count: 19 x:1037 y:985
Top/Left done...Please do not touch screen...
...done, Now Touch Bottom/Right angle!
count: 0 x:3 y:65527
count: 1 x:7 y:65527
count: 2 x:0 y:65531
count: 3 x:3 y:65530
count: 4 x:4 y:65534
count: 5 x:4 y:0
count: 6 x:0 y:65524
count: 7 x:8 y:65524
count: 8 x:4 y:65531
count: 9 x:7 y:65524
count: 10 x:11 y:65532
count: 11 x:3 y:65521
count: 12 x:6 y:65528
count: 13 x:8 y:65531
count: 14 x:7 y:65530
count: 15 x:7 y:65527
count: 16 x:11 y:65528
count: 17 x:6 y:65528
count: 18 x:8 y:13
count: 19 x:4 y:65524
Calibration done...watch results
Now open file RA8875/_utility/RA8875Calibration.h
Change the following:
#define TOUCSRCAL_XLOW 0
#define TOUCSRCAL_YLOW 0
#define TOUCSRCAL_XHIGH 0
#define TOUCSRCAL_YHIGH 0
Into:
#define TOUCSRCAL_XLOW 1039
#define TOUCSRCAL_YLOW 982
#define TOUCSRCAL_XHIGH 5
#define TOUCSRCAL_YHIGH 58975
Save and Have a nice day!
I am guessing I need to update a couple more places including what I mentioned about allowing min > max
instead of calling it min and max, it should probably be called something like TOUCHCAL_UL_X TOUCHCAL_UL_Y TOUCHCAL_LR_X TOUCHCAL_LR_Y
or the like, but don't know if I wish to muck up everything...
So will let you know when I have something that works on this one... Hopefully it does not require changing other stuff like the clocks...