Hey everyone,
so I’ve been experimenting with the Adafruit HX8357 with my Photon, I have been successful in getting the display to work, however I cannot get the touchscreen to respond whatsoever (nothing happens on screen when I touch it and nothing appears in serial). Looking into the library (I use the online IDE as the local one causes a whole range of problems) it appears it was coded for the Spark with a bunch of #if defines pertaining to that device (mainly in the TOUCH_4WIRE library).
I believe this is why the code will not work with the photon, is there any way to have this updated?
Cheers.
I’ll have to check. When I last used that lib I had it working on Photons too (hence the compatibility note in the lib description ;-))
Are you using the BreakoutTouchPaint sample with the same pin assignment as in the code?
What errors do you get on local build?
I appreciate the prompt response!
Regarding the local build, I don’t have any issues specifically with the library, but rather Particle Dev/Atom complaining about various plugins not working.
I am using the BreakoutTouchPaint example. I have redefined the pinouts to the following (I am using software SPI since I am using SPI3 pins):
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A3 // must be an analog pin, use "An" notation!
#define YM D1 // can be a digital pin
#define XP D0 // can be a digital pin
#define TFT_RST A0
#define TFT_DC A1
#define TFT_CS D5
#define TFT_MISO D3
#define TFT_MOSI D2
#define TFT_SCLK D4
I also just tried running it with exactly the same pins as the BreakTouchPaint example to no avail. I have also experimented with various resistances for the display (I don’t have a multimeter on me however I have tried 0,285,300,500 and 1000 ohms).
I’ve just tested with HW SPI and pinout as outlined in the demo and it worked right away.
Next I’ll try your pins for soft SPI. Can you also post the constructor call for the display you are using?
I just physically copied the BreakTouchPaint example and changed my pins to match it. The display is showing the images fine. The touchscreen part just seems to not work. Is there any other calibration required to get the touchscreen working? I used various resistance values in the constructor call for the TouchScreen function as mentioned above.
Therefore it is:
// These are the four touchscreen analog pins
#define YP A1 // must be an analog pin, use "An" notation!
#define XM A0 // must be an analog pin, use "An" notation!
#define YM D1 // can be a digital pin
#define XP D0 // can be a digital pin
// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 500
#define TS_MINY 300
#define TS_MAXX 3650
#define TS_MAXY 3650
#define MINPRESSURE 5
#define MAXPRESSURE 4000
// The display uses hardware SPI, plus A6 & A7
#define TFT_RST -1 // dont use a reset pin, tie to arduino RST if you like
#define TFT_DC A7
#define TFT_CS A6
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 285 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 0); // 285);
Nope, nothing else required.
Maybe change #undef DEBUG
to #define DEBUG
(to get serial output) and double check your wiring.
The library definetly works.
Other possible reasons might be that one of your Photon pins are dead or the touch screen is faulty or you’ve go a bad contact.
Checking all these circumstances might be good.
Also being a resistive touch you’d need to apply slightly more pressure then on capacitive touch screens.
Maybe shooting close-up pics of your wiring might help us see something too.
So I have changed pins on the photon to eliminate that being a possible cause, in the Debug serial output I am finding that the pressure always equals -1, no matter what I try I cannot get it to work. I had to comment out the following to get it to always print the pressure.
if (z < MINPRESSURE || z > MAXPRESSURE) {
return;
}
It seems that maybe in Touch_4Wire.cpp the following statement seems to be executing as evidenced by the serial debugging output:
if (!valid) {
z = -1;
}
Is there a chance your photon is running older firmware or the online version of the driver is different to the local one you are using (I am assuming you’re using a local version of the touchscreen driver)?
To top it off, I plugged it into an Arduino Nano and using the Adafruit supplied drivers everything worked first go.
Nope, I'm on 0.5.2 & 0.5.3-rc.1 and am using the version published in Build.
This is really starting to baffle me. What libraries have you included with your project?
I have included:
ADAFRUIT_MFGFX
ADAFRUIT_HX8357
TOUCH_4WIRE
Cheers, I appreciate your help.
Exactly those
You could try setting the min/max boundaries to 0/4095 instead of 300/3650 & 500/3650.
There is one line TSPoint TouchScreen::getPoint(void)
if (abs(samples[0] - samples[1]) > XY_TOLERANCE) { valid = 0; }
Which renders the samples invalid. You’d need to find out why.
Maybe by changing #define XY_TOLERANCE 15
to a bigger value foe the time being.
You could also add some extra Serial.print()
statements to give you some raw data feedback.