Giter VIP home page Giter VIP logo

hyperpixel2r-python's Introduction

HyperPixel 2" Round Touch Driver

GitHub Workflow Status Coverage Status PyPi Package Python Versions

Pre-requisites

You must install the HyperPixel 2r drivers which enable an i2c bus for the touch IC - https://github.com/pimoroni/hyperpixel2r

Installing

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

SDL/Pygame on Raspberry Pi

pygame.error: No video mode large enough for 640x480

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

Usage

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 tracked
  • x - x coordinate from 0 to 479
  • y - y coordinate from 0 to 479
  • state - touch state True for touched, False for released

For example:

@touch.on_touch
def handle_touch(touch_id, x, y, state):
    print(touch_id, x, y, state)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.