colinodell / mqtt-control-panel

A simple alarm control panel for Home Assistant's manual_mqtt alarm. Designed to run on a Raspberry Pi using an Adafruit 3.5" PiTFT.
MIT License
86 stars 25 forks source link

Touch points misplaced? #1

Closed runraid closed 7 years ago

runraid commented 7 years ago

First off, thanks for putting this together.

I've got things working with a raspberry pi 3 and the PiTFT Plus 480x320 resistive touch screen (2441 model, same as yours), but I'm having issues with touch.

The button presses don't seem to be working, it's almost as if the touch coordinates are misaligned with the actual coordinates... and the touches don't always register. I can touch to the right of the screen and sometimes that will trigger the "1" or "2" button, even though I touched nowhere near those buttons.

When running "sudo evtest /dev/input/touchscreen", I can verify that the touch screen does work and valid x/y coords are returned for each press. For example, when I touch roughly in the middle of the screen...

Event: time 1501614062.680235, -------------- EV_SYN ------------
Event: time 1501614062.686953, type 3 (EV_ABS), code 0 (ABS_X), value 2272
Event: time 1501614062.686953, type 3 (EV_ABS), code 1 (ABS_Y), value 1921
Event: time 1501614062.686953, type 3 (EV_ABS), code 24 (ABS_PRESSURE), value 203

Do you have any idea what might be happening here?

colinodell commented 7 years ago

It sounds like you may need to recalibrate it. Try using the manual calibration and let me know if that helps. sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_calibrate

runraid commented 7 years ago

Thanks. What do I do with the output of that calibration? Do I need to put the output somewhere? Or does the command do that for me?

Here's the output

xres = 480, yres = 320
Took 13 samples...
Top left : X =  688 Y = 3490
Took 24 samples...
Top right : X =  686 Y =  544
Took 33 samples...
Bot right : X = 3052 Y =  608
Took 32 samples...
Bot left : X = 3325 Y = 3523
Took 31 samples...
Center : X = 2036 Y = 1996
499.008667 0.002386 -0.129751
-3.343201 0.087653 -0.004049
Calibration constants: 32703032 156 -8503 -219100 5744 -265 65536
runraid commented 7 years ago

I ran sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_test and the screen works perfect. I can drag and draw without issue, yet, the alarm display touches do not register correctly.

Any other ideas?

colinodell commented 7 years ago

I think that command should save the output wherever it is needed. (That calibration is the one that asks you to press the + symbols, right? I tried a few calibration tools and that was the only one which worked).

If you're still having issues, I'd recommend trying a reboot if you haven't already done so. Also try running the Python app as root if you haven't tried that either.

I hope that helps!

On Tue, Aug 1, 2017 at 3:40 PM Ronnie notifications@github.com wrote:

I ran sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_test and the screen works perfect. I can drag and draw without issue, yet, the alarm display touches do not register correctly.

Any other ideas?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/colinodell/mqtt-control-panel/issues/1#issuecomment-319474955, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMVMumUtUrX4MV-HQhFA0W81TzIHguAks5sT382gaJpZM4OqKDB .

runraid commented 7 years ago

Thanks. I'm doing and have done all of the above. No luck.

colinodell commented 7 years ago

Hmm.. I have some other thoughts, but no idea if they'll help:

I wish I had something better to offer.

runraid commented 7 years ago

How important is "pygame==1.9.2a0" ? I've used 1.9.3 because I couldn't find 1.9.2a0 with pip.

runraid commented 7 years ago

Also which sdl config are you using?

colinodell commented 7 years ago

I don't know how important that is TBH. Maybe try a 1.9.2 stable version if that exists?

I'm using SDL 1.2, so I may have followed this guide: https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/pitft-pygame-tips#ensure-you-are-running-sdl-1-dot-2. I don't know that I have any special configurations for it (though I'd be happy to share a config file if you can point me to one)

Speaking of config files, here's the bottom of my /boot/config.txt:

device_tree=bcm2708-rpi-0-w.dtb
dtparam=spi=on
dtparam=i2c1=on
dtparam=i2c_arm=on
dtoverlay=pitft35-resistive,rotate=270,speed=16000000,fps=20
runraid commented 7 years ago

I've tried it all. At this point I'll just have to give up. Something just doesn't work and I'm pretty sure it's with the mqtt-control-panel as I can draw perfectly with the calibration test programs, so I'm certain things are calibrated correctly and I'm certain my screen is functional.

Thanks.

runraid commented 7 years ago

I take that back. Running this https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/pitft-pygame-tips#ensure-you-are-running-sdl-1-dot-2

to get on the correct SDL version seems to have improved things. Now touches register every time, but are not properly calibrated. Making progress...

runraid commented 7 years ago

OK got it. Instead of trying to get the touch calibration to match the screen orientation, I made the screen match the touch by instead of rotating the screen 270, I only rotated it 90... dtoverlay=pitft35-resistive,rotate=270,speed=16000000,fps=20

Now things match. I'm not sure how to get the touch calibration to rotate -- worst case now is, it works, just my device is upside down... not that it matters.

The 2nd thing was the SDL config from the link above. It's critical to be on that specific version.

3rd: I could only get this to work with pygame = 1.9.3.

Thanks!

colinodell commented 7 years ago

Awesome, I'm glad you got it (mostly) working!

If you're able to figure out the rotation I'd love to hear what you did. (Posting the solution here might also help anyone else who has similar issues in the future)

runraid commented 7 years ago

Will do. Right now I'm trying to figure out why the device claims it connected to mqtt (which is is at first because it gets the correct state) but then ignores all future state changes in mqtt. I'm changing the state with the HomeAssistant UI and the current state is not reflected on the device.

If I reboot the device it will get the correct state. If I reboot home assistant the device will update with the correct state.

runraid commented 7 years ago

Noticed a pattern. If I reboot the device, I can toggle armed-home, armed-away, and disarmed in the HA UI and the device will instantly see the updated state. I can keep switching to new states and the device has no issue.

Things go screwy once I get on the device, type in my 4 digit code and click "armed". Once I do that on the device it exhibits the behavior in the previous comment where the device is unable to reflect the true state in mqtt (I toggle states in the HA UI and the device does not see the updated states... even if I diconnect it from mqtt the device UI still says "connected")