Adafruit is open and shipping! Let's build back better, together!
0

Resistive Touchscreen on Prod 1770 not returning values
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Resistive Touchscreen on Prod 1770 not returning values

by adafruit_support_carter on Mon Nov 09, 2020 12:51 pm

CircuitPython doesn't have interrupt support. So, yep, you'll need to use something like RPi.GPIO for that.

adafruit_support_carter
 
Posts: 17777
Joined: Tue Nov 29, 2016 2:45 pm

Re: Resistive Touchscreen on Prod 1770 not returning values

by destockwell on Tue Nov 10, 2020 12:26 am

I now recognize that CircuitPython does not provide Interrupt support. But, how about the STMPE610 module itself?

I am trying to trap a "touch detect" interrupt using RPi.GPIO functionality, but see that even when I touch the touch screen, the STMPE610 module never raises INT (terminal 3 across the bottom of the STMPE610. Am trying to read the interrupt line in a simple loop using GPIO.input(channel#), but never see the line rise or fall.

Simple code sample:

import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

GPIO.setup(26, GPIO.IN)
while True:
print(GPIO.input(26))
time.sleep(1)


I have also tried GPIO.setup with pull_up_down parameter but then the value printed is set to the pull-up/down setting. How can I get an interrupt off the STMPE?

destockwell
 
Posts: 18
Joined: Sun Sep 06, 2020 6:37 pm

Re: Resistive Touchscreen on Prod 1770 not returning values

by adafruit_support_carter on Tue Nov 10, 2020 12:17 pm

You need to also enable it on the STMPE610. Your code is only setting up GPIO pins and is doing nothing to actually initialize the STMPE610.

It looks like the CircuitPython driver enables touch detect interrupt by default:
https://github.com/adafruit/Adafruit_Ci ... 10.py#L144
So should be able to simply import and create a STMPE610 instance. Then do the above for setting up the GPIO pin attached to the STMPE610 interrupt.

adafruit_support_carter
 
Posts: 17777
Joined: Tue Nov 29, 2016 2:45 pm

Re: Resistive Touchscreen on Prod 1770 not returning values

by destockwell on Tue Nov 10, 2020 5:42 pm

Thanks for your info. Very helpful.

Now, I have continued to work through issues with the STMPE610 and its timing (and maybe the Circuitfruit driver/library.

* I find that when the IRQ is raised, touch data does not arrive in the buffer for another 10 msec. So, when I check buffer_empty immediately after receiving the interrupt, the buffer is ALWAYS empty. I fix this with a brief loop, during which the IRQ stays high and buffer_empty ultimately goes low, at which time I can then access/print the contents of the array of touches.

* When accessing and displaying the array of touches (actually, a "dict" structure), if I pull off one entry at a time until empty (the get_point property), then at the end, the IRQ drops to zero, as I might expect. However, if I access these using the touches property, giving me all-at-once, the IRQ never is reset, never drops back to zero.

Will upload code and outputs (and maybe a photo) in a subsequent reply...getting them off a Pi-0W is a little tricky in currently limited in-house infrastructure.

destockwell
 
Posts: 18
Joined: Sun Sep 06, 2020 6:37 pm

Re: Resistive Touchscreen on Prod 1770 not returning values

by destockwell on Tue Nov 10, 2020 11:55 pm

Code. as promised:

Code: Select all | TOGGLE FULL SIZE
import board
import digitalio
import time

from adafruit_stmpe610 import Adafruit_STMPE610_SPI as stmpe_spi
touch = stmpe_spi(board.SPI(), digitalio.DigitalInOut(board.CE1))

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

GPIO.setup(26, GPIO.UP, pull_up_down = GPIO.PUD_DOWN)

print('Before wait_for_edge, irq line is %s' % GPIO.input(26))
GPIO.wait_for_edge(26, GPIO.RISING, timeout=10000)
print('After wait_for_edge, irq line is %s' % GPIO.input(26))

if touch.touched :
    t_st = time.time()
    while touch.buffer_empty :
        t_end = time.time()
    t_total = t_end - t_st
    print('Waited %5.3f sec for touch data' % t_total)

    if not touch.buffer_empty :
        print('irq line is now %s' % GPIO.input(26))
        while not touch.buffer_empty :
            print(touch.get_point)
#       print(touch.touches)
        print('irq line is now %s' % GPIO.input(26))

        if GPIO.input(26) != 0 :
            t_st = time.time()
            while GPIO.input(26) > 0:
                t_end = time.time()
            t_total = t_end - t_st
            print('Waited %5.3f sec for IRQ to drop' % t_total)
    else :
        print(Touched, but no touches!')
else :
    print('No touches')

Line commented out is a substitution for the previous two lines. However, when print(touch.touches) is executed, the interrupt (on line 26) never clears.

When print(touch.get_point) is used, the interrupt always clears.
Last edited by adafruit_support_carter on Wed Nov 11, 2020 2:24 pm, edited 1 time in total.
Reason: added [coide] tags

destockwell
 
Posts: 18
Joined: Sun Sep 06, 2020 6:37 pm

Re: Resistive Touchscreen on Prod 1770 not returning values

by destockwell on Wed Nov 11, 2020 12:45 pm

First case, using print(touch.touches)

Before wait_for_edge, irq line is:0
After wait_for_edge, irq line is:1
Waited 0.015 sec for touch data
irq line is now 1
[{'x': 764, 'y': 1076, 'pressure': 65}, {'x': 747, 'y': 1055, 'pressure': 63}, {'x': 808, 'y': 1037, 'pressure': 66}, {'x': 1012, 'y': 1017, 'pressure': 66}]
irq line is now 1

Second case, using while not touch.buffer_empty: print(touch.get_point)

Before wait_for_edge, irq line is:0
After wait_for_edge, irq line is:1
Waited 0.016 sec for touch data
irq line is now 1
{'x': 401, 'y': 900, 'pressure': 91}
{'x': 457, 'y': 906, 'pressure': 80}
{'x': 576, 'y': 903, 'pressure': 65}
{'x': 735, 'y': 920, 'pressure': 64}
{'x': 945, 'y': 937, 'pressure': 61}
{'x': 1218, 'y': 989, 'pressure': 63}
{'x': 1479, 'y': 1046, 'pressure': 64}
{'x': 1662, 'y': 1084, 'pressure': 58}
{'x': 1847, 'y': 1071, 'pressure': 57}
{'x': 2046, 'y': 1019, 'pressure': 62}
{'x': 2101, 'y': 950, 'pressure': 58}
{'x': 1966, 'y': 925, 'pressure': 56}
{'x': 1543, 'y': 916, 'pressure': 56}
{'x': 1178, 'y': 876, 'pressure': 58}
irq line is now 0

Thanks for any insight about why the irq line is not dropping in the first case...

destockwell
 
Posts: 18
Joined: Sun Sep 06, 2020 6:37 pm

Re: Resistive Touchscreen on Prod 1770 not returning values

by adafruit_support_carter on Wed Nov 11, 2020 2:27 pm

use of GPIO.UP here looks suspicious:
Code: Select all | TOGGLE FULL SIZE
    GPIO.setup(26, GPIO.UP, pull_up_down = GPIO.PUD_DOWN)

should be .IN or .OUT?

adafruit_support_carter
 
Posts: 17777
Joined: Tue Nov 29, 2016 2:45 pm

Re: Resistive Touchscreen on Prod 1770 not returning values

by destockwell on Wed Nov 11, 2020 2:53 pm

Sorry, my mistake, entering code to message by hand.

Parameter was actually GPIO.IN, not GPIO.UP

destockwell
 
Posts: 18
Joined: Sun Sep 06, 2020 6:37 pm

Re: Resistive Touchscreen on Prod 1770 not returning values

by destockwell on Wed Nov 11, 2020 3:44 pm

I believe I have found a weirdness that explains why print(touch.touches) does not clear the buffer and drop the interrupt line. In the library code:

@property
def touches(self):
"""
Returns a list of touchpoint dicts, with 'x' and 'y' containing the
touch coordinates, and 'pressure'
"""
touchpoints = []
while ***** (len(touchpoints) < 4) ***** and not self.buffer_empty:
(x_loc, y_loc, pressure) = self.read_data()
point = {"x": x_loc, "y": y_loc, "pressure": pressure}
touchpoints.append(point)
return touchpoints

It seems that a design choice was made to return no more than FOUR touches at a time. Not sure why that choice was made, but it is unexpected, and only documented in the code.

So, my choice will be to just use the construct:

while not touch.buffer_empty:
.....print(touch.get_point)

Actually, I will be returning the points and probably pushing them into a queue to be consumed by some touchscreen handler in another thread...

Thanks for your attention, and for being a second set of eyes on my beginning Python code. (I already know C#, C++, C, PHP, Pascal, FORTRAN, PL/1, various Basic, and several machine-level assembler languages, etc., so Python is "just one more")

destockwell
 
Posts: 18
Joined: Sun Sep 06, 2020 6:37 pm

Please be positive and constructive with your questions and comments.