pimoroni / hyperpixel2r-python

MIT License
23 stars 9 forks source link

I would like to enable touch in a browser #6

Open vasilisvg opened 3 years ago

vasilisvg commented 3 years ago

When I bought the HyperPixel 2.1 Round I assumed that it would work in a similar way as the original Hyperpixel Touch screens. I’ve used one of them before and it simply enables touch for whatever you want to use on a screen. I have a fullscreen Firefox running on a Raspberry PI with a HyperPixel touch without a problem. It just works. I am a bit surprised that the touch driver for the round one is only available for pygame, if I understand things correctly. Are there any plans to update the original driver to work with the round screen as well? I would love to be able to use this screen with web technology in a browser.

Sebwap commented 3 years ago

I think the round model is more specially designed for pi zero (w). And this one is not very smooth with desktop environment.

Touch driver is available with any python project, not just pygame :)

Gadgetoid commented 3 years ago

Are there any plans to update the original driver to work with the round screen as well?

We're at the behest of whatever touch drivers are available natively in Linux if we want to do things properly- but you can just use a Python driver to inject events into uinput, see: https://github.com/pimoroni/hyperpixel2r-python/commit/9880f70cabf616935920b751ef7f95cc6f42134b

I didn't jump through the Linux hoops this time since I didn't think anyone would want to use a round touch screen in a desktop environment. I was clearly wrong 😆

I will look into what the state is for a "proper" driver again, though it probably wont differ much from the Python method.

vasilisvg commented 3 years ago

I didn't jump through the Linux hoops this time since I didn't think anyone would want to use a round touch screen in a desktop environment. I was clearly wrong 😆

