cancel
Showing results for 
Search instead for 
Did you mean: 

Resistive touch screen calibration problem: setCalibrationMatrix translating points incorrectly

JLakn
Associate II

Hey,

I'm working on custom board project with display size 800x480px and resistive touch screen. I have issue with using setCalibrationMatrix. Below is code snippet from my STM32TouchController.cpp file. In initalization, calibration matrix i set by calling calib.setCalibrationMatrix(reference_points, adc_points). I determined adc_points using the debugger by clicking on reference_points drawn on the screen. adc_points are raw values from AD converter the same goes for x_val and y_val in sampleTouch routine. After the calibration matrix is set as seen below the values in touchgfx engine are translated incorrectly. To be precise y coordinate is offseted by +160. Here are three examples for touched and translated points:

  • pressed reference point drawn on screen in position

x: 40 y: 40 is translated to x: 42 y: 203 (raw adc values: x: 427 y: 804)

  • x: 760 y: 40 -----------------> x: 762 y: 202 (raw adc values: x: 3678 y: 844)
  • x: 760 y: 440 -----------------> x: 762 y: 603 (raw adc values: x: 3677 y: 3489)

So my question is am I doing something wrong or is something wrong with mathematics in touchgfx engine ?

TouchCalibration calib;
touchgfx::Point  reference_points[3] =  
{
    {  40,  40 },
    { 760,  40 },
    { 760,  440 }
};
touchgfx::Point  adc_points[3]=
{
    {  424, 820},  
    { 3675, 861}, 
    { 3678, 3502}, 
};
 
void STM32TouchController::init()
{
    /**
     * Initialize touch controller and driver
     *
     */
	calib.setCalibrationMatrix(reference_points, adc_points);
}
 
bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
{
    /**
     * By default sampleTouch returns false,
     * return true if a touch has been detected, otherwise false.
     *
     * Coordinates are passed to the caller by reference by x and y.
     *
     * This function is called by th
     * e TouchGFX framework.
     * By default sampleTouch is called every tick, this can be adjusted by HAL::setTouchSampleRate(int8_t);
     *
     */
 
	osDelay(debounce_time);
	if(touch_detect()){
		int32_t x_val = read_ch_x();
		int32_t y_val = read_ch_y();
 
		if(touch_detect()){
			x=x_val;
			y=y_val;
 
			return true;
		}else return false;
	}
 
    return false;
}

5 REPLIES 5
Martin KJELDSEN
Chief III

Hi,

I talked to someone else here a while ago who had similar issues. So, there may be something wrong. I can tell you that nothing has changed in the math for the calibration matrix in years. I think we may have to investigate this issue at our end. The guy ended up implementing his own routines. If it seems like you can just offset y by 160 maybe just do that for now while i investigate this. I have a few resistive displays lying around.

/Martin

JLakn
Associate II

Hi @Martin KJELDSEN​ ,

Thanks for quick reply. Please let me know when you have any new information on this. For now I will just do as you said and continue with project.

Martin KJELDSEN
Chief III

Great, @Community member​,

Thanks for the feedback. Very helpful.

/Martin

JLakn
Associate II

@Martin KJELDSEN​ 

I used touch calibration routine by Carlos E. Vidales (source attached) and it's working like charm. As I seen in touchgfx source TouchCalibration.cpp (posted in link) Carlos E. Vidales routines with modifications are used. Perhaps there is some bug in modifications. Hope this helps in investigating this problem.

Martin KJELDSEN
Chief III

I think Carlos was the one i was thinking about. Thanks for reminding me!

/Martin