edit

Grove - Touch Sensor

Grove - Touch Sensor enables you to replace press with touch. It can detect the change in capacitance when a finger is near by. That means no matter your finger directly touches the pad or just stays close to the pad, Grove - Touch Sensor would outputs HIGH also.

Specifications

  • Operating Voltage: 2.0 - 5.5V
  • Operating Current(Vcc=3V):1.5 - 3.0μA
  • Operating Current(VDD=3V):3.5 - 7.0μA
  • Output Response Time: 60 - 220mS
  • Used Chipset: TTP223-BA6

Tip

More details about Grove modules please refer to Grove System

Platforms Supported

Arduino Raspberry Pi BeagleBone Wio LinkIt ONE

Caution

The platforms mentioned above as supported is/are an indication of the module's hardware or theoritical compatibility. We only provide software library or code examples for Arduino platform in most cases. It is not possible to provide software library / demo code for all possible MCU platforms. Hence, users have to write their own software library.

Option features

AHLB TOG LPMB MOTB SLRFTB RST Q OPDO
Output Active High / Low Toggle mode Power Mode Max. On Time Sampling length RESET PIN CMOS Output Open Drain Mode
V V 0 1 1 X V X
Active High Disabled LOW Infinite 1.6 msec N/A Present N/A

Getting started

Play with Arduino

This demo is going to show you how to turn on/off an LED.

Hardware

  • Step 1. Prepare the below stuffs:
Seeeduino V4.2 Base Shield Grove-Touch_Sensor Grove-LED
enter image description here enter image description here enter image description here enter image description
Get One Now Get One Now Get One Now Get One Now
  • Step 2. Connect Grove-Touch_Sensor to port D2 of Grove-Base Shield.
  • Step 3. Connect Grove-LED to port D3 of Grove-Base Shield.
  • Step 4. Plug Grove - Base Shield into Seeeduino.
  • Step 5. Connect Seeeduino to PC via a USB cable.

with_ardu

Software

  • Step 1. Please copy and paste code below to a new Arduino sketch.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    const int TouchPin=2;
    const int ledPin=3;
    
    void setup() {
        pinMode(TouchPin, INPUT);
        pinMode(ledPin,OUTPUT);
    }
    
    void loop() {
        int sensorValue = digitalRead(TouchPin);
        if(sensorValue==1)
        {
            digitalWrite(ledPin,HIGH);
        }
        else
        {
            digitalWrite(ledPin,LOW);
        }
    }
    
    Step 2. Monitor the led on and off.

Play With Raspberry Pi (With Grove Base Hat for Raspberry Pi)

Hardware

  • Step 1. Things used in this project:
Raspberry pi Grove Base Hat for RasPi Grove - Touch Sensor
enter image description here enter image description here enter image description here
Get ONE Now Get ONE Now Get ONE Now
  • Step 2. Plug the Grove Base Hat into Raspberry.
  • Step 3. Connect the touch sensor to port 12 of the Base Hat.
  • Step 4. Connect the Raspberry Pi to PC through USB cable.

Note

For step 3 you are able to connect the touch sensor to any GPIO Port but make sure you change the command with the corresponding port number.

Software

  • Step 1. Follow Setting Software to configure the development environment.
  • Step 2. Download the source file by cloning the grove.py library.
1
2
cd ~
git clone https://github.com/Seeed-Studio/grove.py
  • Step 3. Excute below commands to run the code.
1
2
cd grove.py/grove
python grove_touch_sensor.py 12

Following is the grove_touch_sensor.py code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import time
from grove.gpio import GPIO


class GroveTouchSensor(GPIO):
    def __init__(self, pin):
        super(GroveTouchSensor, self).__init__(pin, GPIO.IN)
        self._last_time = time.time()

        self._on_press = None
        self._on_release = None

    @property
    def on_press(self):
        return self._on_press

    @on_press.setter
    def on_press(self, callback):
        if not callable(callback):
            return

        if self.on_event is None:
            self.on_event = self._handle_event

        self._on_press = callback

    @property
    def on_release(self):
        return self._on_release

    @on_release.setter
    def on_release(self, callback):
        if not callable(callback):
            return

        if self.on_event is None:
            self.on_event = self._handle_event

        self._on_release = callback

    def _handle_event(self, pin, value):
        t = time.time()
        dt, self._last_time = t - self._last_time, t

        if value:
            if callable(self._on_press):
                self._on_press(dt)
        else:
            if callable(self._on_release):
                self._on_release(dt)

Grove = GroveTouchSensor


def main():
    import sys

    if len(sys.argv) < 2:
        print('Usage: {} pin'.format(sys.argv[0]))
        sys.exit(1)

    touch = GroveTouchSensor(int(sys.argv[1]))

    def on_press(t):
        print('Pressed')
    def on_release(t):
        print("Released.")

    touch.on_press = on_press
    touch.on_release = on_release

    while True:
        time.sleep(1)


if __name__ == '__main__':
    main()

Success

If everything goes well, you will be able to see the following result

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
pi@raspberrypi:~/grove.py/grove $ python grove_touch_sensor.py 12
Pressed
Released.
Pressed
Released.
Pressed
Released.
Pressed
Released.
^CTraceback (most recent call last):
  File "grove_touch_sensor.py", line 110, in <module>
    main()
  File "grove_touch_sensor.py", line 106, in main
    time.sleep(1)
KeyboardInterrupt

You can quit this program by simply press Ctrl+C.

Play With Raspberry Pi (with GrovePi_Plus)

Hardware

  • Step 1. Prepare the below stuffs:
Raspberry pi GrovePi_Plus Grove-Touch_Sensor
enter image description here enter image description here enter image description here
Get One Now Get One Now Get One Now
  • Step 2. Plug the GrovePi_Plus into Raspberry.
  • Step 3. Connect Grove-Touch_Sensor to D2 port of GrovePi_Plus.
  • Step 4. Connect the Raspberry to PC through USB cable.

with_rpi

Software

  • Step 1. Follow Setting Software to configure the development environment.
  • Step 2. Git clone the Github repository.
1
2
cd ~
git clone https://github.com/DexterInd/GrovePi.git
  • Step 3. Excute below commands to use this sensor, please change the port to from D4 to D2.
1
python grove_touch_sensor.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
#
# GrovePi Example for using the Grove Touch Sensor (http://www.seeedstudio.com/wiki/Grove_-_Touch_Sensor)
#
# The GrovePi connects the Raspberry Pi and Grove sensors.  You can learn more about GrovePi here:  http://www.dexterindustries.com/GrovePi
#
# Have a question about this example?  Ask on the forums here:  http://forum.dexterindustries.com/c/grovepi
#
'''
## License
The MIT License (MIT)
GrovePi for the Raspberry Pi: an open source platform for connecting Grove Sensors to the Raspberry Pi.
Copyright (C) 2017  Dexter Industries
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''
import time
import grovepi

# Connect the Grove Touch Sensor to digital port D2
# SIG,NC,VCC,GND
touch_sensor = 2

grovepi.pinMode(touch_sensor,"INPUT")

while True:
    try:
        print(grovepi.digitalRead(touch_sensor))
        time.sleep(.5)

    except IOError:
        print ("Error")
Here is result:

Resources

Projects

Using Grove Touch Sensor To Control Grove LED: How to connect and use Grove Touch Sensor to control Grove LED socket kit.

Touch sensor Grove module:

Tech Support

Please submit any technical issue into our forum.