Virtual/Reality

Using the capacitive touch feature on the ESP32, anything conductive can become a button! We will use this button to turn the environment in the Quest 2 from passthrough, to a blue-sky environment.

What is needed

Supplies

  1. Adafruit ESP32 Feather V2T
  2. Wire
  3. Conductive tape, thread, or fabric

Tools

  • Screwdriver

Step by Step

Wire the board

On your ESP32 that is connected to the screw terminal board; find pin 27. Screw a wire or male-male connection wire to pin 27. The other end of the wire can be attached to any conductive material.

Program the ESP32

In the parameters above the Setup(), add this line:

const int TOUCH_PIN = 27;

Inside the setup block, add this line:

pinMode(TOUCH_PIN, INPUT);

Inside these loop block add this line:

BTSerial.println(touchRead(TOUCH_PIN));
delay(200);

Upload this code to the ESP32.

Turn on and off an environment in Unity

In the “ExampleCommunicator” script, create the following parameter:

public GameObject environment;

Save the script, then in Unity, drag the “Environment” game object from the hierarchy into the new “Environment” parameter in the “Example Communicator” component.

Back in the “ExampleCommunicator” script, add the following inside the “OnMessageReceived” function.

//Attempt to turn the incoming message to an integer
int touch;

if(int.TryParse(message, out touch)){
    _debugText.text = "Touch Value: " + touch;
    //Change the comparison value that works for your setup
    if(touch<50){
        environment.SetActive(true);
    }else{
        environment.SetActive(false);
    }
}

Save the script, build the project to the Quest headset, and test! 

NOTE: The sensor readings will vary on several factors, including how long the wire or conductive material is and how the ESP32 is powered (USB or battery). Some calibration will be needed.

Example tutorial by Tyler Beatty