Touch_4Wire library not yet ported for Photon

@wesner0019, I’ve just moved your posts over to this new thread, to keep the original on topic :wink:

Discussion concerning this library https://github.com/ScruffR/touch_4wire

1 Like

Just glad it compiled so i can perform some testing with my custom 2.2 touch screens and photon while this is being settled.

updated the code to be to compile both for the core and photon:
.h file

#if  (PLATFORM_ID) == 6
#define pinLO(_pin) (PIN_MAP[_pin].gpio_peripheral->BSRRH = PIN_MAP[_pin].gpio_pin)
#define pinHI(_pin) (PIN_MAP[_pin].gpio_peripheral->BSRRL = PIN_MAP[_pin].gpio_pin)
#else
#define pinLO(_pin)    (PIN_MAP[_pin].gpio_peripheral->BRR = PIN_MAP[_pin].gpio_pin)
#define pinHI(_pin)    (PIN_MAP[_pin].gpio_peripheral->BSRR = PIN_MAP[_pin].gpio_pin)
#endif

.cpp file

#if  (PLATFORM_ID) == 6
STM32_Pin_Info* PIN_MAP = HAL_Pin_Map(); // Pointer required for highest access speed
#endif
2 Likes

@ScruffR, can you verify that the touch_4wire is working with the photon. I’ve updated my code with peekay’s macros. everything compiled I flashed to a photon but nothing is registering, I’m using the coolterm to serial print the readings.
FYI, i used the same macros for the ili9341 library and that is working.

I’m using the following for the touch pins.

#define YP A0  // must be an analog pin, use "An" notation!
#define XM A1  // must be an analog pin, use "An" notation!
#define YM D0  // can be a digital pin
#define XP D1  // can be a digital pin

Think I found whats going on
all these need to be

#if  (PLATFORM_ID) == 6
code

not

#if defined (SPARK)
 code

That didn’t work either, still no touch response.

Unfortunately I haven’t got any of my Photons yet, so I can’t verify if any of my corrections do work and thus I’d rather not upload an unverified update.
But as soon I have got my devices in hand, I’ll check all my libraries (only three fortunately ;-)) whether they work on the Photon with 0.4.0 and the Core with 0.3.4 and 0.4.0 (as soon it’s finalized).

Sorry for not being able to help any more for now.

2 Likes

@ScruffR I just noticed that 1 axis is working just not the other axis or pressure. : :weary:

When below: the X axis works short screen direction.

#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

When below: the Y axis works long direction.

#define YP A0  // must be an analog pin, use "An" notation!
#define XM A1  // must be an analog pin, use "An" notation!
#define YM D0  // can be a digital pin
#define XP D1  // can be a digital pin

So this at least verifies that both the axis are working ( no shorts, bad connections, etc).

I’ve also tried changing the D1 and A1 pins to other pins, but I get the same response. So this seems to be code related some how.

Have you checked that your pins actually do work, especially the analog pins?
For pressure, have you measured the resistance of the touch sensor and calibrated the lib for your device?


Edit: Just seen your updated post :blush:

@ScruffR, I also measured the resistance. It came in around 326 ohm.

Just to confirm some things

Could you try the designated functions for each axis seperately and notch up the #define XY_TOLERANCE 15 - e.g 1024 :wink:

  uint16_t pressure(void);
  int readTouchY();
  int readTouchX();

Something like this?

void loop(void) {
  TSPoint p = ts.getPoint();
  int rawX = ts.readTouchX();
  int rawY = ts.readTouchY();
  
  Serial.print("raw X = "); Serial.print(rawX);
  Serial.print("\traw Y = "); Serial.println(rawY);

  //if(p.z > ts.pressureThreshhold){
     Serial.print("X = "); Serial.print(p.x);
     Serial.print("\tY = "); Serial.print(p.y);
     Serial.print("\tPressure = "); Serial.println(p.z);
 // }

  delay(100);
}
1 Like

So interesting discovery. Its working now after I added below in the loop:

 int rawY = ts.readTouchY();

seems like in the code that ts.readTouchY(); is not getting called properly somehow

#include "Touch_4Wire.h"

#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


TouchScreen ts = TouchScreen(XP, YP, XM, YM, 326);

void setup(void) {
  Serial.begin(9600);
  delay(5000);
  Serial.println("Ready");
}

void loop(void) {
  TSPoint p = ts.getPoint();
  //int rawX = ts.readTouchX();
  int rawY = ts.readTouchY();
  
  //Serial.print("raw X = "); Serial.print(rawX);
  //Serial.print("\traw Y = "); Serial.println(rawY);

  if(p.z > ts.pressureThreshhold){
     Serial.print("X = "); Serial.print(p.x);
     Serial.print("\tY = "); Serial.print(p.y);
     Serial.print("\tPressure = "); Serial.println(p.z);
 }

  delay(100);
}

Sorry, I don’t quite get it.

So if you only add the ts.readTouchY() line after ts.getPoint() the point p gets read correctly???

That’s most obscure, and I have no explanation for it :confused:

You have not changed XY_TOLERANCE at all?

Could you try calling ts.readTouchY() only once in setup() - I do recall that getPoint() does not always set all states explicitly, relying on the state being unchanged while running inside the function - but dirty interrupts or something in the background might interfere with this assumtion.

@ScruffR

"So if you only add the ts.readTouchY() line after ts.getPoint() the point p gets read correctly???"
Yeah it works when this happens. I also moved this read into just the setup and the touch doesn’t work.

I have the touch tolerance set to 20 from 15.

@wesner0019, did you post your ported library somewhere? I would need to see it to understand what might be going on. :smiley:

1 Like

@peekay123, posted in git

1 Like

@wesner0019, @mdma suggested that “static” be added to the STM32_Pin_Info* ... definition to keep it restricted to the specific scope. So, static STM32_Pin_Info* ...

Ok, I think I found the issue. The way pull-ups are enabled on the Arduino is NOT the way it works on the Core/Photon.

So this code will NOT work:

  pinMode(_ym, INPUT);

  // ScruffR: I guess this should detach PULL_UPs

  // ScruffR: Since Spark Core has no PULL UPs with INPUT - not needed
  pinSetLow(_yp);
  pinSetLow(_ym);

If you don’t want any pull-ups on Core/Photon then just using pinMode(pin, INPUT) will do that. So the pinSetLow() calls are not usefull and should be removed.

OMG, there is code everywhere which sets a pin as an input then writes low to it then reads it as an analog input. I really don’t know what the implications of this are on the GPIO but this may be part of the problem. The library very much is based on Arduino GPIO behavior which will not work on the STM32. I’ll investigate. :smile:

@peekay123, That’s what I said too. lots of high low writes all over!

Huge thanks for looking into this!

@wesner0019 & @peekay123, as far as I’m aware I did have that corrected in my own port for the Core, hence the comments :wink:

But since all the original Arduino code was stripped the comments don’t match up with what you’re seeing in the code :sunglasses:

All that setting HIGH and LOW is required to apply the voltage across the respective resistor plates and the analofRead() on the other coordinates pin should measure the voltage on the touching point.

@wesner0019, maybe you have to go back to my original code and recreate what was stripped a bit too much :wink:


I never thought to ask how much you actually altered the original, that would have saved a lot of time for both of us.

@ScruffR, @wesner0019, I may have this code already ported somewhere. Stay tuned.

1 Like

@ScruffR, @peekay123, I also tried the code pulled directly from the Particle Web library for this and only modified the STM32 definitions.

I got the same behavior as above.

the git repository has been updated