raspi-cap
v0.0.5
Published
Raspberry Pi / Node.js module for the CAP1188 capacitive touch breakout
Downloads
4
Readme
Raspberry Pi / Node.js module for the CAP1188 capacitive touch breakout
The CAP1188 is an 8-channel capacitive touch sensor and is available in a handy breakout board. This module enables I2C communication with the chip to easily get information about which pins are being touched. It's based on Espruino CAP1188 lirrary which itself is based on the Adafruit CAP1188 Arduino libary.
Wiring
You can wire this up as follows:
| Device Pin | Pi | | ---------- | --------------------------------------------------------------- | | 1 (GND) | Ground | | 2 (VIN) | 3.3v | | 3 (SDA) | BCM 2/SDA | | 4 (SCK) | BCM 3/SCL | | RST | BCM 17 (0) Optional* |
* Any GPIO pin can be used, see Reset below.
Install
Enable I2C on the Pi
sudo raspi-config
- "Interfacing Options"
- "I2C"
- "Would you like the ARM I2C interface to be enabled?" -> "YES"
- "OK"
- "Finish"
Install this library
npm install --save https://github.com/andrewn/raspi-cap/archive/master.tar.gz
Usage
Basic usage:
const connect = require("raspi-cap").connect;
// Connect to the CAP1188 breakout.
// When it's ready, the Promise resolves
// with the CAP1188 instance
connect().then(cap1188 => {
// Returns an array of 8 items for pins C1 - C8
// true indicates a touch, false is no touch
// e.g. C6 is being touched
// [ false, false, false, false, false, true, false, false ]
const touches = cap1188.readTouches();
console.log(touches);
});
See the examples
directory for more examples.
Sensitivity
You can read and set the sensitivity using getSensitivity()
and setSensitivity(level)
where level
is a number between 0 and 7 inclusive.
0 is most sensitive and 7 is least sensitive.
See examples/cap1188-sensitivity.js
.
From the datasheet:
| Level | Sensitivity Multiplier | | ----- | ---------------------- | | 0 | 128x (most sensitive) | | 1 | 64x | | 2 | 32x (default) | | 3 | 16x | | 4 | 8x | | 5 | 4x | | 6 | 2x | | 7 | 1x (least sensitive) |
Reset
Optionally, you can connect the reset pin on the board (marked RST), to a pin on the Pi. Call the reset()
method to reinitialize the sensor which can recalibrate it instead of having to cycle the power. A Promise is returned that resolves when the board has been reset.
See this page about how to specify a pin.
In addition, the reset
event is also emitted.
var cap = require("CAP1188").connect(I2C1, { resetPin: 0 }); // using WiringPi number for BCM17
cap.reset(function () {
// the board has been reset
});
GUI
There's a tiny GUI you can run:
sudo raspi-cap-debug
It'll show red circles (🔴) for untouched pins and blue circles (🔵) for touched pins.