ttp229
TonTouch TTP229 hardware driver for CircuitPython. Can detect up to 16 channels of touch input over a specialized 2-pin serial interface.
If using a Raspberry Pi Pico series microcontroller (RP2040/RP235x), this module will utilize a PIO state machine to read data from the TTP229 efficiently. Otherwise, it will use basic digitalio bit-banging to control the clock pin and read data over the serial interface.
To use this module, the TTP229 must be configured for 2-wire serial interface mode (not I2C). It can support either 8-key or 16-key mode and clock active-high/low depending on the parameters provided in the class constructor. By default, the module is configured for 16-key mode with an active-high clock.
See the device documentation for how best to configure your pins of the TTP229.
Author(s): Cooper Dalrymple
Implementation Notes
Hardware:
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
- class ttp229.Mode
Enum-like class representing the possible modes of the TTP229.
- KEY_16 = 1
16-keys mode
- KEY_8 = 0
8-keys mode
- class ttp229.TTP229(sdo: microcontroller.Pin, scl: microcontroller.Pin, mode: int = Mode.KEY_16, invert_clk: bool = False)
Driver for the TTP229-BSF serial interface capacitive touch sensor. The states of each touch input can be accessed after calling
update()using thedatavalue, theon_pressandon_releasecallbacks, or by treating the object as a list (see example below).import board import ttp229 ttp = ttp229.TTP229(board.GP0, board.GP1) ttp.update() for i in range(len(ttp)): print("Touch input {:d} is {:s}".format(i, "on" if ttp[i] else "off")
- Parameters:
- on_press: Callable[[int], None] = None
Callback which will be called when a press is detected during the
update()method. The callback must include 1 integer parameter for the index of the touch input.import board import ttp229 ttp = ttp229.TTP229(board.GP0, board.GP1) def pressed(index:int) -> None: print("Touch input {:d} was pressed".format(index)) ttp.on_press = pressed
- on_release: Callable[[int], None] = None
Callback which will be called when a release is detected during the
update()method. The callback must include 1 integer parameter for the index of the touch input.import board import ttp229 ttp = ttp229.TTP229(board.GP0, board.GP1) def released(index:int) -> None: print("Touch input {:d} was released".format(index)) ttp.on_release = released