pimoroni / hyperpixel2r-python

MIT License
23 stars 10 forks source link

constant phantom touches? #10

Closed mptsolutions closed 2 years ago

mptsolutions commented 2 years ago

I'm afraid I may already know the answer, but figured I would ask just in case I am misunderstanding how the touch library is meant to work. My screen is attached to a PiZeroW and I've managed to run all of the examples except for test.py which throws an error when touched. But I noticed that the examples constantly flash colours (even when nothing is touching the screen) so I created the little test below to sort out what might be happening. My expectation is the handle_touch function should only run once when a touch goes down, and then again when it goes up - so I should just get two lines printed for each individual touch. But instead the function is firing constantly as soon as the program starts - it just immediately starts printing lines and doesn't stop until the program is stopped, even though I'm not touching the screen at all. I've also notice that there is always a touch reported as touch_id: 15, x: 4095, y: 4095, state: False right at the start, which seems pretty weird...

Is there something else I am missing about how this is supposed to work... or do I just have a defective screen that thinks it is always being touched?

from hyperpixel2r import Touch
from time import sleep

touch = Touch()

@touch.on_touch
def handle_touch(touch_id, x, y, state):
    print(f'touch_id: {touch_id}, x: {x}, y: {y}, state: {state}')

print('started')
try:
    while True:
        sleep(1)
except KeyboardInterrupt:
    print('stopped')

The output:

pi@raspberryPi:~ $ sudo python3 toucher.py
started
touch_id: 0, x: 237, y: 276, state: False
touch_id: 1, x: 238, y: 146, state: True
touch_id: 0, x: 237, y: 276, state: True
touch_id: 1, x: 238, y: 142, state: True
touch_id: 1, x: 238, y: 137, state: True
touch_id: 1, x: 238, y: 137, state: False
touch_id: 15, x: 4095, y: 4095, state: False
touch_id: 0, x: 237, y: 278, state: True
touch_id: 0, x: 238, y: 255, state: True
touch_id: 0, x: 238, y: 230, state: True
touch_id: 0, x: 239, y: 208, state: True
...
touch_id: 0, x: 239, y: 161, state: True
touch_id: 1, x: 239, y: 340, state: False
touch_id: 0, x: 239, y: 151, state: True
touch_id: 1, x: 239, y: 340, state: True
touch_id: 0, x: 239, y: 152, state: True
touch_id: 1, x: 239, y: 340, state: False
touch_id: 0, x: 239, y: 143, state: True
touch_id: 0, x: 239, y: 157, state: True
touch_id: 0, x: 239, y: 151, state: True
touch_id: 0, x: 239, y: 145, state: True
touch_id: 1, x: 239, y: 285, state: False
^C
stopped
mptsolutions commented 2 years ago

Nevermind. I had a sudden flash of brilliance to try it with a second PiZero... and it works fine. I guess I've got a zapped Pi.

mptsolutions commented 2 years ago

Actually, now that I've had an afternoon of coding... it's suddenly started happening again. I think it's pretty unlikely that I have two malfunctioning RpiZeros, so... any thoughts on what might be the issue?

Gadgetoid commented 2 years ago

This is... strange. How's the board connected, do you have any other i2c devices connected downstream, or any code running which might interfere?

I've been laying the groundwork to get the kernel level touch driver supported, so it might be worth seeing if that exibits the same behavior too.

Details are here: https://github.com/pimoroni/hyperpixel2r/pull/3

mptsolutions commented 2 years ago

I just have the Pi Zero connected directly to the screen. No other devices and I'm using a clean install of the Buster version of RaspberryPi OS Lite. After first boot I apt install git, python3-pip and libsdl2-dev. Then clone / install the hyperpixel2r driver. Then pip install hyperpixel2r and pygame. From there the test code above will run and I get the same output. Sometimes the phantom touches start right away, sometimes it takes a few minutes.

I will give the kernel-level driver a try and see how that goes.

update: I found someone on the support forum with the same problem: https://forums.pimoroni.com/t/hyperpixel-2-1-round-faulty-touch/18123

mptsolutions commented 2 years ago

Confirmed - same random fake touches happen with the kernel-level driver.

Gadgetoid commented 2 years ago

Thank you- sounds like it could be a hardware issue :grimacing:

I might suggest trying to reseat the ribbon cable, but that can sometimes do more harm than good. A photo of the back of your board would be helpful- I can compare it to mine and see if it's worth a try.

In the mean time, could you bung an email to support@pimoroni.com with a brief description and link to this thread to show 'em we've tried a couple of different software fixes across multiple Pi's. They should be able to sort out a replacement if they don't have any other ideas for a fix.

mptsolutions commented 2 years ago

The ribbon looks fine to me. It's in straight and there doesn't appear to be an damage. image

mptsolutions commented 2 years ago

Got my screen replaced and the new one works perfectly!