I am using the lgt328 ili9341 touch demo. It's interesting. I stripped it down to a minimum and it just draws circles where you touch the screen. here's the minimum code.
#chip LGT8F328P#option explicit#include<glcd.h>#include<xpt2046.h>#include<LGT8F328P.h >'******************************************************************************************************'SetuptheGLCD#define GLCD_TYPE GLCD_TYPE_ILI9341'PinmappingsforSPI-thisGLCDdriversupportsHardwareSPIandSoftwareSPI#define GLCD_DC DIGITAL_8 ' Data command line#define GLCD_CS DIGITAL_10 ' Chip select line#define GLCD_RESET DIGITAL_9 ' Reset line#define GLCD_DI DIGITAL_12 ' Data in | MISO - Not used therefore not really required#define GLCD_DO DIGITAL_11 ' Data out | MOSI#define GLCD_SCK DIGITAL_13 ' Clock Line#define ILI9341_HARDWARESPI'SetuptheXPT2046'TypicalCalibrationrangeforSoftwareSPIwhenusingXPT2046#define XPT2046XMIN 30#define XPT2046YMIN 25#define XPT2046XMAX 210#define XPT2046YMAX 225#define XPT2046_DI DIGITAL_12 ' Data in | MISO#define XPT2046_DO DIGITAL_11 ' Data out | MOSI#define XPT2046_SCK DIGITAL_13 ' Clock Line#define XPT2046_CS DIGITAL_2 ' Chip select line#define XPT2046_IRQ ANALOG_5#define XPT2046_SOFTWARESPI#define LGT_XPT_HWSPIMODE MASTER 'optionally can be MASTERSLOW'MainprogramGLCDRotatePortraitGLCDCLSTFT_BLUESetCalibation_XPT2046(XPT2046XMIN,XPT2046XMAX,XPT2046YMIN,XPT2046YMAX,GLCD_WIDTH,GLCD_HEIGHT);ScreenLayoutdimXconverge,YconvergeasIntegerdimconvergeCounterasbytedoXconverge=0Yconverge=0convergeCounter=1dorepeat5'getthevalues-GetXY_XPT2046(XTouchPoint_XPT2046,YTouchPoint_XPT2046)endRepeat'testforsettlingbytestingforconverganceifABS((Xconverge-XTouchPoint_XPT2046))>1orABS((Yconverge-YTouchPoint_XPT2046))>1thenXconverge=XTouchPoint_XPT2046Yconverge=YTouchPoint_XPT2046convergeCounter++Else'convergedexitdoendifLoop;FlipthedatatohandleforthescreenrotationYTouchPoint_XPT2046=Current_GLCD_HEIGHT-YTouchPoint_XPT2046FilledCircleXTouchPoint_XPT2046,YTouchPoint_XPT2046,3,TFT_LIGHTGREYloop
I don't understand the code. I can't see what convergeCounter++ is for.
Does YTouchPoint_XPT2046 = Current_GLCD_HEIGHT - YTouchPoint_XPT2046 need to be in the main loop?
It's a good gcb include but how does it work ?
What is
'Typical Calibration range for Software SPI when using XPT2046
#defineXPT2046XMIN30
#defineXPT2046YMIN25
#defineXPT2046XMAX210
#defineXPT2046YMAX225
about please?
I notice an increasing x axis error as you touch screen further right??
The display is 240x320. The x axis error is a problem. I can do a youtube video to show the error.
ps #define GLCD_TYPE GLCD_TYPE_ILI9341 seems new.
Also why TFT_LIGHTGREY instead of ili9341 colours? asked before.
convergeCounter is a method to ensure the pointer is in the same place within 1 returned pixel value
If reads the position of the event 5 times then if the read is with 1 pixel of the last one it exits the do loop - this stops the XPT sensor returning wild results.
It's a good gcb include but how does it work ?
The include is relatively simple.
Setups the ports etc and sets the interrupt
It sends the calibration data to the XPT
Take a load of samples by sending a request for a sample but for the LGT turn off harware SPI prior to request and restore SPI state after the request has completed.
Return an average of the sensor values
What is
'Typical Calibration range for Software SPI when using XPT2046
#defineXPT2046XMIN30
#defineXPT2046YMIN25
#defineXPT2046XMAX210
#defineXPT2046YMAX225
about please?
These are the calibration values. Use the original demo to set the returned values. See https://youtu.be/wN35LwRgOAQ
I notice an increasing x axis error as you touch screen further right??
Recalibrate please.
Also why TFT_LIGHTGREY instead of ili9341 colours? asked before.
TFT_LIGHTGREY is the same value as the ILI9341 constant. I created the ILI9341 constants before I was thinking about just using TFT_color_code_constants
:-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Nice one Anobium. Thinking a 50Hz timer interrupt for getting x,y touched. You mention 20ms before touch the screen.
The x,y is from where the circle is drawn so getting there.
I just want to test an x,y co-ordinate of a screen pressed position but in a program would need a way of getting the screen touched event.
I'm not the brightest crayon in the box so lots of thinking to do.
I got to try the mega328 interrupts with LGT328. TimerCalulator program ?? what to set it? Assume interrupt happen twice as fast??
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using the lgt328 ili9341 touch demo. It's interesting. I stripped it down to a minimum and it just draws circles where you touch the screen. here's the minimum code.
I don't understand the code. I can't see what convergeCounter++ is for.
Does YTouchPoint_XPT2046 = Current_GLCD_HEIGHT - YTouchPoint_XPT2046 need to be in the main loop?
It's a good gcb include but how does it work ?
What is
about please?
I notice an increasing x axis error as you touch screen further right??
The display is 240x320. The x axis error is a problem. I can do a youtube video to show the error.
ps #define GLCD_TYPE GLCD_TYPE_ILI9341 seems new.
Also why TFT_LIGHTGREY instead of ili9341 colours? asked before.
Last edit: stan cartwright 2022-01-17
Stan - how cool!
convergeCounter is a method to ensure the pointer is in the same place within 1 returned pixel value
If reads the position of the event 5 times then if the read is with 1 pixel of the last one it exits the do loop - this stops the XPT sensor returning wild results.
The include is relatively simple.
These are the calibration values. Use the original demo to set the returned values. See https://youtu.be/wN35LwRgOAQ
Recalibrate please.
TFT_LIGHTGREY is the same value as the ILI9341 constant. I created the ILI9341 constants before I was thinking about just using TFT_color_code_constants
:-)
Nice one Anobium. Thinking a 50Hz timer interrupt for getting x,y touched. You mention 20ms before touch the screen.
The x,y is from where the circle is drawn so getting there.
I just want to test an x,y co-ordinate of a screen pressed position but in a program would need a way of getting the screen touched event.
I'm not the brightest crayon in the box so lots of thinking to do.
I got to try the mega328 interrupts with LGT328. TimerCalulator program ?? what to set it? Assume interrupt happen twice as fast??
Check demos https://github.com/Anobium/Great-Cow-BASIC-Demonstration-Sources/tree/master/Interrupt_and_Timer_Solutions
Your video https://www.youtube.com/watch?v=wN35LwRgOAQ explains a lot about the mechanics. Cheers.
@Stan - I spotted some serial debug left in the XPT library. Get the latest patch for that library - the latest has the debug removed. Here is the URL
https://sourceforge.net/projects/gcbasic/files/Release%20Candidates/Patches/gcb%40syn/GreatCowBASIC/include/xpt2046.h/download
Replace the existing in the include folder.