I tried for lots to get ili9341 touch to work and eventually it worked using software spi.
I tried the demo from latest test gcb and it works with hspi on a few same displays.
The line #define XPT2046_ReadSamples 15 "seems" new but it works well!!
It has to be set to GLCDRotate Portrait for the touch x,y to match the screen
although the code looks like it's supposed to take care of that.
I am happy this is finally working.
This is the demo I used
I had to swap these lines for it to work ie wireing.
#define XPT2046_DI DIGITAL_12 ' Data in | MISO
#define XPT2046_DO DIGITAL_11 ' Data out | MOSI
Evan, here is a problem
Using a device with 3.3V logic output and 5V logic input..then is ili9341 cs-touch line need pulling up?
via 5V voltage divider to raise 3.3V to 5V logic.
the XPT2046 demo display works but not the touch
I tried trello but probably messed up question.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This mega328 demo works very well.
It has the line #define XPT2046_ReadSamples 15 which made the hspi work...did it?
anyway works and accurate.
And a video how good it is https://www.youtube.com/watch?v=WJa3ZFUI43E
new batteries for my camera :)
'''AdemonstrationprogramforGCGBandGCB.'''--------------------------------------------------------------------------------------------------------------------------------'''ThisprogramisasimpleGLCDdemonstrationoftheILI9341GLCDwiththeXPT2046Touchcapabilities.'''ItisanicegraphicalLCD,suitableforalotofvariousprojects.'''ThisprogramshowsthecalibrationofthetouchwiththespecificGLCD.'''TheGLCDisconnectedtothemicroprocessorasshowninthehardwaresectionofthiscode.''':'''ThishasbeentestedusingthehardwareandsoftwareSPIoption.''':'''Note:forthecorrectoperationofthisdisplayyouMUSTconnectviaaCD4050,seehttp://forum.arduino.cc/index.php?topic=181679.90''':'''@author'''@licenceGPL'''@version1.1'''@date'''********************************************************************************'ChipSettings.#chip mega328p, 16#option explicit#include<glcd.h>#include<xpt2046.h>#include<uno_mega328p.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 ' remove/comment out if you want to use software SPI.'Optionally,youcandefinetheHWSPIModebyusing#defineHWSPIModemasterfastwhere#defineHWSPIModeismasterslow|master|masterfast'ThiswilloverwritethedefaultintheGLCDlibrary.Thisissousersdonothavetochangethelibrary.'thedefaultis"masterfast"'Thefollowingexampleiscommentedoutintentionally'#defineHWSPIModemasterfast'******************************************************************************************************'SetuptheXPT2046'TypicalcalibrationrangeforHardwareSPIwhenusingXPT2046'for320*240screeen...maybedifferentforothers#define XPT2046XMIN 15#define XPT2046YMIN 14#define XPT2046XMAX 110#define XPT2046YMAX 113#define XPT2046_ReadSamples 15'TypicalCalibrationrangeforSoftwareSPIwhenusingXPT2046'#defineXPT2046XMIN30'#defineXPT2046YMIN25'#defineXPT2046XMAX210'#defineXPT2046YMAX225#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_HardwareSPI ' remove/comment out if you want to use software SPI - must use same method as GLCD'Optionally,youcandefinetheHWSPIModebyusing#defineHWSPIModemasterfastwhere#defineHWSPIModeismasterslow|master|masterfast'ThiswilloverwritethedefaultintheXPT2046library.Thisissousersdonothavetochangethelibrary.'thedefaultis"masterfast"'Thefollowingexampleiscommentedoutintentionally'#defineHWSPIModemasterfast'Settheinitialcalibration-shownheretoshowthemethod.'Ifyourotatethescreenthenyouwillhavetocallthemethodtoresettheseparameters.SetCalibation_XPT2046(XPT2046XMIN,XPT2046XMAX,XPT2046YMIN,XPT2046YMAX,GLCD_WIDTH,GLCD_HEIGHT)'******************************************************************************************************'MainprogramGLCDRotatePortraitGLCDCLSTFT_NAVYSetCalibation_XPT2046(XPT2046XMIN,XPT2046XMAX,XPT2046YMIN,XPT2046YMAX,GLCD_WIDTH,GLCD_HEIGHT)ScreenLayoutdimXconverge,YconvergeasIntegerdimconvergeCounterasbytedoXconverge=0Yconverge=0convergeCounter=1filledboxCurrent_GLCD_WIDTH,0,Current_GLCD_WIDTH-10,10,TFT_RED'alwayswaitfortoucheventwaitwhileisTouched_XPT2046filledboxCurrent_GLCD_WIDTH,0,Current_GLCD_WIDTH-10,10,TFT_YELLOWdorepeat5'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_XPT2046filledboxCurrent_GLCD_WIDTH,0,Current_GLCD_WIDTH-10,10,TFT_GREENifXTouchPoint_XPT2046>Current_GLCD_WIDTH-59andYTouchPoint_XPT2046>Current_GLCD_HEIGHT-20thenifXTouchPoint_XPT2046<Current_GLCD_WIDTHandYTouchPoint_XPT2046<Current_GLCD_HEIGHTthen'clearScreenLayoutendifelseFilledCircleXTouchPoint_XPT2046,YTouchPoint_XPT2046,3,TFT_LIGHTGREY'ShowtherawdataGLCDPrint(24,56,pad(str(XTouchPoint_XPT2046raw),3))GLCDPrint(24,72,pad(str(YTouchPoint_XPT2046raw),3))GLCDPrint(24,90,pad(str(convergeCounter),3))'Automaticallyadjustthevaluestominandmax'NotneededinarealprogramuseSetCalibation_XPT2046(XPT2046_Xmin,XPT2046_Xmax,XPT2046_Ymin,XPT2046_Ymax)ifXTouchPoint_XPT2046raw<XPT2046_XminthenXPT2046_Xmin=XTouchPoint_XPT2046rawifYTouchPoint_XPT2046raw<XPT2046_YminthenXPT2046_Ymin=YTouchPoint_XPT2046rawifXTouchPoint_XPT2046raw>XPT2046_XmaxthenXPT2046_Xmax=XTouchPoint_XPT2046rawifYTouchPoint_XPT2046raw>XPT2046_YmaxthenXPT2046_Ymax=YTouchPoint_XPT2046raw'showthevaluesGLCDPrint(102,56,pad(str(XPT2046_Xmin),3))GLCDPrint(102,72,pad(str(XPT2046_Ymin),3))GLCDPrint(162,56,pad(str(XPT2046_Xmax),3))GLCDPrint(162,72,pad(str(XPT2046_Ymax),3))GLCDPrint(24,230,pad(str(XTouchPoint_XPT2046),5))GLCDPrint(24,246,pad(str(YTouchPoint_XPT2046),5))'donothammerthetouchwait20msendifloopsubScreenLayout#define GLCD_OLED_FONTGLCDfntDefaultsize=2GLCDFontWidth=5'LayoutthescreenGLCDCLSGLCDPrint(2,3,"XPT2046 demonstration 2019")line0,34,Current_GLCD_WIDTH,34line0,128,Current_GLCD_WIDTH,128line0,220,Current_GLCD_WIDTH,220GLCDPrint(2,25,"Dynamic Calibration")GLCDPrint(22,40,"Raw Min Max")GLCDPrint(2,56,"X:")GLCDPrint(2,72,"Y:")GLCDPrint(2,90,"C:")GLCDPrint(2,122,"Current Calibration")GLCDPrint(2,146,"X:")GLCDPrint(2,162,"Y:")GLCDPrint(102,146,pad(str(XPT2046_Xmin),3))GLCDPrint(102,162,pad(str(XPT2046_Ymin),3))GLCDPrint(162,146,pad(str(XPT2046_Xmax),3))GLCDPrint(162,162,pad(str(XPT2046_Ymax),3))GLCDPrint(2,214,"Scaled")GLCDPrint(2,230,"X:")GLCDPrint(2,246,"Y:")GLCDPrint(120,214,"GLCD Size")GLCDPrint(120,230,"X:"+Str(Current_GLCD_WIDTH))GLCDPrint(120,246,"Y:"+Str(Current_GLCD_HEIGHT))GLCDfntDefaultsize=1GLCDPrint(2,Current_GLCD_HEIGHT-17,"v0.9c")GLCDfntDefaultsize=2filledboxCurrent_GLCD_WIDTH,0,Current_GLCD_WIDTH-10,10,TFT_REDDimoldGLCDBackgroundaswordoldGLCDBackground=GLCDBackgroundGLCDBackground=TFT_WHITEGLCDPrint(Current_GLCD_WIDTH-58,Current_GLCD_HEIGHT-18,"Clear",TFT_BLACK)GLCDBackground=oldGLCDBackground'------VersionControl-optional#include"GCBVersionNumber.cnt"'IncludetheGCBVersionNumber.cnttoincrementversionStringandcreatethebuildtimestringcalledGCBBuildTimeStr.'versionStringastringiscreatedautomatically.'GCBBuildTimeStrisastringthatisalsocreatedautomatically.'use"GCBVersionNumber.cnt"asthiswillcreatealocalcopyoftheversionStringtracker.'ifyouuse<GCBVersionNumber.cnt>thisisasystemwideversionStringtracker.dimversionStringasstring*40versionString="Build: "+GCBBuildStrversionString=versionString+"@"+GCBBuildTimeStrGLCDfntDefaultsize=1GLCDPrint(2,Current_GLCD_HEIGHT-10,versionString)GLCDfntDefaultsize=2'------EndofVersionControl-optionalEndSub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The code looks complicated
may be take 4 x,y samples and the difference between top y and bottom y is y centre and same for most x - least x as centre x.
are raw values worth trying to use?
what's GLCDPrint ( 102, 56, pad(str(XPT2046_Xmin),3 ) ) ?
looks new...it's probably in help
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The GLCDPrint is simple a Left padding of spaces to ensure any prior string is erased, as is 999 to 1 with pad this becomes "999" to "1 " {trailing spaces erase the last two chars "99"
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried for lots to get ili9341 touch to work and eventually it worked using software spi.
I tried the demo from latest test gcb and it works with hspi on a few same displays.
The line #define XPT2046_ReadSamples 15 "seems" new but it works well!!
It has to be set to GLCDRotate Portrait for the touch x,y to match the screen
although the code looks like it's supposed to take care of that.
I am happy this is finally working.
This is the demo I used
I had to swap these lines for it to work ie wireing.
Last edit: stan cartwright 2020-10-18
Evan, here is a problem
Using a device with 3.3V logic output and 5V logic input..then is ili9341 cs-touch line need pulling up?
via 5V voltage divider to raise 3.3V to 5V logic.
the XPT2046 demo display works but not the touch
I tried trello but probably messed up question.
If this is LGT related, until we release to the general folks, use Trello
This mega328 demo works very well.
It has the line #define XPT2046_ReadSamples 15 which made the hspi work...did it?
anyway works and accurate.
And a video how good it is https://www.youtube.com/watch?v=WJa3ZFUI43E
new batteries for my camera :)
The code looks complicated
may be take 4 x,y samples and the difference between top y and bottom y is y centre and same for most x - least x as centre x.
are raw values worth trying to use?
what's GLCDPrint ( 102, 56, pad(str(XPT2046_Xmin),3 ) ) ?
looks new...it's probably in help
The GLCDPrint is simple a Left padding of spaces to ensure any prior string is erased, as is 999 to 1 with pad this becomes "999" to "1 " {trailing spaces erase the last two chars "99"