# Touch Sensor

{% embed url="<https://youtu.be/wDd5okeHDMA>" %}

## Function introduction

The sensor contains two touch parts (left and right) and can detect changes in capacitance when a finger approaches. This means the touch sensor will output a high level whether your finger touches lightly or presses hard. You can realize the function you want by judging the detected value (1 for high level, 0 for low level).

<figure><img src="/files/kuyISSQUAdiuYuQmMgTe" alt=""><figcaption></figcaption></figure>

## BiBoard

### Hardware setup

#### BiBoard V1 for Bittle X V2 / Bittle X+Arm / Nybble Q

<figure><img src="/files/QJOZnyDYDLc4nAmmg0ho" alt="" width="375"><figcaption></figcaption></figure>

#### BiBoard V0 for Bittle X

<figure><img src="/files/yJFecILCdOlTxDzsSQh2" alt=""><figcaption></figcaption></figure>

For specific use, the end connected to the sensor can be fixed on the robot's head (included in Bittle's mouth or attached to the top of Nybble's head). Of course, you can also use your creativity according to your needs.

### Software setup

#### Petoi Desktop App

* You can use the [Firmware Uploader](https://guide.petoi.com/desktop-app/firmware-uploader#select-the-correct-options-to-upload-the-latest-firmware) within the Petoi Desktop App.

  Please select the correct ***Product*** type, ***Borard version***, and ***Serial port***. The mode should be **Standard**, so press the **Upgrade the Firmware** button. for example, Bittle, BiBoard\_V0\_2, COM5 as follows:

  <figure><img src="/files/WPPvzmmwwt6bVG1wDOoG" alt=""><figcaption></figcaption></figure>

  After uploading,  [open the serial monitor](https://guide.petoi.com/arduino-ide/serial-monitor) and use the serial command "***XT***" to switch to using the touch sensor mode.

#### Arduino IDE

* You can use [Arduino IDE](https://www.arduino.cc/en/software) to [upload the sketch](https://guide.petoi.com/arduino-ide/upload-sketch-for-biboard#id-2.-set-up-biboard)(***OpenCatEsp32.ino***).&#x20;

  Use the latest OpenCatESP32 code to finish the setup. For example,  to modify the code for ***Bittle*** as shown below:<br>

  <figure><img src="/files/5vX8SspsC7PHdkYCZkE3" alt=""><figcaption></figcaption></figure>

  After uploading,  [open the serial monitor](https://guide.petoi.com/arduino-ide/serial-monitor) and use the serial command "***XT***" to switch to using the touch sensor mode.

#### Arduino module test code

The test code is in the **OpenCatESP32** project source code ([ModuleTests/testDoubleTouch](https://github.com/PetoiCamp/OpenCatEsp32/blob/main/ModuleTests/testDoubleTouch/testDoubleTouch.ino))

#### Mind+ Demo code

<https://github.com/PetoiCamp/Petoi_MindPlusLib/blob/main/examples/BiBoard/DoubleTouch_BiBoard.mp>

## NyBoard for Bittle / Nybble

### Hardware setup

Connecting to the NyBoard with wire as shown in the following picture, connect to the NyBoard Grove interface, which includes D6, D7:

<figure><img src="/files/CLgYeIm1oP2PBFHENdBo" alt=""><figcaption></figcaption></figure>

### Software setup

#### Petoi Desktop App

* You can use the [Firmware Uploader ](https://guide.petoi.com/desktop-app/firmware-uploader#select-the-correct-options-to-upload-the-latest-firmware)within the Petoi Desktop App.\
  Please select the correct ***Product*** type, ***Borard version***, and ***Serial port***. The mode should be **Touch**, so press the **Upgrade the Firmware** button. for example, Nybble, NyBoard\_V1\_2, COM5 as follows:

<figure><img src="/files/xcDGqAtDKQQ0U7Xib2IK" alt=""><figcaption></figcaption></figure>

#### Arduino IDE

* You can use [Arduino IDE](https://www.arduino.cc/en/software) to upload and modify the source code.&#x20;

The code using this sensor has been integrated into the [**OpenCat**](https://github.com/PetoiCamp/OpenCat) project. Uncomment the line **`#define DOUBLE_TOUCH`**  in the **OpenCat.ino**, as shown in the figure below, use the Arduino IDE to upload the sketch to the robot main board, which can reproduce the example function of integrating the robot action.

#### Prepare the Arduino UNO development environment.

With **NyBoard V1\_\***, you can choose **Arduino Uno**.&#x20;

<figure><img src="/files/4JBNM8f9Sdm40i7VCH7O" alt=""><figcaption></figcaption></figure>

For example,  to modify the code for ***Bittle*** as shown below:

<figure><img src="/files/GiQdQ9peny9sQHUM6qwD" alt=""><figcaption></figcaption></figure>

#### Arduino module test code

If you want to test a touch sensor's function alone or learn more about its principles. You can use the Arduino IDE to upload the test code(**testDoubleTouch.ino**):

The test code is in the **OpenCat** project source code ([ModuleTests/testDoubleTouch](https://github.com/PetoiCamp/OpenCat/blob/main/ModuleTests/testDoubleTouch/testDoubleTouch.ino))

This demo sketch implements real-time printing of the detection values of D6 and D7 pins in the [serial monitor](https://guide.petoi.com/arduino-ide/serial-monitor):&#x20;

<figure><img src="/files/PEGVDmPvm2jIKR2xKRdz" alt=""><figcaption></figcaption></figure>

#### Mind+ Demo

1. &#x20;You can upload the firmware via the Petoi Desktop App:

   ![](/files/C941rKUVkO5wd6kEIJsE)

{% hint style="info" %}
Or you can upload the **OpenCat.ino** as follows, uncomment the line **`#define GROVE_SERIAL_PASS_THROUGH`** in the **OpenCat.ino:**

<img src="/files/lcwY9gQHVogAwA6pPBx5" alt="" data-size="original">
{% endhint %}

{% hint style="success" %}
For BiBoard, you can skip this step.
{% endhint %}

&#x20;2\.    Follow [the instructions](https://guide.petoi.com/block-based-programming/petoi-coding-blocks#import-petoi-mind-extension-library) to import the Petoi Coding Blocks in the app **Mind+**, and load the Mind+ code file.

3. &#x20;Connect the robot and computer with the [USB adapter](https://guide.petoi.com/communication-modules/usb-downloader-ch340c)(USB uploader) or [Bluetooth module](https://guide.petoi.com/communication-modules/dual-mode-bluetooth).
4. &#x20;Power on the robot and click the **Run** button ![](/files/IgSx3kYHC78aLZ9jc6hK) in **Mind+.**<br>

<figure><img src="/files/XqtnOq2plFTEdQXzwcxI" alt=""><figcaption></figcaption></figure>

#### Mind+ Demo code

<https://github.com/PetoiCamp/Petoi_MindPlusLib/blob/main/examples/NyBoard/DoubleTouch_NyBoard.mp>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guide.petoi.com/extensible-modules/touch-sensor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
