B4R Code Snippet ESP32 touch capable sensing pins

SubName: ESP32 touch pins
Description: The ESP32 comes with 10 touch capable sensing pins called T0 to T9, these pins are capacitive and extremely easy to read, so easy in fact that I'm not even going to attach a photo to this post. To manipulate a touch pin, you just have to connect a breadboard jumper wire to one of the touch capable pins, in this example I'm using T0 (Touch0) which is on D4 (GPOI4). Once you have connected the wire to the D4 touch pin, you just have to touch the end of the wire with your finger and then read the results.

When you touch the pin with your finger the reading will drop. In the example below the reading drops from 89 to 8.
AppStart
Touch reading = 89
Touch reading = 89
Touch reading = 89
Touch reading = 89
Touch reading = 89
Touch reading = 89
Touch reading = 89
Touch reading = 89
Touch reading = 89
Touch reading = 89
Touch reading = 89
Touch reading = 8
Touch reading = 8
Touch reading = 8
Touch reading = 8
Touch reading = 8
Touch reading = 8
Touch reading = 8
Touch reading = 8
Touch reading = 8
Touch reading = 8
Touch reading = 87
Touch reading = 89
Touch reading = 89
Touch reading = 89
Touch reading = 89
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial

    Private touched As Int 'ignore
    Private TmrTouched As Timer
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")

    TmrTouched.Initialize("TmrTouched_Tick", 1000)
    TmrTouched.Enabled = True
End Sub

Sub TmrTouched_Tick
    RunNative("touch", Null)
    Log("Touch reading = ", touched)
End Sub

#if C
void touch (B4R::Object* unused)
{
    // Touch capable pin T0 is D4/GPIO4 on the ESP32
    b4r_main::_touched = touchRead(T0);
}
#End if

Tags: ESP32, Touch, Capable, Sensitive, GPIO, Pin, Inline, C, C++

Enjoy...
 
Last edited:

Beja

Expert
Licensed User
Thanks Pete, and never mind.. I don't know how to connect because 'am not familiar with esp32 in the first place. But thanks anyway.
 

Peter Simpson

Expert
Licensed User
Thanks Pete, and never mind.. I don't know how to connect because 'am not familiar with ESP32 in the first place. But thanks anyway.

Look at the colour legend on the top right of the image below, look for the word touch the in orange then look for orange labels on the ESP32 image. just connecting a wire to any of those pins will allow you you read the vale when you touch the other end of the wire with your finger.
tGI2F.jpg


Enjoy...
 
Top