You must install the HyperPixel 2r drivers which enable an i2c bus for the touch IC - https://github.com/pimoroni/hyperpixel2r
Make sure you edit /boot/config.txt
and add :disable-touch
after hyperpixel2r
, like so:
dtoverlay=hyperpixel2r:disable-touch
This disables the Linux touch driver so Python can talk to the touch IC.
Stable library from PyPi:
- Just run
pip3 install hyperpixel2r
In some cases you may need to use sudo
or install pip with: sudo apt install python3-pip
Latest/development library from GitHub:
git clone https://github.com/pimoroni/hyperpixel2r-python
cd hyperpixel2r-python
sudo ./install.sh
The version of Pygame shipped with Raspberry Pi OS doesn't like non-standard resolutions like 480x480. You can fake a 640x480 standard display by forcing HDMI hotplug, and then just to a 480x480 region to display on HyperPixel 2.0" round. In /boot/config.txt
:
# Force 640x480 video for Pygame / HyperPixel2r
hdmi_force_hotplug=1
hdmi_mode=1
hdmi_group=1
Set up touch driver instance:
touch = Touch(bus=11, i2c_addr=0x15, interrupt_pin=27):
Touches should be read by decorating a handler with @touch.on_touch
.
The handler should accept the arguments touch_id
, x
, y
and state
.
touch_id
- 0 or 1 depending on which touch is trackedx
- x coordinate from 0 to 479y
- y coordinate from 0 to 479state
- touch stateTrue
for touched,False
for released
For example:
@touch.on_touch
def handle_touch(touch_id, x, y, state):
print(touch_id, x, y, state)