Merge branch 'touch_sensor/update_touch_sensor_examples' into 'master'

touch_sensor: update touch sensor examples

Closes IDF-3885 and IDFGH-7751

See merge request espressif/esp-idf!19284
This commit is contained in:
morris 2022-08-02 01:25:04 +08:00
commit 06b31d487b
31 changed files with 384 additions and 114 deletions

View File

@ -1,4 +1,6 @@
if(IDF_TARGET STREQUAL "esp32s2")
set(TOUCH_ELEMENT_COMPATIBLE_TARGETS "esp32s2" "esp32s3")
if(IDF_TARGET IN_LIST TOUCH_ELEMENT_COMPATIBLE_TARGETS)
idf_component_register(SRCS "touch_element.c"
"touch_button.c"
"touch_slider.c"

View File

@ -1,4 +1,6 @@
if(IDF_TARGET STREQUAL "esp32s2")
set(TOUCH_ELEMENT_COMPATIBLE_TARGETS "esp32s2" "esp32s3")
if(IDF_TARGET IN_LIST TOUCH_ELEMENT_COMPATIBLE_TARGETS)
idf_component_register(SRCS "test_touch_element.c"
"test_touch_button.c"
"test_touch_slider.c"

View File

@ -280,6 +280,8 @@ static esp_err_t slider_object_set_threshold(void)
return ret;
}
// workaround for compilation error on xtensa-esp32s3-elf-gcc (crosstool-NG esp-2022r1-RC1) 11.2.0 (IDF-5725)
__attribute__((optimize("-Os")))
static void slider_object_process_state(void)
{
te_slider_handle_list_t *item;

View File

@ -186,16 +186,16 @@ examples/peripherals/touch_sensor:
examples/peripherals/touch_sensor/touch_element:
enable:
- if: IDF_TARGET == "esp32s2"
reason: only test on esp32s2
- if: IDF_TARGET in ["esp32s2", "esp32s3"]
reason: only supports esp32s2 and esp32s3
examples/peripherals/touch_sensor/touch_sensor_v1:
disable:
- if: SOC_TOUCH_SENSOR_NUM != 10
- if: SOC_TOUCH_VERSION_1 != 1
examples/peripherals/touch_sensor/touch_sensor_v2:
disable:
- if: SOC_TOUCH_SENSOR_NUM != 15
- if: SOC_TOUCH_VERSION_2 != 1
examples/peripherals/twai:
disable:

View File

@ -1,20 +1,30 @@
| Supported Targets | ESP32-S2 |
| ----------------- | -------- |
| Supported Targets | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- |
# Touch button example
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This example demonstrates how to use the Touch Element library of capacitive touch sensor and set up touch button.
## How to use example
### Hardware Required
* A development board with ESP32-S2 or ESP32-S3 chip
* A touch extension board like [esp32-s2-touch-devkit-1](https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp32s2/esp32-s2-touch-devkit-1/user_guide.html)
### Configure the project
* Set the target of the build (where `{IDF_TARGET}` stands for the target chip such as `esp32s2`).
* Run `menuconfig` to select a dispatch method for the example.
* Set the target of the build by following command, where TARGET can be `esp32s2` or `esp32s3`.
```
idf.py set-target TARGET
```
* Run `idf.py menuconfig` to select a dispatch method for the example.
### Build and Flash
Build the project and flash it to the target board, then run monitor tool to view serial output:
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
@ -56,4 +66,6 @@ I (11991) Touch Button Example: Button[9] LongPress
I (12881) Touch Button Example: Button[9] Release
```
See the README.md file in the upper level 'examples' directory for more information about examples.
## Troubleshooting
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.

View File

@ -1,6 +1,3 @@
if(IDF_TARGET STREQUAL "esp32s2")
idf_component_register(SRCS "touch_button_example_main.c"
INCLUDE_DIRS ".")
else()
message(FATAL_ERROR "Touch button example only available on esp32s2 now")
endif()
idf_component_register(SRCS "touch_button_example_main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES touch_element)

View File

@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
def test_touch_button(dut: Dut) -> None:
dut.expect_exact('Touch Button Example: Touch element library installed')
dut.expect_exact('Touch Button Example: Touch button installed')
dut.expect_exact('Touch Button Example: Touch buttons created')
dut.expect_exact('Touch Button Example: Touch element library start')

View File

@ -1,12 +1,27 @@
| Supported Targets | ESP32-S2 |
| ----------------- | -------- |
| Supported Targets | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- |
# Touch Element waterproof Example
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This example demonstrates how to use the Touch Element library of capacitive Touch Sensor and setup the touch elements with touch element waterproof protection.
## How to use example
### Hardware Required
* A development board with ESP32-S2 or ESP32-S3 chip
* A touch extension board like [esp32-s2-touch-devkit-1](https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp32s2/esp32-s2-touch-devkit-1/user_guide.html)
### Configure the project
* Set the target of the build by following command, where TARGET can be `esp32s2` or `esp32s3`.
```
idf.py set-target TARGET
```
* Run `idf.py menuconfig` to select weather to enable waterproof function.
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
@ -39,4 +54,6 @@ I (12561) Touch Element Waterproof Example: Button[9] Press
I (12811) Touch Element Waterproof Example: Button[9] Release
```
See the README.md file in the upper level 'examples' directory for more information about examples.
## Troubleshooting
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.

View File

@ -1,6 +1,3 @@
if(IDF_TARGET STREQUAL "esp32s2")
idf_component_register(SRCS "waterproof_example_main.c"
INCLUDE_DIRS ".")
else()
message(FATAL_ERROR "Touch element waterproof example only available on esp32s2 now")
endif()
INCLUDE_DIRS "."
PRIV_REQUIRES touch_element)

View File

@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
def test_touch_element_waterproof(dut: Dut) -> None:
dut.expect_exact('Touch Element Waterproof Example: Touch Element library install')
dut.expect_exact('Touch Element Waterproof Example: Touch Element waterproof install')
dut.expect_exact('Touch Element Waterproof Example: Touch button install')
dut.expect_exact('Touch Element Waterproof Example: Touch buttons create')

View File

@ -1,19 +1,29 @@
| Supported Targets | ESP32-S2 |
| ----------------- | -------- |
| Supported Targets | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- |
# Touch button example
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This example demonstrates how to use the Touch Element library of capacitive touch sensor and set up more than one type of touch elements and handle all the event messages in one task.
## How to use example
### Hardware Required
* A development board with ESP32-S2 or ESP32-S3 chip
* A touch extension board like [esp32-s2-touch-devkit-1](https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp32s2/esp32-s2-touch-devkit-1/user_guide.html)
### Configure the project
* Set the target of the build (where `{IDF_TARGET}` stands for the target chip such as `esp32s2`).
* Set the target of the build by following command, where TARGET can be `esp32s2` or `esp32s3`.
```
idf.py set-target TARGET
```
### Build and Flash
Build the project and flash it to the target board, then run monitor tool to view serial output:
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
@ -135,4 +145,6 @@ I (4341) Touch Elements Combination Example: Slider Calculate, position: 101
I (4351) Touch Elements Combination Example: Slider Release, position: 101
```
See the README.md file in the upper level 'examples' directory for more information about examples.
## Troubleshooting
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.

View File

@ -1,6 +1,3 @@
if(IDF_TARGET STREQUAL "esp32s2")
idf_component_register(SRCS "touch_elements_example_main.c"
INCLUDE_DIRS ".")
else()
message(FATAL_ERROR "Touch elements combination example only available on esp32s2 now")
endif()
idf_component_register(SRCS "touch_elements_example_main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES touch_element)

View File

@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
def test_touch_elements_combination(dut: Dut) -> None:
dut.expect_exact('Touch Elements Combination Example: Touch element library installed')
dut.expect_exact('Touch Elements Combination Example: Touch button installed')
dut.expect_exact('Touch Elements Combination Example: Touch buttons created')
dut.expect_exact('Touch Elements Combination Example: Touch slider installed')
dut.expect_exact('Touch Elements Combination Example: Touch slider created')
dut.expect_exact('Touch Elements Combination Example: Touch element library start')

View File

@ -1,20 +1,30 @@
| Supported Targets | ESP32-S2 |
| ----------------- | -------- |
| Supported Targets | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- |
# Touch Element basic example (EVENT)
# Touch Element matrix example
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This example demonstrates how to use the Touch Element library of capacitive touch sensor and set up touch matrix.
## How to use example
### Hardware Required
* A development board with ESP32-S2 or ESP32-S3 chip
* A touch extension board like [esp32-s2-touch-devkit-1](https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp32s2/esp32-s2-touch-devkit-1/user_guide.html)
### Configure the project
* Set the target of the build (where `{IDF_TARGET}` stands for the target chip such as `esp32` or `esp32s2`).
* Run `menuconfig` to select a dispatch method for the example.
* Set the target of the build by following command, where TARGET can be `esp32s2` or `esp32s3`.
```
idf.py set-target TARGET
```
* Run `idf.py menuconfig` to select a dispatch method for the example.
### Build and Flash
Build the project and flash it to the target board, then run monitor tool to view serial output:
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
@ -50,4 +60,6 @@ I (10551) Touch Matrix Example: Matrix LongPress, axis: (1, 1) index: 4
I (11031) Touch Matrix Example: Matrix Release, axis: (1, 1) index: 4
```
See the README.md file in the upper level 'examples' directory for more information about examples.
## Troubleshooting
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.

View File

@ -1,6 +1,3 @@
if(IDF_TARGET STREQUAL "esp32s2")
idf_component_register(SRCS "touch_matrix_example_main.c"
INCLUDE_DIRS ".")
else()
message(FATAL_ERROR "Touch matrix example only available on esp32s2 now")
endif()
idf_component_register(SRCS "touch_matrix_example_main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES touch_element)

View File

@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
def test_touch_matrix(dut: Dut) -> None:
dut.expect_exact('Touch Matrix Example: Touch element library installed')
dut.expect_exact('Touch Matrix Example: Touch matrix installed')
dut.expect_exact('Touch Matrix Example: Touch matrix created')
dut.expect_exact('Touch Matrix Example: Touch element library start')

View File

@ -1,20 +1,30 @@
| Supported Targets | ESP32-S2 |
| ----------------- | -------- |
| Supported Targets | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- |
# Touch Element basic example (EVENT)
# Touch Element slider example
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This example demonstrates how to use the Touch Element library of capacitive touch sensor and set up touch slider.
## How to use example
### Hardware Required
* A development board with ESP32-S2 or ESP32-S3 chip
* A touch extension board like [esp32-s2-touch-devkit-1](https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp32s2/esp32-s2-touch-devkit-1/user_guide.html)
### Configure the project
* Set the target of the build (where `{IDF_TARGET}` stands for the target chip such as `esp32s2`).
* Run `menuconfig` to select a dispatch method for the example.
* Set the target of the build by following command, where TARGET can be `esp32s2` or `esp32s3`.
```
idf.py set-target TARGET
```
* Run `idf.py menuconfig` to select a dispatch method for the example.
### Build and Flash
Build the project and flash it to the target board, then run monitor tool to view serial output:
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
@ -81,4 +91,6 @@ I (2351) Touch Slider Example: Slider Calculate, position: 61
I (2361) Touch Slider Example: Slider Release, position: 61
```
See the README.md file in the upper level 'examples' directory for more information about examples.
## Troubleshooting
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.

View File

@ -1,6 +1,3 @@
if(IDF_TARGET STREQUAL "esp32s2")
idf_component_register(SRCS "touch_slider_example_main.c"
INCLUDE_DIRS ".")
else()
message(FATAL_ERROR "Touch slider example only available on esp32s2 now")
endif()
idf_component_register(SRCS "touch_slider_example_main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES touch_element)

View File

@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
def test_touch_slider(dut: Dut) -> None:
dut.expect_exact('Touch Slider Example: Touch element library installed')
dut.expect_exact('Touch Slider Example: Touch slider installed')
dut.expect_exact('Touch Slider Example: Touch slider created')
dut.expect_exact('Touch Slider Example: Touch element library start')

View File

@ -3,20 +3,45 @@
# Touch Pad Interrupt Example
## ESP32 platform
(See the README.md file in the upper level 'examples' directory for more information about examples.)
Demonstrates how to set up ESP32's capacitive touch pad peripheral to trigger interrupt when a pad is touched. It also shows how to detect the touch event by the software for sensor designs when greater touch detection sensitivity is required.
This example demonstrates how to set up ESP32's capacitive touch pad peripheral to trigger interrupt when a pad is touched. It also shows how to detect the touch event by software for sensor designs where greater touch detection sensitivity is required.
- The hardware interrupt mode occupies less CPU resources, but we can only apply fixed threshold and software algorithms are also impossibile.
- The polling mode is flexible and supports various software algorithms. However, it comsumes more CPU.
ESP32 supports touch detection by configuring hardware registers. The hardware periodically detects the pulse counts. If the number of pulse counts exceeds the set threshold, a hardware interrupt will be generated to notify the application layer that a certain touch sensor channel may be triggered.
For the sensor designs when the pad is covered a glass or plastic, the difference caused by a 'touch' action could be very small. In such a case we are using software pooling and algorithms to reduce noise to still be able to detect small changes of the pulse counts. In certain cases we may need to use additional routines to adjust the threshold level dynamically as it may change depending on environment conditions.
For the sensors covered with glass or plastic, the capacitance difference caused by a touch action could be very small. In such cases, software polling is used so software algorithms can be applied to reduce noise and catch small changes of the pulse counts. In certain cases, we may need to add additional routines to adjust the threshold level dynamically as it may change depending on environment conditions.
Comparison of the two modes:
For a simpler example how to configure and read capacitive touch pads, please refer to [touch_pad_read](../touch_pad_read).
- The hardware interrupt mode occupies less CPU resources, but only a single threshold can be set and cannot support various software algorithms.
- The continuous pooling is flexible and supports various software algorithms. However, it also costs CPU overhead
## How to use example
The application is cycling between the interrupt mode and the pooling mode with a filter, to compare performance of the touch sensor system in both scenarios:
### Hardware Required
* A development board with ESP32 chip
* Proper touch sensor system
For hardware and firmware design guidelines on ESP32 touch sensor system, please refer to [Touch Sensor Application Note](https://github.com/espressif/esp-iot-solution/blob/release/v1.1/documents/touch_pad_solution/touch_sensor_design_en.md), where you may find comprehensive information on how to design and implement touch sensing applications, such as linear slider, wheel slider, matrix buttons and spring buttons.
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
```
(Replace PORT with the name of the serial port to use.)
(To exit the serial monitor, type ``Ctrl-]``.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
## Example Output
The application cycles between the interrupt mode and the pooling mode with a filter, to compare performance of the touch sensor system between both scenarios:
```
I (6303) Touch pad: Waiting for any pad being touched...
@ -33,12 +58,8 @@ I (17903) Touch pad: Waiting for any pad being touched...
I (22903) Touch pad: Waiting for any pad being touched...
```
Note: Sensing threshold is set up automatically at start up by performing simple calibration. Application is reading current value for each pad and assuming two thirds of this value as the sensing threshold. Do not touch pads on application start up, otherwise sensing may not work correctly.
## Troubleshooting
## Reference Information
Sensing threshold is set up automatically at start up by performing simple calibration. Application is reading current value for each pad and assuming two thirds of this value as the sensing threshold. Do not touch pads on application start up, otherwise sensing may not work correctly.
For a simpler example how to configure and read capacitive touch pads, please refer to [touch_pad_read](../touch_pad_read).
Design and implementation of the touch sensor system is a complex process. The [Touch Sensor Application Note](https://github.com/espressif/esp-iot-solution/blob/release/v1.0/documents/touch_pad_solution/touch_sensor_design_en.md) contains several ESP32 specific notes and comments to optimize the design and get the best out of the application with sensors controlled with the ESP32.
See the README.md file in the upper level 'examples' directory for more information about examples.
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
@ -165,5 +165,5 @@ void app_main(void)
// Register touch interrupt ISR
touch_pad_isr_register(tp_example_rtc_intr, NULL);
// Start a task to show what pads have been touched
xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL);
xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 4096, NULL, 5, NULL);
}

