Decoupled Analog TDS/Electrical Conductivity (EC) sensor driver for Raspberry Pi Pico/Pico 2 C SDK with persistent flash calibration.
- C 87.4%
- CMake 12.6%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .gitignore | ||
| CMakeLists.txt | ||
| example.c | ||
| pico_sdk_import.cmake | ||
| README.md | ||
| tds_ec.c | ||
| tds_ec.h | ||
lf-tds-ec
A reusable, self-contained TDS (Total Dissolved Solids) and EC (Electrical Conductivity) sensor driver library for the Raspberry Pi Pico / Pico 2 (RP2040 and RP2350 microcontrollers) using the Pico C SDK.
Features
- Averaged ADC Reads: Reads and averages 30 samples to filter out electrical noise from the analog breakout board.
- Third-Order Polynomial Conversion: Maps the non-linear relationship of voltage to raw Electrical Conductivity (
\mu\text{S/cm}). - Temperature Compensation (2% per °C): Adjusts conductivity readings according to temperature relative to a standard
25^\circ\text{C}baseline. - Persistent Calibration (Flash-Based): Automatically loads and saves the probe's calibration factor (
K) to the final 4KB sector of the Pico's external QSPI flash, keeping it safe across reboots.
Pinout & Connections
Make sure to power the transmitter board with 3.3\text{V} (Pico's 3V3 OUT pin), so the analog output does not exceed the Pico's ADC range.
| TDS Breakout Pin | Pico GPIO Pin | Description |
|---|---|---|
| + | 3V3 OUT | 3.3V Power input |
| - | GND | Power Ground (0V) |
| A | GP26 (ADC0) | Analog output representing EC (Default in example) |
Standalone Compilation
To compile the standalone example project:
mkdir build
cd build
cmake -DPICO_PLATFORM=rp2350 -DPICO_BOARD=pico2 ..
make
Flash the generated tds_ec_example.uf2 binary to your Pico 2.
Integrating as a Submodule / Subdirectory
You can drop this repository into your project directory (e.g. under drivers/lf-tds-ec) and add it to your root CMakeLists.txt:
add_subdirectory(drivers/lf-tds-ec)
target_link_libraries(my_project_name
lf_tds_ec
)
This registers the static library target lf_tds_ec and handles header include paths automatically.