I’m doing some experiments with an Adafruit 2.8" TFT display with a resistive touch screen. (https://learn.adafruit.com/adafruit-2-8-tft-touch-shield-v2/overview).
Therefore, I’ve ported successfully the Adafruit STMPE610 resistive touch screen controller library and put it into GitHub (MaxSharx/Adafruit_STMPE610) to use it in my code. Example runs very well, but the “TouchPaint” demo by adafruit makes trouble.
At the beginning TouchPaint runs well and I was able to draw some pictures but after a while it has broken. The display seems to use SPI_CLOCK_DIV2 and SPI_MODE0 but the Adafruit_STMPE610 only runs with SPI_MODE1 now. The fascinating issue is that at the beginning the Adafruit_STMPE610 runs successfully with SPI_MODE0. The library first tests if SPI_MODE0 is ok and switches to SPI_MODE1 if any errors occurs (tested by getVersion and reading register 0).
I’m very confused about how to get this display together with its touch screen working because of the needed different settings. Separately they are working. Every hint or help is appreciated. Thanks in advance!
@MaxSharx, SPI becomes quite a pain when using mixed data-mode devices. The same issue comes up when using Digole displays in SPI mode coupled with an SD card. Switching data modes causes SPI bus glitching so that has shown not to be a viable solution. What HAS worked is to use the slow device (in you case, the touch screen) via software SPI and the other device using hardware SPI. This is because SPI on the Core (based on the Arduino model) is a blocking call and returns only once an entire byte is transferred.
It is possible to use the same SPI hardware pins (different CS lines of course) and making sure the SCLK line is set to the correct state (between MODE1 and MODE0)when the software SPI transaction is complete.
@MaxSharx, both libraries set the SPI configuration. I suspect that with a DIV2 clock, the STMPE610 sometimes works and sometime not causing it to switch to MODE 1. The device spec shows a max SPI clock of 1MHz or DIV64 or perhaps DIV32 at best.
You can change the SPI clock speed in the STMPE610 library before each transaction OR you use both the display and touch panel at the slower clock rate. Using the software SPI approach may give you the best of both worlds.
The STMPE610 library has a software SPI mode and you could map the same pins as the hardware SPI for the LCD (different CS lines). Since the software SPI will slow things down and use MODE 0 clock settings, everything should work just fine.
@peekay123, thanks for your quick answer. The 1MHz restriction was the reason of choosing SPI_CLOCK_DIV64 for the touch and because of the different settings I’ve tried to explicitly reset the setting in my STMPE610 port but without any success. Actually, I try to use software SPI.
OK, I’ve tried out software SPI and experienced no problems using the touch screen alone.
But, in combination with the display it doesn’t work. The display seems to block any communication.
Thus, the “TouchPaint” demo starts but doesn’t react on any input even though the initialization of the touch screen was successful. Software SPI uses shiftOut / shiftIn but setting the clock pin to low shows no effect either.
BUT: After reverting back to hardware SPI magically the demo runs fine! That’s a really very weird behavior. I won’t change anything and I guess it won’t work tomorrow.
@MaxSharx, you’re freaking me out here but I am glad things are working!
@MaxSharx @peekay123 Where can I find the example code used for my Photon and TFT touch shied 2.8" version 2?
I think I found the link. But, when I run your code I get a error. “Adafruit_STMPE610/Adafruit_STMPE610.h: No such file or directory” How would you or how did you fix this error? I really just need to run this example code to see if my wiring on my photon to TFT touch shield is correct or not.
@Question, do you have a link to the library?
I using the particle dev software.
@Question, I assume you put all the code (the example ino and all libraries files) in the same directory. If that’s the case then change the line in TouchTest.ino:
The path is necessary when using the web IDE but not when using Particle Dev.
So, if I’m using the Particle dev (which I am), I shouldn’t be able to have that error. Also, I know this is stupid but how do you include libraries into the particle dev?
Of course you should be able to get that error. The path provided for the .h file was incorrect!
Just to be clear, when you say “Particle Dev”, you are referring to the locally installed tool, not the web-based IDE, correct?
Using Particle Dev, a library is included by copying its files (.cpp and .h file) into the same directory as the user app .ino file. In the near future, you will be able to refer to libraries without having to copy any files (like arduino).
@peekay123 I solved the code issue and it works now. But, I figured out my wiring was incorrect for my Photon to my TFT touch shield. Do you know the pinout in which I can connect my Photon and TFT touch shield, making my TFT touch shield have touch screen and displaying the example code? Thanks!
@Question, how do you have the two devices connected to the Photon now? Since both are SPI devices, you will need to make sure they share the MOSI/MISO/SCK pins but have separate CS pins. Note in TouchTest.ino that the touch panel CS is set to D5.
But my pinout was only possible with only display and not touchscreen.
@Question, that’s great, however I can’t really tell what the wiring is! Perhaps you can list out what photon pin connects to which display/panel pin?
This was my display pinout. Display Pinout
Photon TFT touch shield
D5 Reset pin
How would I change it so that I can also have touch screen. All I know is that when I flash the code to the photon the screen turns back white.