View File

@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.esp32
@pytest.mark.generic
def test_touch_pad_interrupt_v1(dut: Dut) -> None:
dut.expect_exact('Touch pad: Initializing touch pad')
dut.expect(r'test init: touch pad \[\d+\] val is \d+')
dut.expect_exact('Touch pad: Waiting for any pad being touched...')
dut.expect_exact('Touch pad: Change mode...filter mode')
dut.expect_exact('Touch pad: Waiting for any pad being touched...')

View File

@ -3,15 +3,43 @@
# Touch Pad Read Example
## ESP32 plaform
(See the README.md file in the upper level 'examples' directory for more information about examples.)
Read and display raw values or IIR filtered values from capacitive touch pad sensors.
Read and print raw values or IIR filtered values from capacitive touch sensors.
Once configured, ESP32 is continuously measuring capacitance of touch pad sensors. Measurement is reflected as numeric value inversely related to sensor's capacitance. The capacitance is bigger when sensor is touched with a finger and the measured value smaller. In opposite situation, when finger is released, capacitance is smaller and the measured value bigger.
Once configured, ESP32 will continuously measure capacitance of touch pad sensors. Measurement is reflected as numeric value inversely related to sensor's capacitance. With a finger touched on a pad, its capacitance will get larger meanwhile the measured value gets smaller, and vice versa.
To detect when a sensor is touched and when not, each particular design should be calibrated by obtaining both measurements for each individual sensor. Then a threshold between both values should be established. Using specific threshold, API is then able to distinguish whether specific sensor is touched or released.
To detect if a sensor is touched or not, each particular design should be calibrated by obtaining both measurements for each individual sensor. Then a threshold between both values can be established. With specific threshold, API is then able to distinguish whether specific sensor is touched or released.
ESP32 supports reading up to ten capacitive touch pad sensors T0 - T9, connected to specific GPIO pins. For information on available pins please refer to [Technical Reference Manual](https://espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf). Application initializes all ten sensor pads. Then in a loop reads sensors T0 - T9 and displays obtained values (after a colon) on a serial terminal:
There is another similar example that demonstrates how to perform simple calibration and trigger an interrupt when a pad is touched - see [touch_pad_interrupt](../touch_pad_interrupt).
## How to use example
### Hardware Required
* A development board with ESP32 chip
* Proper touch sensor system
For hardware and firmware design guidelines on ESP32 touch sensor system, please refer to [Touch Sensor Application Note](https://github.com/espressif/esp-iot-solution/blob/release/v1.1/documents/touch_pad_solution/touch_sensor_design_en.md), where you may find comprehensive information on how to design and implement touch sensing applications, such as linear slider, wheel slider, matrix buttons and spring buttons.
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
```
(Replace PORT with the name of the serial port to use.)
(To exit the serial monitor, type ``Ctrl-]``.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
## Example Output
ESP32 supports up to ten capacitive touch pad sensors, T0 - T9, which are connected to specific GPIO pins. For the information about touch sensor capable pins, please refer to [Technical Reference Manual](https://espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf). This example will initialize all the 10 touch pads, and print the measured values to serial terminal:
```
Touch Sensor filter mode read, the output format is:
@ -22,10 +50,6 @@ T0:[1072,1071] T1:[ 475, 475] T2:[1003,1003] T3:[1231,1231] T4:[1676,1676] T5:[1
T0:[1071,1071] T1:[ 475, 475] T2:[1004,1004] T3:[1231,1231] T4:[1678,1677] T5:[1147,1146] T6:[1607,1607] T7:[1118,1118] T8:[1694,1694] T9:[1222,1221]
```
## Reference Information
## Troubleshooting
For hardware and firmware design guidelines on ESP32 touch sensor system, please refer to [Touch Sensor Application Note](https://github.com/espressif/esp-iot-solution/blob/release/v1.0/documents/touch_pad_solution/touch_sensor_design_en.md), where you may find comprehensive information on how to design and implement touch sensing applications, such as linear slider, wheel slider, matrix buttons and spring buttons.
There is another similar example that demonstrates how to perform simple calibration and trigger an interrupt when a pat is touched - see [touch_pad_interrupt](../touch_pad_interrupt).
See the README.md file in the upper level 'examples' directory for more information about examples.
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
@ -66,5 +66,5 @@ void app_main(void)
touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD);
#endif
// Start task to read values sensed by pads
xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL);
xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 4096, NULL, 5, NULL);
}

View File

@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.esp32
@pytest.mark.generic
def test_touch_pad_read_v1(dut: Dut) -> None:
dut.expect_exact('Touch Sensor filter mode read, the output format is:')
dut.expect(r'T0:\[\s*\d+,\s*\d+\] T1:\[\s*\d+,\s*\d+\] T2:\[\s*\d+,\s*\d+\] T3:\[\s*\d+,\s*\d+\] T4:\[\s*\d+,\s*\d+\]'
r' T5:\[\s*\d+,\s*\d+\] T6:\[\s*\d+,\s*\d+\] T7:\[\s*\d+,\s*\d+\] T8:\[\s*\d+,\s*\d+\] T9:\[\s*\d+,\s*\d+\]')

View File

@ -3,13 +3,41 @@
# Touch Pad Interrupt Example
## ESP32-S2, ESP32-S3 platform
(See the README.md file in the upper level 'examples' directory for more information about examples.)
Demonstrates how to set up ESP32-S2's capacitive touch pad peripheral to trigger interrupt when a pad is touched. It also shows how to detect the touch event by the software for sensor designs when greater touch detection sensitivity is required.
This example demonstrates how to set up ESP32-S2/S3's capacitive touch pad peripheral to trigger interrupt when a pad is touched. It also shows how to detect the touch event by the software for sensor designs when greater touch detection sensitivity is required.
ESP32-S2 supports touch detection by configuring hardware registers. The hardware periodically detects the pulse counts. If the number of pulse counts exceeds the set threshold, a hardware interrupt will be generated to notify the application layer that a certain touch sensor channel may be triggered.
- The hardware interrupt mode occupies less CPU resources, but we can only apply fixed threshold and software algorithms are also impossibile.
- The polling mode is flexible and supports various software algorithms. However, it comsumes more CPU.
The application is cycling between the interrupt mode and the pooling mode with a filter, to compare performance of the touch sensor system in both scenarios:
ESP32-S2/S3 supports touch detection by configuring hardware registers. The hardware periodically detects the pulse counts. If the number of pulse counts exceeds the set threshold, a hardware interrupt will be generated to notify the application layer that a certain touch sensor channel may be triggered.
For a simpler example how to configure and read capacitive touch pads, please refer to [touch_pad_read](../touch_pad_read).
## How to use example
### Hardware Required
* A development board with ESP32-S2 or ESP32-S3 chip
* A touch extension board like [esp32-s2-touch-devkit-1](https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp32s2/esp32-s2-touch-devkit-1/user_guide.html)
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
```
(Replace PORT with the name of the serial port to use.)
(To exit the serial monitor, type ``Ctrl-]``.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
## Example Output
The application cycles between the interrupt mode and the pooling mode with a filter, to compare performance of the touch sensor system between both scenarios:
```
I (304) Touch pad: Initializing touch pad
@ -27,10 +55,6 @@ W (6174) Touch pad: TouchSensor [13] be actived, exit guard mode
I (6194) Touch pad: TouchSensor [9] be inactived, status mask 0x0
```
## Reference Information
## Troubleshooting
For a simpler example how to configure and read capacitive touch pads, please refer to [touch_pad_read](../touch_pad_read).
Design and implementation of the touch sensor system is a complex process. The [Touch Sensor Application Note](https://github.com/espressif/esp-iot-solution/blob/release/v1.0/documents/touch_pad_solution/touch_sensor_design_en.md) contains several ESP32 specific notes and comments to optimize the design and get the best out of the application with sensors controlled with the ESP32.
See the README.md file in the upper level 'examples' directory for more information about examples.
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.

View File

@ -208,5 +208,5 @@ void app_main(void)
touch_pad_fsm_start();
// Start a task to show what pads have been touched
xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL);
xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 4096, NULL, 5, NULL);
}

View File

@ -0,0 +1,15 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
def test_touch_pad_interrupt_v2(dut: Dut) -> None:
dut.expect_exact('Touch pad: Initializing touch pad')
dut.expect_exact('Touch pad: Denoise function init')
dut.expect_exact('Touch pad: touch pad waterproof init')
dut.expect_exact('Touch pad: touch pad filter init')
dut.expect(r'touch pad \[\d+\] base \d+, thresh \d+')

View File

@ -3,15 +3,38 @@
# Touch Pad Read Example
## ESP32-S2, ESP32-S3 platform
(See the README.md file in the upper level 'examples' directory for more information about examples.)
Read and display raw values from capacitive touch pad sensors.
Once configured, ESP32-S2 is continuously measuring capacitance of touch pad sensors. Measurement is reflected as numeric value inversely related to sensor's capacitance. The capacitance is bigger when sensor is touched with a finger and the measured value bigger. In opposite situation, when finger is released, capacitance is smaller and the measured value smaller.
Once configured, ESP32S2/S3 will continuously measure capacitance of touch pad sensors. Measurement is reflected as numeric value inversely related to sensor's capacitance. With a finger touched on a pad, its capacitance will get larger meanwhile the measured value gets smaller, and vice versa.
To detect when a sensor is touched and when not, each particular design should be calibrated by obtaining both measurements for each individual sensor. Then a threshold between both values should be established. Using specific threshold, API is then able to distinguish whether specific sensor is touched or released. For ESP32-S2, the hardware integrates the edge detection algorithm, which can achieve the purpose of detecting touch actions by configuring appropriate parameters. Please find the example in [touch_pad_interrupt](../touch_pad_interrupt).
To detect if a sensor is touched or not, each particular design should be calibrated by obtaining both measurements for each individual sensor. Then a threshold between both values can be established. With specific threshold, API is then able to distinguish whether specific sensor is touched or released. For ESP32-S2/S3, the hardware integrates the edge detection algorithm, which can achieve the purpose of detecting touch actions by configuring appropriate parameters. There is another similar example that demonstrates how to perform simple calibration and trigger an interrupt when a pad is touched - see [touch_pad_interrupt](../touch_pad_interrupt).
ESP32-S2 supports reading up to 14 capacitive touch pad sensors T1 - T14, connected to specific GPIO pins. For information on available pins please refer to ESP32-S2 Technical Reference Manual. T0 is the internal denoise channel used to filter out system noise and there is no corresponding external GPIO. Application initializes 14 sensor pads. Then in a loop reads sensors T1 - T14 and displays obtained values (after a colon) on a serial terminal:
## How to use example
### Hardware Required
* A development board with ESP32-S2 or ESP32-S3 chip
* A touch extension board like [esp32-s2-touch-devkit-1](https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp32s2/esp32-s2-touch-devkit-1/user_guide.html)
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
```
(Replace PORT with the name of the serial port to use.)
(To exit the serial monitor, type ``Ctrl-]``.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
## Example Output
ESP32-S2/S3 supports up to 14 capacitive touch pads, T1 - T14, which are connected to the specific GPIO pins. For the information of available pins please refer to ESP32-S2/S3 Technical Reference Manual. Note that T0 is an internal channel with no corresponding GPIO, it is mainly used for de-noise. This example will initialize all the 14 touch pads. The raw values of each pad can be monitored in the terminal:
```
Touch Sensor read, the output format is:
@ -22,10 +45,6 @@ T1: [6463] T2: [6512] T3: [6643] T4: [8920] T5: [9050] T6: [7191] T7: [7176] T8:
T1: [6476] T2: [6508] T3: [6641] T4: [8919] T5: [9053] T6: [7190] T7: [7177] T8: [7416] T9: [7143] T10: [7386] T11: [7974] T12: [7776] T13: [8153] T14: [8193]
```
## Reference Information
## Troubleshooting
For hardware and firmware design guidelines on ESP32 touch sensor system, please refer to [Touch Sensor Application Note](https://github.com/espressif/esp-iot-solution/blob/release/v1.0/documents/touch_pad_solution/touch_sensor_design_en.md), where you may find comprehensive information on how to design and implement touch sensing applications, such as linear slider, wheel slider, matrix buttons and spring buttons.
There is another similar example that demonstrates how to perform simple calibration and trigger an interrupt when a pat is touched - see [touch_pad_interrupt](../touch_pad_interrupt).
See the README.md file in the upper level 'examples' directory for more information about examples.
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.

View File

@ -85,5 +85,5 @@ void app_main(void)
touch_pad_fsm_start();
/* Start task to read values by pads. */
xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL);
xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 4096, NULL, 5, NULL);
}

View File

@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
def test_touch_pad_read_v2(dut: Dut) -> None:
dut.expect_exact('touch read: Denoise function init')
dut.expect(r'T1: \[\d+\] T2: \[\d+\] T3: \[\d+\] T4: \[\d+\] T5: \[\d+\] T6: \[\d+\] T7: \[\d+\] T8: \[\d+\] T9: \[\d+\]'
r' T10: \[\d+\] T11: \[\d+\] T12: \[\d+\] T13: \[\d+\] T14: \[\d+\]')