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!")