idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
DS18x20 Component

Type-safe DS18x20 1-Wire temperature sensor driver for ESP32. More...

Namespaces

namespace  idfxx
 
namespace  idfxx::ds18x20
 DS18x20 1-Wire temperature sensor classes and utilities.
 

Classes

class  idfxx::ds18x20::device
 DS18x20 1-Wire temperature sensor device. More...
 

Enumerations

enum class  idfxx::ds18x20::family : uint8_t {
  idfxx::ds18x20::family::ds18s20 = 0x10 ,
  idfxx::ds18x20::family::ds1822 = 0x22 ,
  idfxx::ds18x20::family::ds18b20 = 0x28 ,
  idfxx::ds18x20::family::max31850 = 0x3B
}
 DS18x20 device family identifiers. More...
 
enum class  idfxx::ds18x20::resolution : uint8_t {
  idfxx::ds18x20::resolution::bits_9 = 0x1F ,
  idfxx::ds18x20::resolution::bits_10 = 0x3F ,
  idfxx::ds18x20::resolution::bits_11 = 0x5F ,
  idfxx::ds18x20::resolution::bits_12 = 0x7F
}
 DS18B20 ADC resolution configuration. More...
 

Functions

std::vector< deviceidfxx::ds18x20::scan_devices (idfxx::gpio pin, size_t max_devices=8)
 Scans for DS18x20 devices on a 1-Wire bus.
 
std::vector< thermo::millicelsius > idfxx::ds18x20::measure_and_read_multi (std::span< const device > devices)
 Measures and reads temperatures from multiple devices.
 
result< std::vector< device > > idfxx::ds18x20::try_scan_devices (idfxx::gpio pin, size_t max_devices=8)
 Scans for DS18x20 devices on a 1-Wire bus.
 
result< std::vector< thermo::millicelsius > > idfxx::ds18x20::try_measure_and_read_multi (std::span< const device > devices)
 Measures and reads temperatures from multiple devices.
 

Detailed Description

Type-safe DS18x20 1-Wire temperature sensor driver for ESP32.

Provides temperature measurement and scratchpad access for DS18S20, DS1822, DS18B20, and MAX31850 1-Wire temperature sensors.

Depends on Core Utilities for error handling and GPIO Component for pin configuration.

Enumeration Type Documentation

◆ family

DS18x20 device family identifiers.

Each 1-Wire device family has a unique 8-bit code stored in the low byte of the device's ROM address.

Enumerator
ds18s20 

DS18S20 (9-bit, +/-0.5C)

ds1822 

DS1822 (12-bit, +/-2C)

ds18b20 

DS18B20 (12-bit, +/-0.5C)

max31850 

MAX31850 (14-bit, +/-0.25C)

Definition at line 45 of file ds18x20.hpp.

◆ resolution

DS18B20 ADC resolution configuration.

Values correspond to the configuration register byte in the scratchpad. Higher resolution provides better precision but increases conversion time.

Enumerator
bits_9 

9-bit resolution (~93.75ms conversion)

bits_10 

10-bit resolution (~187.5ms conversion)

bits_11 

11-bit resolution (~375ms conversion)

bits_12 

12-bit resolution (~750ms conversion, default)

Definition at line 59 of file ds18x20.hpp.

Function Documentation

◆ measure_and_read_multi()

std::vector< thermo::millicelsius > idfxx::ds18x20::measure_and_read_multi ( std::span< const device devices)
inline

Measures and reads temperatures from multiple devices.

Sends a measure command for each bus and reads the temperature from each device.

Parameters
devicesDevices to read from.
Returns
A vector of temperatures in the same order as the input devices.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 128 of file ds18x20.hpp.

References idfxx::ds18x20::try_measure_and_read_multi(), and idfxx::unwrap().

◆ scan_devices()

std::vector< device > idfxx::ds18x20::scan_devices ( idfxx::gpio  pin,
size_t  max_devices = 8 
)
inline

Scans for DS18x20 devices on a 1-Wire bus.

Discovers all DS18x20-family devices connected to the specified GPIO pin.

Parameters
pinGPIO pin connected to the 1-Wire bus.
max_devicesMaximum number of devices to discover.
Returns
A vector of discovered devices.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 124 of file ds18x20.hpp.

References idfxx::ds18x20::try_scan_devices(), and idfxx::unwrap().

◆ try_measure_and_read_multi()

result< std::vector< thermo::millicelsius > > idfxx::ds18x20::try_measure_and_read_multi ( std::span< const device devices)

Measures and reads temperatures from multiple devices.

Sends a measure command for each bus and reads the temperature from each device.

Parameters
devicesDevices to read from.
Returns
A vector of temperatures in the same order as the input devices, or an error on bus communication failure. Returns an empty vector if the input is empty.

Referenced by idfxx::ds18x20::measure_and_read_multi().

◆ try_scan_devices()

result< std::vector< device > > idfxx::ds18x20::try_scan_devices ( idfxx::gpio  pin,
size_t  max_devices = 8 
)

Scans for DS18x20 devices on a 1-Wire bus.

Discovers all DS18x20-family devices connected to the specified GPIO pin.

Parameters
pinGPIO pin connected to the 1-Wire bus.
max_devicesMaximum number of devices to discover.
Returns
A vector of discovered devices, or an error on bus communication failure.
Return values
invalid_stateIf the pin is not connected.

Referenced by idfxx::ds18x20::scan_devices().