Haha, assumptions (-:

I use a minimal desktop environment, just enough to run a browser. It’s a headless Raspberry OS Lite with just xserver-xorg x11-xserver-utils xinit openbox and a browser. I haven’t been successful in installing Firefox on a Rpi Zero and the round screen yet (which is a pity since it is superior in rendering CSS), but Chrome runs fine.

vasilisvg commented 2 years ago

I just received a Raspberry Pi Zero 2W. I haven't tested it yet, but the specs promise a comparable speed to 3B or 3B+. It sounds like it is capable of doing some heavier graphics. I would love to connect it to the round screen. Any news on this?

Gadgetoid commented 2 years ago

For now you should use the uinput touch example here in lieu of a touch driver - https://github.com/pimoroni/hyperpixel2r-python/blob/master/examples/uinput-touch.py

There are some details on the touch IC here https://forums.pimoroni.com/t/hyperpixel-round-touch/17568/3

And perhaps an Android kernel driver. But nothing for Linux yet, so that would be a huge rabbit hole - https://github.com/ulefoneofficial/Power-Armor-13/tree/main/kernel-4.14/drivers/input/touchscreen/hynitron

vasilisvg commented 2 years ago

I am just a raspberry pi tinkerer, I would in no way be able to write a kernel (-: The other sources and examples you provided don’t really seem to fix my issue, unfortunately. Basically, the issue I have is: I own a rectangular Hyperpixel screen which Just Works. So I bought a round screen which is sold under the same moniker assuming that it would just work as well. I am surprised that it if you want to enable touch, it is still a python only device. I guess I'll need to use a physical mask on a rectangular screen to achieve what I want in the future )-:

Gadgetoid commented 2 years ago

The Python code I linked doesn't require you to write Python in order to use touch- it should work more or less like a regular touch driver except it's written in Python. Did it not work for you?

vasilisvg commented 2 years ago

Seems like I made a wrong assumption about how the driver works. I'll try again and let you know if it works.

vasilisvg commented 2 years ago

Oh wow, it works! This is fantastic! For future reference, and for anybody who ends up here. Here is how I got it to work.

First, install the driver. I needed sudo, without it, it resulted in lots of errors. So install it like so:

sudo pip3 install hyperpixel2r

I also ran the following code, but I am not entirely sure if it is really needed:

sudo python3 -m pip install pygame --upgrade

Then I installed the examples like so

git clone https://github.com/pimoroni/hyperpixel2r-python

Now I ran the uinput-touch.py like so:

cd hyperpixel2r-python/examples/
sudo python3 uinput-touch.py

If it works it should say something like 2021-11-04 22:00:21.617653: HyperPixel2r Touch daemon running...

F1p commented 2 years ago

If anyone is interested in a backlight on/off script. This also can adjust backlight brightness with PWM on pin 19.

sudo apt-get install wiringpi

#!/usr/bin/env python
# backlight-monitor.py

# ============================ #
# Display ON/OFF by P Thomson  #
# ============================ #

import os, subprocess, time

# Set the screen timeout here at for example, 30 seconds with xset:
subprocess.call('XAUTHORITY=~pi/.Xauthority xset -display :0 s 30 && xset -display :0 dpms 30 30 30', shell=True)

while True:
    if subprocess.check_output('xset -display :0 q | grep Monitor', shell=True)[14] == 110 :
        # Value of 500 is about half brightness
        subprocess.call('XAUTHORITY=~pi/.Xauthority gpio -g mode 19 pwm && gpio -g pwm 19 500', shell=True)
    if subprocess.check_output('xset -display :0 q | grep Monitor', shell=True)[14] == 102 :
        # Value of 0 is off
        subprocess.call('XAUTHORITY=~pi/.Xauthority gpio -g mode 19 pwm && gpio -g pwm 19 0', shell=True)
    time.sleep(0.3)
jamaces commented 2 years ago

I am trying to get touch to work on a raspbery pi4

I went through the steps above https://github.com/pimoroni/hyperpixel2r-python/issues/6#issuecomment-961473716

After running cd hyperpixel2r-python/examples/ sudo python3 uinput-touch.py

I continue to get the error message ~/hyperpixel2r-python/examples $ sudo python3 uinput-touch.py 2022-01-18 12:38:29.439633: HyperPixel2r Touch daemon running... Traceback (most recent call last): File "uinput-touch.py", line 155, in <module> touch = Touch() File "/usr/local/lib/python3.7/dist-packages/hyperpixel2r/__init__.py", line 13, in __init__ self._bus = smbus2.SMBus(bus) File "/usr/local/lib/python3.7/dist-packages/smbus2/smbus2.py", line 280, in __init__ self.open(bus) File "/usr/local/lib/python3.7/dist-packages/smbus2/smbus2.py", line 310, in open self.fd = os.open(filepath, os.O_RDWR) FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-11' Exception ignored in: <function InputDevice.__del__ at 0xb6103b70> Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/evdev/device.py", line 160, in __del__ File "/usr/local/lib/python3.7/dist-packages/evdev/device.py", line 305, in close File "/usr/local/lib/python3.7/dist-packages/evdev/eventio_async.py", line 55, in close File "/usr/lib/python3.7/asyncio/events.py", line 726, in get_event_loop_policy File "/usr/lib/python3.7/asyncio/events.py", line 719, in _init_event_loop_policy ImportError: sys.meta_path is None, Python is likely shutting down

Any support is appreciated.

Thank you!

F1p commented 2 years ago

Have you installed the following first?

sudo pip3 install python-uinput sudo pip3 install evdev

And enabled uinput with the command: sudo modprobe uinput

jamaces commented 2 years ago

Have you installed the following first?

sudo pip3 install python-uinput sudo pip3 install evdev

And enabled uinput with the command: sudo modprobe uinput

I didn't know about pip3 install python-uinput along with modprobe uinput

after installing python-uinput it said it is satisfied

However whenever I try to start any of the examples:

sudo python3 (example).py

I end up with the error

FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-11'

Should this be a concern?

edit: when I got to '/dev all I have i2c-22 not i2c-11

edit2: error fixed.

ran

sudo ln -s /dev/i2c-22 /dev/i2c-11

this is only a temp fix, when reboot the link is removed. Is there anyway to link to i2c-22?

Gadgetoid commented 2 years ago

I'll need to fix the Python script to find the right i2c bus automatically. I made the mistake of thinking it would be in any way consistent.

I might have another look into getting a proper kernel driver up and running, too, since it appears to be far more popular a demand than I'd anticipated!

Gadgetoid commented 2 years ago

Touch driver raised as a PR here: https://github.com/pimoroni/hyperpixel2r/pull/3

You should be able to test this over your existing install by:

git clone https://github.com/pimoroni/hyperpixel2r/ -b patch-f5x06-touch
cd hyperpixel2r/src
make
sudo make install

Then reboot.

This will build and copy a new hyperpixel2r.dtbo to /boot/overlays

jamaces commented 2 years ago

I appreciate the quick support I will give a try this weekend.

davidfurlong commented 2 years ago

I haven't followed this thread entirely but I'd like to share what is working for me - Thank you very much to the devs here 🙏 for all these resources

via ssh running sudo python3 uinput-touch.py & runs touch mode in the background, then DISPLAY=:0 chromium-browser --start-maximized --kiosk https://www.google.com opens a browser full screen to the specified url with touch working.

As a JS dev I'm going to play around with building stuff for the browser for it to use the hyperpixel and program for it rather that trying to get better at python/python libs.