Labs / Bipes + MicroPython / 7 Sensors: Enable Programs to "Perceive the World"

7.2 Triggerable Without Pressing? Unlock Contactless Touch Sensing Tricks! —— TTP223-Based Touch Key Module

Author: Li Zisheng · Source: FreakStudio open documentation · License: CC BY 4.0

Contents

Young makers, now let's unlock a much cooler touch version — the touch key module based on TTP223 ✨! It doesn't have the "press-down" tactile feel of mechanical keys; just a light tap of your finger, and the development board will respond instantly (like lighting up an LED or triggering a motor), just like using a touchscreen phone — totally high-tech and awesome~

1. Module Introduction

Mechanical buttons require being pressed down, so is there a method that can be triggered with just a light touch without pressing? This is exactly what the TTP223 touch button module excels at!

The TTP223 touch key module is a capacitive touch input module: when a finger approaches or touches the sensing area, the module detects the tiny capacitance change caused by the human body and immediately outputs a level signal to inform the development board that "someone has touched me!"

Compared with ordinary mechanical keys, it has these obvious features:

In graphical programming, these blocks are mainly used for the TTP223 touch button:

In practical projects, it is often used for the following purposes:

Quick Science Pop

What exactly is "capacitive sensing"? Our fingers inherently carry a weak capacitance (which can be simply understood as a "tiny electric charge"). When a finger touches the sensing area of the module, it alters the capacitance value of the module's internal circuit. Once the TTP223 chip detects this change, it outputs a trigger signal — this is the core principle behind touchscreen smartphones and touch-controlled table lamps!

2. Wiring Instructions

To make the development board "sense" your fingers, the first step is still —— connect the wires correctly!

TTP223 DIO0 6

We connect the TTP223 touch key module to the DIO0 interface of the development board, and the corresponding relationship is as follows:

Development Board Pins

Module Pins

Description

Pin 6

DOUT

Digital signal output after touch detection

Pin 7

NC

Do not use

📌 Note

  • When no touch is detected, the DOUT output is low;
  • When a finger touches the sensing area, DOUT will turn into a high level;
    the development board can determine whether a touch has occurred as long as it reads this level change.

3. Example: Detect whether it is touched

Experiment Objective: To implement the most basic touch detection function: when we touch the TTP223 module with a finger, a prompt message will be printed on the terminal, and the printing will stop after the finger is released.

Everyday Life Insight: The reason why a mobile phone screen can detect whether you have "tapped it" relies on a principle similar to that of this module. Now, let's make a small device that "can sense touch"!

The graphical program is as follows:

TTP223 9/GPIO6 1

Building Block Assembly Steps:

  1. infinite loop
    • Select the repeat while true block to make the program continuously detect the touch status;
  2. Read touch status
    • Use the read digital input block;
    • Pin Selection: Pin 12 / GPIO9 (corresponding to the DIO1 interface);
  3. conditional judgment
    • Use the if read digital input block;
    • When the read result is true (high level), it indicates that the current position is being touched;
  4. Touch Response
    • Add the print "Touch detected" block when the condition is true;

Experimental Effect:

Graphical blocks will be automatically converted into MicroPython code for execution on the development board:

TTP223 pIn6 6 1

XML file (can be directly imported into building blocks):

TTP223-based touch button module.xml 2 KB

Tips

  1. If there is no response to touch:
    • Check whether the correct pins are selected (GPIO9 / Pin12);
    • Make sure your finger directly touches the sensor area; being separated by overly thick materials may affect the performance.
  2. The touch module is relatively sensitive to the environment:
    • When there is a large amount of metal on the desktop, it may be triggered more easily;
  3. For a more stable effect:
    • Add a delay of 200~500 ms after the touch trigger.

✨ Interactive Mini Quiz

  1. Think about it:
    Why doesn't TTP223 need to handle "key shake" like mechanical buttons?
  2. Try it out:
    Change the delay time from 300 ms to 50 ms, what will happen?
    Then change it to 1000 ms to experience the change in the feel~

Summary

  1. The TTP223 touch key module is a capacitive input device that triggers signals by sensing finger touches;
  2. Compared with mechanical buttons, it requires no force to operate, is more durable, and enables more natural interaction;
  3. The basic usage is to detect "whether it is being touched", and the advanced usage is touch to switch states;
  4. Adding an appropriate delay can prevent consecutive accidental touches and make the program perform more stably.