adafruit_stmpe610

This is a CircuitPython Driver for the STMPE610 Resistive Touch sensor

  • Author(s): Jerry Needell, CedarGroveMakerStudios

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_stmpe610.Adafruit_STMPE610

A class (driver) for the STMPE610 Resistive Touch controller used by the 2.4” 320x240 TFT FeatherWing display (#3315), 3.5” 480x320 TFT FeatherWing display (#3651), and the Resistive Touch Screen Controller - STMPE610 breakout board (#1571). This class acts as a super class for the I2C and SPI interface classes.

This class was modified from the original to add the Displayio Button compatible touch_point property to the existing functionality.

See the examples folder for instantiation kwargs and properties.

property buffer_empty: bool

Buffer empty status.

property buffer_size: int

The amount of touch data in the buffer.

property get_point: Dict[str, int]

Read one touch from the buffer.

property get_version: int

Read the version number from the sensor.

read_data() Tuple[int, int, int]

Request next stored reading - return tuple containing (x,y,pressure).

property touched: bool

Report if any touches were detected.

property touches: List[Dict[str, int]]

Returns a list of touchpoint dicts, with ‘x’ and ‘y’ containing the touch coordinates, and ‘pressure’.

class adafruit_stmpe610.Adafruit_STMPE610_I2C(i2c: I2C, address: int = 65, calibration: Tuple[Tuple[int, int], Tuple[int, int]] | None = None, size: Tuple[Tuple[int, int], Tuple[int, int]] | None = None, disp_rotation: Literal[0, 90, 180, 270] = 0, touch_flip: Tuple[bool, bool] = (False, False))

I2C interface class for the STMPE610 Resistive Touch sensor.

Parameters:
  • i2c – I2C interface bus

  • address (int) – I2C address. Defaults to 0x41

  • calibration (None, (int, int)) – touchscreen calibration tuple. Defaults to None.

  • size (None, (int, int)) – display size tuple (width, height). Defaults to None.

  • disp_rotation (int) – display rotation in degrees. Values allowed are 0, 90, 180, and 270. Defaults to 0.

  • touch_flip ((bool, bool)) – swap touchscreen axis range minimum and maximum values for (x, y) axes as referenced to display 0-degree rotation. Defaults to (False, False).

** Quickstart: Importing and instantiating Adafruit_STMPE610_I2C**

Import the Adafruit_STMPE610_I2C class and instantiate for the 2.4” TFT Wing after instantiating the display:

import adafruit_stmpe610
ts = adafruit_stmpe610.Adafruit_STMPE610_I2C(board.I2C(), address=0x41,
    calibration=((357, 3812), (390, 3555)),
    size=(display.width, display.height), disp_rotation=display.rotation,
    touch_flip=(False, False))
property touch_point: Tuple[int, int, int] | None

Read latest touched point value and convert to calibration-adjusted and rotated display coordinates. Commpatible with Displayio Button. :return: x, y, pressure rtype: int, int, int

class adafruit_stmpe610.Adafruit_STMPE610_SPI(spi: SPI, cs: Pin, baudrate: int = 1000000, calibration: Tuple[Tuple[int, int], Tuple[int, int]] | None = None, size: Tuple[int, int] | None = None, disp_rotation: Literal[0, 90, 180, 270] = 0, touch_flip: Tuple[bool, bool] = (False, False))

SPI interface class for the STMPE610 Resistive Touch sensor.

Parameters:
  • spi – SPI interface bus

  • cs (pin) – touchscreen SPI interface chip select pin

  • baudrate (int) – SPI interface clock speed in Hz. Defaults to 1000000 (1MHz).

  • calibration (None, (int, int)) – touchscreen calibration tuple. Defaults to None.

  • size (None, (int, int)) – display size tuple (width, height). Defaults to None.

  • disp_rotation (int) – display rotation in degrees. Values allowed are 0, 90, 180, and 270. Defaults to 0.

  • touch_flip ((bool, bool)) – swap touchscreen axis range minimum and maximum values for (x, y) axes as referenced to display 0-degree rotation. Defaults to (False, False).

** Quickstart: Importing and instantiating Adafruit_STMPE610_I2C**

Import the Adafruit_STMPE610_SPI class and instantiate for the 2.4” TFT Wing after instantiating the display:

import adafruit_stmpe610
ts = adafruit_stmpe610.Adafruit_STMPE610_SPI(spi, cs=cs_pin,
    baudrate=1000000,
    calibration=((357, 3812), (390, 3555)),
    size=(display.width, display.height), disp_rotation=display.rotation,
    touch_flip=(False, False))
property touch_point: Tuple[int, int, int] | None

Read latest touched point value and convert to calibration-adjusted and rotated display coordinates. Commpatible with Displayio Button. :return: x, y, pressure rtype: int, int, int

adafruit_stmpe610.map_range(x: float, in_min: float, in_max: float, out_min: float, out_max: float) float

Maps a value from one range to another. Values beyond the input minimum or maximum will be limited to the minimum or maximum of the output range.

Returns:

Returns value mapped to new range

Return type:

float