<< Click to Display Table of Contents >>

Navigation:  Bits and PCs Blog - 2025.11.20 >

TTP229 Touch Pad - 2025.05.05

Previous pageReturn to chapter overviewNext page

The TTP299-BSF is a capacitive sensing chip for touch pad controls. You can buy ready-made modules from between CHF1 and 5. These run on 3.3 or 5V.

However, there is a problem. The serial communications is not I2C or SPI, it is a 2-wire interface with clock and data signals but no I2C address frame. To start, it toggles the data line low/high, then each data bit must be clocked out on the falling edge of the clock signal. The timing is very important.

The start pulse is only 70..100µS (it is 70µS on my module). This is much too short to be polled - most pulses would be missed if the microcontroller is doing anything else at all. The few Arduino libraries that I found all use polling, so they do not work if your microcontroller is doing something else when a key is pressed or released. Polling means you can just clock out the bits at various intervals to get the current state of the keys, ignoring the 'data valid' DV signal (the start pulse), see data sheet section 3-4.

To solve this problem, the code below uses an interrupt to detect the rising edge of the DV signal. Once detected, you have several milliseconds to clock in the key data, so you can safely poll every few hundred milliseconds to see if the interrupt has occurred.

Note that not all input pins can be used as interrupts, this depends on the microcontroller. For example, on the Uno only pins 2 and 3 can be used to generate interrupts.

 

This is a typical 16-key module. SCL is the clock, SDO is the data out (these are not I2C signals). VCC can be 3.3V or 5V. OUT1..OUT8 are outputs that can be switched on and off when a key is pressed (keys 1..8 only).

ttp229-1

 

Jumpers

P1 and P2 are jumper blocks which can be used to configure the keypad's behaviour by tying certain key pins (TP0..TP7) to GND via a 1 Meg ohm resistor. Most modules already have the pull-down resistors fitted, so only a jumper is needed.

In most cases the default settings are suitable, but usually you will want to set the number of keys to 16 (the default is 8) by adding the TP2 KYSEL jumper. The jumpers are examined only when the module powers up.

Some boards (like to board above) don't have the TPx markings you can see below, they just have 1\8, 2\7, 3\6, and 4\5, which I guess are the TP numbers + 1.

ttp229-6

 

ttp229-7

 

Data sheet

https://www.tontek.com.tw/uploads/product/106/TTP229-LSF_V1.0_EN.pdf

(If that doesn't work, here's the PDF...)
TTP229-LSF_V1.0_EN.pdf

 

Arduino source code

  TTP229TouchPad.h   [Click to expand]

 

Example sketch

 

  #include "TTP229TouchPad.h"

  using namespace MattLabs;

  TTP229TouchPad touchPad;

 

  void setup() 

  {

    // interrupt data pin 2

    // clock pin 4

    // 16 keys (jumper TP2 is in)

    touchPad.begin(2, 4, 16);

  }

 

  void loop 

  {

    // Poll using touched(), then use readKeys() to get the key

    // depressions, one bit for each key bit15=key16..bit0=key1

    if (touchPad.touched()) {

      unsigned int key = touchPad.readKeys();

      ...

    }

  }

Note that you can just call readKeys() to get the current state of the keyboard - most of the libraries I found do this - but it's not as reliable as using the interrupt, and key depressions (or releases) may be missed.

 

Scope trace

Here's an example of a key press. The orange signal is the data SDO and the blue signal is the clock SCL. The first orange pulse edge is the data start signal, about 70uS long. This generates the interrupt. Once the interrupt is detected by calling touched(), function readKeys() clocks out the data bit for each key. The second orange pulse is the data bit for key 13.

ttp229-3

 

Circuit diagram

Here's a typical module's circuit diagram. If you have the same (the most common) module, use this diagram to determine which jumpers you need.

ttp229-2