Decoupled 1-Wire DS18B20 temperature sensor driver for Raspberry Pi Pico/Pico 2 C SDK.
- C 79.5%
- CMake 20.5%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .gitignore | ||
| CMakeLists.txt | ||
| ds18b20.c | ||
| ds18b20.h | ||
| example.c | ||
| pico_sdk_import.cmake | ||
| README.md | ||
lf-ds18b20
A reusable, interrupt-safe DS18B20 1-Wire temperature sensor driver library for the Raspberry Pi Pico / Pico 2 (RP2040 and RP2350 microcontrollers) using the Pico C SDK.
Features
- Interrupt-Safe Bit-Banging: Temporarily disables interrupts during the exact data-sampling phase of the 1-Wire protocol to prevent multicore scheduling and timer interrupts from corrupting communications.
- Maxim 1-Wire CRC-8 Checking: Validates the scratchpad data on read to guarantee temperature values are free from transmission noise.
- Decoupled & Standalone: Zero external dependencies other than standard Pico SDK packages, making it ready to be integrated into larger projects or used by itself.
Pinout & Connections
Make sure to place a 4.7\text{k}\Omega pull-up resistor between the DS18B20 data pin and the 3.3\text{V} line.
| DS18B20 Pin | Pico GPIO Pin | Description |
|---|---|---|
| VCC | 3V3 OUT | 3.3V Power supply |
| GND | GND | Ground connection |
| DQ (Data) | GP2 | 1-Wire Data line (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 ds18b20_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-ds18b20) and add it to your root CMakeLists.txt:
add_subdirectory(drivers/lf-ds18b20)
target_link_libraries(my_project_name
lf_ds18b20
)
This registers the static library target lf_ds18b20 and handles header include paths automatically.