Skip to main content

A simple XPT2046 chip reader designed for use with CircuitPython.

Project description

skip to docs

xpt2046-circuitpython

A CircuitPython (or Adafruit-Blinka) library which reads values from an XPT2046 chip, commonly found on cheap microcontroller TFT displays.

installation

This project is available on PyPi:

pip3 install xpt2046-circuitpython

Or, to install it manually:

git clone https://github.com/humeman/xpt2046-circuitpython
cd xpt2046-circuitpython
pip3 install .

If you're using this on regular Linux rather than CircuitPython, make sure you also install Adafruit Blinka.

usage

Be sure to enable SPI in sudo raspi-config before proceeding.

sample wiring

TFT Board GPIO Pin #
T_CLK SPI0 SCLK GPIO11 23
T_CS GPIO6 31
T_DIN SPI0 MOSI GPIO10 19
T_DO SPI0 MISO GPIO9 21
T_IRQ GPIO22 15

examples

The most basic read example is:

import xpt2046_circuitpython
import time
import busio
import digitalio
from board import SCK, MOSI, MISO, D6, D22

# Pin config
T_CS_PIN = D6
T_IRQ_PIN = D22

# Set up SPI bus using hardware SPI
spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO)
# Create touch controller
touch = xpt2046.Touch(
    spi, 
    cs = digitalio.DigitalInOut(T_CS_PIN),
    interrupt = digitalio.DigitalInOut(T_IRQ_PIN)
)

# Check if we have an interrupt signal
if touch.is_pressed():
    # Get the coordinates for this touch
    print(touch.get_coordinates())

Some more examples:

  • read.py: A simple program which continuously prints coordinates when the screen is pressed
  • adafruit-ili.py: A simple drawing program for an ILI9341 display controlled by the Adafruit display library

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xpt2046_circuitpython-1.0.3.tar.gz (17.4 kB view hashes)

Uploaded Source

Built Distribution

xpt2046_circuitpython-1.0.3-py3-none-any.whl (17.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page