ProtoCentral FDC2214 capacitance-to-digital converter breakout board
====================================================================

Arduino library for the [ProtoCentral FDC2214 breakout board](https://protocentral.com/), a 4-channel, 28-bit capacitance-to-digital converter from Texas Instruments.

The FDC2214 measures capacitance by sensing the resonant frequency of an external LC tank attached to each channel. This makes it well suited to:

- Proximity / touch sensing
- Gesture detection
- Liquid level sensing (contact and non-contact)
- Material analysis (e.g. fluid identification)
- Metal / thickness detection
- Position / displacement sensing

## Hardware Setup

The ProtoCentral breakout pulls the ADDR pin HIGH on-board, so the default I2C address is `0x2B`. Tying ADDR to GND selects `0x2A`.

| FDC2214 pin | Arduino connection | Function       |
|:-----------:|:------------------:|:--------------:|
| GND         | GND                | Ground         |
| VCC         | 3.3V               | Power          |
| SDA         | A4 (Uno) / SDA     | I²C data       |
| SCL         | A5 (Uno) / SCL     | I²C clock      |
| ADDR        | GND or VDD         | Address select |
| INTB        | (optional) any GPIO| Data-ready IRQ |

Each `INxA / INxB` pair connects to your sensor LC tank. Refer to the datasheet in `docs/` for tank design guidelines.

## Quick start

```cpp
#include <Wire.h>
#include <Protocentral_FDC2214.h>

FDC2214 fdc;

void setup() {
    Serial.begin(115200);
    Wire.begin();

    if (!fdc.begin()) {
        Serial.println("FDC2214 not found");
        while (1);
    }

    fdc.configureDefaults();
    fdc.setAutoscan(true, FDC2214_RR_SEQ_ALL);
    fdc.start();
}

void loop() {
    for (uint8_t ch = 0; ch < 4; ch++) {
        uint32_t raw = fdc.readRawChannel((fdc2214_channel_t)ch);
        float    f   = fdc.readFrequencyHz((fdc2214_channel_t)ch);
        Serial.print("CH"); Serial.print(ch);
        Serial.print(": raw="); Serial.print(raw);
        Serial.print("  f="); Serial.print(f / 1.0e6f, 4); Serial.println(" MHz");
    }
    delay(200);
}
```

## API summary

| Method                                          | Purpose                                         |
|-------------------------------------------------|-------------------------------------------------|
| `begin()` / `isConnected()`                     | Verify Manufacturer/Device ID                   |
| `configureDefaults()`                           | Sensible defaults for capacitive sensing        |
| `setReferenceCount`, `setSettleCount`           | Per-channel timing                              |
| `setClockDividers`, `setDriveCurrent`           | Per-channel input path and tank drive           |
| `setActiveChannel`, `setAutoscan`, `setDeglitch`| Sequencing and noise filter                     |
| `start()` / `stop()`                            | Wake / put device to sleep                      |
| `readRawChannel`                                | 28-bit raw data                                 |
| `readFrequencyHz`                               | Sensor frequency in Hz                          |
| `readCapacitancePf(ch, L_uH)`                   | Capacitance in pF given inductance in µH        |
| `readRegister`, `writeRegister`                 | Raw register access                             |

## Examples

| Example                       | What it shows                                                      |
|-------------------------------|--------------------------------------------------------------------|
| `01_DeviceInfo`               | I²C bus scan + Manufacturer/Device ID readback                     |
| `02_SingleChannel`            | Single-channel mode on CH0, prints raw + frequency                 |
| `03_MultiChannelAutoScan`     | All 4 channels via autoscan                                        |
| `04_Capacitance`              | Convert frequency to picofarads using a known LC tank inductor     |
| `05_ProximitySensing`         | Auto-baseline + threshold trip for proximity/touch                 |
| `06_LiquidLevel`              | Two-channel differential reading for liquid-level estimation       |

## License

Software MIT, hardware CERN-OHL-P v2, documentation CC BY-SA 4.0 — see [`LICENSE.md`](LICENSE.md).
