Introduction

Documentation Status Discord Build Status

CircuitPython driver for the CAP1188 8-Key Capacitive Touch Sensor Breakout.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-cap1188

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-cap1188

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install adafruit-circuitpython-cap1188

Usage Example

See usage examples in the examples folder.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Documentation

For information on building library documentation, please check out this guide.

Table of Contents

Simple test

Ensure your device works with this simple test.

examples/cap1188_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import board
from adafruit_cap1188.i2c import CAP1188_I2C

i2c = board.I2C()  # uses board.SCL and board.SDA
cap = CAP1188_I2C(i2c)

# SPI setup
# from digitalio import DigitalInOut, Direction
# from adafruit_cap1188.spi import CAP1188_SPI
# spi = board.SPI()
# cs = DigitalInOut(board.D5)
# cap = CAP1188_SPI(spi, cs)

while True:
    for i in range(1, 9):
        if cap[i].value:
            print("Pin {} touched!".format(i))

Advance test

This example show the new feature included in the library allowing the possibilite the configure the averaging, cycle and sample. For reference please see Sensor Datasheet.

examples/cap118_advancedtest.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
# SPDX-FileCopyrightText: 2021 Jose David M.
# SPDX-License-Identifier: MIT

# To use in the REPL >>> import cap1188_advancetest

import board
from adafruit_cap1188.i2c import CAP1188_I2C

i2c = board.I2C()
cap = CAP1188_I2C(i2c)

print(f"Sensor Initial Configuration Values: {cap.averaging, cap.sample, cap.cycle}")

averages = (1, 2, 4, 8, 16, 32, 64, 128)
samples = ("320us", "640us", "1.28ms", "2.56ms")
cycles = ("35ms", "70ms", "105ms", "140ms")

print("Setting Up Averages")
for i in averages:
    cap.averaging = i
    print(f"Average: {cap.averaging}")

print("Setting Up Samples")
for i in samples:
    cap.sample = i
    print(f"Sample: {cap.sample}")

print("Setting Up Samples")
for i in cycles:
    cap.cycle = i
    print(f"Cycle: {cap.cycle}")

print("Done!")

adafruit_cap1188.cap1188

CircuitPython driver for the CAP1188 8-Key Capacitive Touch Sensor Breakout.

  • Author(s): Carter Nelson, Jeremiah Rose, Jose David M.

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_cap1188.cap1188.CAP1188

CAP1188 driver base, must be extended for I2C/SPI interfacing.

averaging

Samples that are taken for all active channels during the sensor cycle. All samples are taken consecutively on the same channel before the next channel is sampled and the result is averaged over the number of samples measured before updating the measured results

if CS1, CS2, and CS3 are sampled during the sensor cycle, and the AVG[2:0] bits are set to take 4 samples per channel, then the full sensor cycle will be: CS1, CS1, CS1, CS1, CS2, CS2, CS2, CS2, CS3, CS3, CS3, CS3.

cycle

The programmed cycle time is only maintained if the total averaging time for all samples is less than the programmed cycle. The AVG[2:0] bits will take priority so that if more samples are required than would normally be allowed during the cycle time, the cycle time will be extended as necessary to accommodate the number of samples to be measured.

delta_count(pin)

Return the 8 bit delta count value for the channel.

recalibrate()

Perform a self recalibration on all the pins.

recalibrate_pins(mask)

Recalibrate pins specified by bit mask.

sample

Determines the overall cycle time for all measured channels during normal operation. All measured channels are sampled at the beginning of the cycle time. If additional time is remaining, then the device is placed into a lower power state for the remaining duration of the cycle.

sensitivity

The sensitvity of touch detections. Range is 1 (least) to 128 (most).

threshold_values()

Return tuple of touch threshold values for all channels.

thresholds

Touch threshold value for all channels.

touched()

Return 8 bit value representing touch state of all pins.

touched_pins

A tuple of touched state for all pins.

class adafruit_cap1188.cap1188.CAP1188_Channel(cap1188, pin)

Helper class to represent a touch channel on the CAP1188. Not meant to be used directly.

raw_value

The raw touch measurement.

recalibrate()

Perform a self recalibration.

threshold

The touch threshold value.

value

Whether the pin is being touched or not.

adafruit_cap1188.i2c

CircuitPython I2C driver for the CAP1188 8-Key Capacitive Touch Sensor Breakout.

  • Author(s): Carter Nelson

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_cap1188.i2c.CAP1188_I2C(i2c, address=41)

Driver for the CAP1188 connected over I2C.

adafruit_cap1188.spi

CircuitPython SPI driver for the CAP1188 8-Key Capacitive Touch Sensor Breakout.

  • Author(s): Carter Nelson

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_cap1188.spi.CAP1188_SPI(spi, cs)

Driver for the CAP1188 connected over SPI.

Indices and tables