Skip to content

on ILI9341 more pressure results in higher z values #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rtwfroody opened this issue Jan 18, 2023 · 3 comments
Closed

on ILI9341 more pressure results in higher z values #22

rtwfroody opened this issue Jan 18, 2023 · 3 comments

Comments

@rtwfroody
Copy link
Contributor

I have https://www.adafruit.com/product/2478, and the only way I can get it to work is with the following diff:

diff --git a/adafruit_touchscreen.py b/adafruit_touchscreen.py
index 5bf0fe0..4f28761 100644
--- a/adafruit_touchscreen.py
+++ b/adafruit_touchscreen.py
@@ -136,7 +136,7 @@ class Touchscreen:
                 with AnalogIn(self._yp_pin) as y_p:
                     z_2 = y_p.value
         # print(z_1, z_2)
-        z = 65535 - (z_2 - z_1)
+        z = z_2 + z_1
         if z > self._zthresh:
             with DigitalInOut(self._yp_pin) as y_p:

and a threshold value of around 40000.
Without this diff, the bottom right of the screen never registers a press.

I don't know much about these kinds of screens. Presumably this code works for other screens. Do some screens reverse this? I triple checked my wires and I don't think I wired anything backwards.

I also had to reverse the X calibration to make the coordinates correspond to the ones used when drawing on the screen:

                calibration=([59889, 12545], [16373, 61473]),
@FoamyGuy
Copy link
Contributor

I do know this does work on some screens I've used it mainly with built-in displays on PyPortals. I'm not sure about whether any screens reverse the values like you mentioned.

It is fairly typical to need to change the calibration values though, the defaults tend to work okay for me as long as I don't need precise accuracy with the touch point. But if I get them dialed in the accuracy goes way up and it can register touches on relatively small screen regions successfully.

There is a script in the examples folder that can help find calibration values for your particular screen: https://github.com/adafruit/Adafruit_CircuitPython_Touchscreen/blob/main/examples/touchscreen_calibrator_built_in.py

@rtwfroody
Copy link
Contributor Author

I've made #23 to support both the existing behavior, and the behavior that's required for ILI9341.

@FoamyGuy
Copy link
Contributor

resolved by #23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants