The Capacitive Sensor low-level library provides support for power-efficient capacitive sensing.
The number of supported capacitive pads is equal to the number of available analog channels – 8.
This library has two different implementations, depending on whether you want to use the COMP module:
Despite the two different implementations, the library uses the same API in both cases. To choose the implementation of this library, change the value of USE_COMP.
When using the implementation involving SAADC, the module measures voltage on the pad that is touched. An additional pin is needed to charge the pad through a resistor. On every measurement, the pad is charged and then discharged using the SAADC module. If the pad is touched during measurement, its capacitance is higher. This is detected by ADC which receives a greater value of the measured voltage. Therefore, to set up this solution, you must know the value of the ADC measurement when the pad is idle to decide when it is touched.
When using the implementation involving COMP, ISOURCE is used. For details, refer to Capacitive sensing.
You can create only one instance of this library. Additionally, the number of channels is limited to the number of analog channels, which is eight.
Depending on the selected implementation, the library uses the following resources:
For SAADC implementation:
For COMP implementation:
Because the COMP implementation uses a different method for detecting touch, it requires a different hardware setup than when using SAADC.
The following example setup shows how to connect two pads while using the COMP implementation:
When using SAADC, you need an additional resistor for charging capacitors connected to the pads:
Set the values of the resistor in such a way that the pad is charged during every single measurement period. It means that the resistor's values should be around 100k ohms when using GPIO as the charge source (typically 3V3 in high state).
There are two functions that you must run before you can start working with this library.
First, you must initialize the module. If you are using the SAADC implementation, the only required configuration is to provide the number of the output pin that will be used to charge the pads. For the COMP implementation, initialize the module without specifying any additional configuration parameters.
After the module is initialized, all channels are automatically disabled. To enable the channels, you must run the function nrf_drv_csense_channels_enable. After that, you can start the measurement by calling nrf_drv_csense_sample.
You can now start working with the module. Every time you call the nrf_drv_csense_sample function, the conversion of all enabled channels is performed. You can read the result through a handler or at any time after the conversion. However, data is overwritten after each conversion, so it can be read only until the next conversion.
See the Capacitive Sensor Low-level Example for a full example that uses the Capacitive Sensor low-level library.