Simple test

Ensure your device works with this simple test.

examples/cap1188_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5from adafruit_cap1188.i2c import CAP1188_I2C
 6
 7i2c = board.I2C()  # uses board.SCL and board.SDA
 8# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
 9cap = CAP1188_I2C(i2c)
10
11# SPI setup
12# from digitalio import DigitalInOut, Direction
13# from adafruit_cap1188.spi import CAP1188_SPI
14# spi = board.SPI()
15# cs = DigitalInOut(board.D5)
16# cap = CAP1188_SPI(spi, cs)
17
18while True:
19    for i in range(1, 9):
20        if cap[i].value:
21            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/cap1188_advancedtest.py
 1# SPDX-FileCopyrightText: 2021 Jose David M.
 2# SPDX-License-Identifier: MIT
 3
 4# To use in the REPL >>> import cap1188_advancetest
 5
 6import board
 7from adafruit_cap1188.i2c import CAP1188_I2C
 8
 9i2c = board.I2C()  # uses board.SCL and board.SDA
10# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
11cap = CAP1188_I2C(i2c)
12
13print(f"Sensor Initial Configuration Values: {cap.averaging, cap.sample, cap.cycle}")
14
15averages = (1, 2, 4, 8, 16, 32, 64, 128)
16samples = ("320us", "640us", "1.28ms", "2.56ms")
17cycles = ("35ms", "70ms", "105ms", "140ms")
18
19print("Setting Up Averages")
20for i in averages:
21    cap.averaging = i
22    print(f"Average: {cap.averaging}")
23
24print("Setting Up Samples")
25for i in samples:
26    cap.sample = i
27    print(f"Sample: {cap.sample}")
28
29print("Setting Up Samples")
30for i in cycles:
31    cap.cycle = i
32    print(f"Cycle: {cap.cycle}")
33
34print("Done!")