A new Touch library -adds a method to control Touch control when using a Graphics LCD. The library supports the XPT2046 and the ADS7843 Touch sensors.
The video below shows many of the methods including calibration and the key methods/functions.
Very simple to use. Just include the library, define the phyiscal connnections, calibration and then use the one call to get the co-ordination of the Touch event.
I have posted demonstrations to GitHub - adding more Touch demos all the time.
Enjoy,
Please give a thumbs up!!!
👍
1
Last edit: Anobium 2019-01-09
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Brill!
I was confused about
GLCD_DO and XPT2046_DO
GLCD_DI and XPT2046_DI
The demo and video say they're shared but you emailed to say only XPT2046_DI is used.
Is it compatable with GLCD demonstration of the ILI9341 GLCD read pixel capabilities...
which uses GLCD_DI?
Also using a display that uses 3.3V logic with a 5V uno, what level should/can XPT2046_CS and
XPT2046_IRQ be?
#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 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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The SPI communication for Data out, Data in, Clock MUST be shared when you using Hardware SPI.
The SPI communication for Data out, Data in, Clock SHOULD be shared when you using Software SPI
But, you COULD state different Data out, Data in, Clock for the GLCDF and the Touch device if you were totally bonkers (see https://en.oxforddictionaries.com/definition/bonkers ) as this would not make sense.
Regarding operating logic. I have all MCU Output to the GLCD/TOUCH via a voltage leveler. The IRQ input from the Touch I have used directly to the MCU, but, for simplicity I now have that operating via a voltage leveler.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Anobium,
I apologize for this question.
I found the demostrations on GitHub
However I was not able to find the Touch library for the touch part of the ILI9341.
Please can you help?
Many thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Anobium,
I used the GLCD Library on the PIC18F45k42 with the ILI9341 GLCD.
PIC18F45k42 has not default ports for CLK(out), SDO, and SS functions so that I had to define them within the PPS registers.
A little modification of the GCBASIC Library allowed me to enjoy of such library. Fine and beutifull results!
I read the Touch library you recently introduced for the TSC2046 controller installed on my ILI9341 GLCD.
Recently, I did not know your library and I was already attempting to use the Touch part of the ILI9341 without success.
Reading your library convinced me that my code should work.
However it does not work.
I attach a reduced version of the code.
When the touch screen is touched a PIC interrupt is activated on port C.0.
Te interrupt soubroutine provide the touch commands needed to obtain the x and y position of the touched point of the screen.
The results are always zero!
I do not understand why.
The attached code contains also a small (working) part using the graphical part of the GLCD.
I hope you will help me.
Thank you for your attention and your time
Giuseppe
I think, if I may recommend, that you should simply use the XPT touch driver.
Looking at your code you are not using the library?
And, not sure what all the SPI code is doing? SPIMODE does this and this sets up the environment for you.
Can you use the ILI9341 with the Touch library? as this should work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for the answer.
I will use the XPT Library and run one of your demonstrations on Git Hub as soon as possible.
I will send you the results.
Best Regards
Giuseppe
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Anobium,
now I got the "glcd_XPT2046_demonstation_mega328p_for_ili9341@16.gcb" from Git-Hub.
I adapted the code to PIC 18f45K42 and I used the XPT Touch Library to run the demostration.
I had to slightly modify the XPT Touch Library (as well as the GLCD.ILI9341.h) because the SPIMODE MasterFast is not allowed by my PIC. I think this is due to the fact that only the frequencies Fosc/(2+2*baud) are allowed by PIC18F45K42 (baud is a factor to be chosen). Mybe MasterFast spimode attempt to use a different set of frequencies.
As a matter of fact when SPIMODE MasterFast is applied, the code stops and the screen stay white. SPI device seems to freeze.
Deleting MasterFast setting ,the graphic part of the demonstration code works fine until the IsTouched_XPT2046 variable is reset by touching the screen (as it should be).
As expected, after the touch, the little red filled box locted on the angle of the screen first become yellow and then green.
However, the demostration code does not seem to go further.
This is due to the fact that the (x, y) positions of the touched screen points acquired by the routine GetXY_XPT2046 are always zero!
This is exactly the same drawback I experienced with my code (i.e., without using the XPT2046 Library) I sent you few days ago. I.e. the SPI received data were all zero.
Now the question is why reception of data by SPI does not work?
It depends on the SPI settings? I believe that the settings are OK.
It depends on the pin SPI setting? It could be. However I have not found an answer.
It depends on the fact that the PIC18F45K42 use two separate, different couples of buffers for incoming and outcoming data? I do not know what the low level GCB command SpiTransfer does exactly. Accordingly, I'm not able to explore this possibility.
Now I'm stopped on this question: how to get the correct (x,y) coordinates of the points touched on the screen.
Thank you for your attention
Best regards
Giuseppe
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
2. I can use SPI.
I already use SPI within the demostration code "glcd_XPT2046_demonstation_mega328p_for_ili9341@16.gcb". I modified this code to enable the use of the PIC.
3 The graphical section of the ILI9341 works fine with the GLCD Library .I have the last version of the GLCD library that I got together with the last version of the Great Cow Basic.
I have the latest Touch Library according to your recent answer.
Hi Anobium,
thanks for the new include file. I have seen it just now because I lost all yesterday to understand the malfunctioning of my circuit. Without any success.
This morning I attempted the last, unbealivable chance.
The same PIC port was connected both to the T_DIN pin of theTSC2046 and to the SDI pin of the ILI9341 driver. Because the SDI connection to the ILI9341 is not required, I canceled it.
After that the x-y coordinates of the touched point on the screen are not more equal to zero and I can say that the electronic is now working.
The remaining question now concerns the fact that the read coordinates are quite (to much) different than the ones of the touched point.
However, this is a new problem and I will first install your new file.
I will be in touch.
Many thanks for your help.
Giuseppe
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
-As I told you, to allows the use of the PIC18F45k42 I need little change to the library due to the fact that MasterFast does not work (it uses as CLK frequency the Fosc frequency while the PIC allows only frequencies Fosc/(2+2baud) for an arbitrary integer value of baud). And I do not like the slower MasterSlow.
-Concerning SDI, my recent experience is that disconnecting SDI was the solution to my problem. Since it does nothing, it is not a limitation to disable it permanently.
I know that I need a calibration. However this is now the point I want to consider.
The SetCalibration.. routine included in the library is obviously dummy.
Unfortunately my hardware is on a breadboard at the moment and I think that the calibration data provided by the demonstration code are far from the ones appropriate to my hardware.
This is what I want to do now.
Thank you
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Have you tried the new capabilites for you to set the SPI speed? What did you try? Post the adapted .h so I can compare to the master.
Let us resolve that first to get the library sorted and to confirm the library is good. This is in the context that you are the first user to use on a PIC. So, I want to ensure the library is robust first.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I found some problem also with the demonstration code glcd_XPT2046_demonstation_mega328p_for_ili9341@16.gcb
wherein due to the instruction
define XPT2046_IRQ ANALOG_5
I assumed that the IRQ pin should be analog.
However, within PIC18F45K42 when a pin is defined analog, the corresponding port will receive always zero. Accordingly, after a long search I had to not declare analog the corresponding input, i.e., I set equal to zero the corresponding ANSEL bit.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm sorry, I do not know how I can ping you. Mybe by e-mail. I have not yours.
My E-mail is g.deliaATunina.it.
At the moment I'm not able to compile with the include file you sent because the compiler says that there is not a BIT subroutine.
However, looking within Great Cow Basic manual (page 562) it shoul find such a function.
Last edit: Anobium 2019-03-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A new Touch library -adds a method to control Touch control when using a Graphics LCD. The library supports the XPT2046 and the ADS7843 Touch sensors.
The video below shows many of the methods including calibration and the key methods/functions.
Very simple to use. Just include the library, define the phyiscal connnections, calibration and then use the one call to get the co-ordination of the Touch event.
I have posted demonstrations to GitHub - adding more Touch demos all the time.
Enjoy,
Please give a thumbs up!!!
Last edit: Anobium 2019-01-09
Brill!
I was confused about
GLCD_DO and XPT2046_DO
GLCD_DI and XPT2046_DI
The demo and video say they're shared but you emailed to say only XPT2046_DI is used.
Is it compatable with GLCD demonstration of the ILI9341 GLCD read pixel capabilities...
which uses GLCD_DI?
Also using a display that uses 3.3V logic with a 5V uno, what level should/can XPT2046_CS and
XPT2046_IRQ be?
The SPI communication for Data out, Data in, Clock MUST be shared when you using Hardware SPI.
The SPI communication for Data out, Data in, Clock SHOULD be shared when you using Software SPI
But, you COULD state different Data out, Data in, Clock for the GLCDF and the Touch device if you were totally bonkers (see https://en.oxforddictionaries.com/definition/bonkers ) as this would not make sense.
Regarding operating logic. I have all MCU Output to the GLCD/TOUCH via a voltage leveler. The IRQ input from the Touch I have used directly to the MCU, but, for simplicity I now have that operating via a voltage leveler.
Hi Anobium,
I apologize for this question.
I found the demostrations on GitHub
However I was not able to find the Touch library for the touch part of the ILI9341.
Please can you help?
Many thanks
You really MUST download ALL the latest GLCD libraries and this (Touch) library from https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include
Last edit: Anobium 2019-03-18
I got it.
Thank you
Hi Anobium,
I used the GLCD Library on the PIC18F45k42 with the ILI9341 GLCD.
PIC18F45k42 has not default ports for CLK(out), SDO, and SS functions so that I had to define them within the PPS registers.
A little modification of the GCBASIC Library allowed me to enjoy of such library. Fine and beutifull results!
I read the Touch library you recently introduced for the TSC2046 controller installed on my ILI9341 GLCD.
Recently, I did not know your library and I was already attempting to use the Touch part of the ILI9341 without success.
Reading your library convinced me that my code should work.
However it does not work.
I attach a reduced version of the code.
When the touch screen is touched a PIC interrupt is activated on port C.0.
Te interrupt soubroutine provide the touch commands needed to obtain the x and y position of the touched point of the screen.
The results are always zero!
I do not understand why.
The attached code contains also a small (working) part using the graphical part of the GLCD.
I hope you will help me.
Thank you for your attention and your time
Giuseppe
I think, if I may recommend, that you should simply use the XPT touch driver.
Looking at your code you are not using the library?
And, not sure what all the SPI code is doing? SPIMODE does this and this sets up the environment for you.
Can you use the ILI9341 with the Touch library? as this should work.
Thank you for the answer.
I will use the XPT Library and run one of your demonstrations on Git Hub as soon as possible.
I will send you the results.
Best Regards
Giuseppe
Hi Anobium,
now I got the "glcd_XPT2046_demonstation_mega328p_for_ili9341@16.gcb" from Git-Hub.
I adapted the code to PIC 18f45K42 and I used the XPT Touch Library to run the demostration.
I had to slightly modify the XPT Touch Library (as well as the GLCD.ILI9341.h) because the SPIMODE MasterFast is not allowed by my PIC. I think this is due to the fact that only the frequencies Fosc/(2+2*baud) are allowed by PIC18F45K42 (baud is a factor to be chosen). Mybe MasterFast spimode attempt to use a different set of frequencies.
As a matter of fact when SPIMODE MasterFast is applied, the code stops and the screen stay white. SPI device seems to freeze.
Deleting MasterFast setting ,the graphic part of the demonstration code works fine until the IsTouched_XPT2046 variable is reset by touching the screen (as it should be).
As expected, after the touch, the little red filled box locted on the angle of the screen first become yellow and then green.
However, the demostration code does not seem to go further.
This is due to the fact that the (x, y) positions of the touched screen points acquired by the routine GetXY_XPT2046 are always zero!
This is exactly the same drawback I experienced with my code (i.e., without using the XPT2046 Library) I sent you few days ago. I.e. the SPI received data were all zero.
Now the question is why reception of data by SPI does not work?
It depends on the SPI settings? I believe that the settings are OK.
It depends on the pin SPI setting? It could be. However I have not found an answer.
It depends on the fact that the PIC18F45K42 use two separate, different couples of buffers for incoming and outcoming data? I do not know what the low level GCB command SpiTransfer does exactly. Accordingly, I'm not able to explore this possibility.
Now I'm stopped on this question: how to get the correct (x,y) coordinates of the points touched on the screen.
Thank you for your attention
Best regards
Giuseppe
Let us start with first principles.
Let us sort the basics out and then we can get you on a standard library (hopefully).
#define HWSPIMode MasterSlow
Last edit: Anobium 2019-03-23
1. The PIC is 18F45k42
2. I can use SPI.
I already use SPI within the demostration code "glcd_XPT2046_demonstation_mega328p_for_ili9341@16.gcb". I modified this code to enable the use of the PIC.
3 The graphical section of the ILI9341 works fine with the GLCD Library .I have the last version of the GLCD library that I got together with the last version of the Great Cow Basic.
I have the latest Touch Library according to your recent answer.
4The http://gcbasic.sourceforge.net/help/ili9341controllers.html give an error. I used #define HWSPIMode MasterSlow with the same results: the (x, y) coordinates are always zero
Giuseppe
**
Ok. You need the latest library. See attached - replace the existing libraries these are the libraries from the up coming release.
I have put the release_List.txt in the ZIP.
Hi Anobium,
thanks for the new include file. I have seen it just now because I lost all yesterday to understand the malfunctioning of my circuit. Without any success.
This morning I attempted the last, unbealivable chance.
The same PIC port was connected both to the T_DIN pin of theTSC2046 and to the SDI pin of the ILI9341 driver. Because the SDI connection to the ILI9341 is not required, I canceled it.
After that the x-y coordinates of the touched point on the screen are not more equal to zero and I can say that the electronic is now working.
The remaining question now concerns the fact that the read coordinates are quite (to much) different than the ones of the touched point.
However, this is a new problem and I will first install your new file.
I will be in touch.
Many thanks for your help.
Giuseppe
The library should work.
Should we adapt (permanently, for other in the future) to disable SDI?
So, the library is working? For the GLCD and the Touch but the results of the XY are not full range.
Then, you need to calibrate - so, your hardware out and we can work out the calibration.
-As I told you, to allows the use of the PIC18F45k42 I need little change to the library due to the fact that MasterFast does not work (it uses as CLK frequency the Fosc frequency while the PIC allows only frequencies Fosc/(2+2baud) for an arbitrary integer value of baud). And I do not like the slower MasterSlow.
-Concerning SDI, my recent experience is that disconnecting SDI was the solution to my problem. Since it does nothing, it is not a limitation to disable it permanently.
The SetCalibration.. routine included in the library is obviously dummy.
Unfortunately my hardware is on a breadboard at the moment and I think that the calibration data provided by the demonstration code are far from the ones appropriate to my hardware.
This is what I want to do now.
Thank you
Have you tried the new capabilites for you to set the SPI speed? What did you try? Post the adapted .h so I can compare to the master.
Let us resolve that first to get the library sorted and to confirm the library is good. This is in the context that you are the first user to use on a PIC. So, I want to ensure the library is robust first.
Ok, I will do it.
I found some problem also with the demonstration code glcd_XPT2046_demonstation_mega328p_for_ili9341@16.gcb
wherein due to the instruction
define XPT2046_IRQ ANALOG_5
I assumed that the IRQ pin should be analog.
However, within PIC18F45K42 when a pin is defined analog, the corresponding port will receive always zero. Accordingly, after a long search I had to not declare analog the corresponding input, i.e., I set equal to zero the corresponding ANSEL bit.
Ping me a personal message or email me.
We may have a more serious issue with the K42 section of the compiler.
So, ping me for an offline conversation please,
I'm sorry, I do not know how I can ping you. Mybe by e-mail. I have not yours.
My E-mail is g.deliaATunina.it.
At the moment I'm not able to compile with the include file you sent because the compiler says that there is not a BIT subroutine.
However, looking within Great Cow Basic manual (page 562) it shoul find such a function.
Last edit: Anobium 2019-03-25