File espos_onewire.h¶
FileList > espos_sensors > include > espos_onewire.h
Go to the source code of this file
#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include "esp_err.h"
Public Types¶
| Type | Name |
|---|---|
| typedef struct espos_ds18b20 * | espos_ds18b20_handle_t |
| typedef struct espos_onewire_bus * | espos_onewire_bus_handle_t |
Public Functions¶
| Type | Name |
|---|---|
| uint64_t | espos_ds18b20_address (espos_ds18b20_handle_t dev) The sensor's ROM id. |
| void | espos_ds18b20_close (espos_ds18b20_handle_t dev) |
| uint32_t | espos_ds18b20_convert_ms (int bits) |
| esp_err_t | espos_ds18b20_open (espos_onewire_bus_handle_t bus, uint64_t addr, espos_ds18b20_handle_t * out) Open one sensor by address. |
| esp_err_t | espos_ds18b20_read_kelvin (espos_ds18b20_handle_t dev, float * out_kelvin) The temperature from the LAST conversion, in kelvin the Signal K unit, so nothing downstream has to convert. |
| esp_err_t | espos_ds18b20_set_resolution (espos_ds18b20_handle_t dev, int bits) Resolution, 9..12 bits. |
| void | espos_onewire_close (espos_onewire_bus_handle_t bus) |
| esp_err_t | espos_onewire_convert_all (espos_onewire_bus_handle_t bus) Start a conversion on every sensor on the bus at once (the 1-Wire SKIP ROM broadcast), then read each one when it is done. |
| esp_err_t | espos_onewire_open (int gpio, espos_onewire_bus_handle_t * out) Open a 1-Wire bus on one GPIO. |
| esp_err_t | espos_onewire_search (espos_onewire_bus_handle_t bus, uint64_t * addrs, size_t max, size_t * out_n) Find every DS18B20 on the bus. |
Public Types Documentation¶
typedef espos_ds18b20_handle_t¶
typedef espos_onewire_bus_handle_t¶
Public Functions Documentation¶
function espos_ds18b20_address¶
The sensor's ROM id.
function espos_ds18b20_close¶
function espos_ds18b20_convert_ms¶
function espos_ds18b20_open¶
Open one sensor by address.
esp_err_t espos_ds18b20_open (
espos_onewire_bus_handle_t bus,
uint64_t addr,
espos_ds18b20_handle_t * out
)
Address 0 means "the only sensor on the bus" and is a convenience for the single-sensor case; it fails when the bus has more than one, rather than picking one at random.
function espos_ds18b20_read_kelvin¶
The temperature from the LAST conversion, in kelvin the Signal K unit, so nothing downstream has to convert.
Does not trigger one: call espos_onewire_convert_all() and read after the conversion time.
A sensor that has been unplugged reads 85 C exactly (the chip's power-on value) and that is reported as ESP_ERR_INVALID_RESPONSE rather than a plausible-looking number, because a disconnected engine sensor reading a steady 85 C is the kind of fault that gets believed.
function espos_ds18b20_set_resolution¶
Resolution, 9..12 bits.
Fewer bits convert faster: 9 bits is 0.5 C in ~94 ms, 12 bits is 0.0625 C in ~750 ms. For a cabin or engine temperature 10 or 11 bits is the sensible trade; 12 is the chip default.
function espos_onewire_close¶
function espos_onewire_convert_all¶
Start a conversion on every sensor on the bus at once (the 1-Wire SKIP ROM broadcast), then read each one when it is done.
This is the pattern to use: converting sensors one at a time costs the conversion time PER sensor, so eight sensors at 12 bits take six seconds instead of one.
espos_ds18b20_convert_ms() is how long to wait before reading.
function espos_onewire_open¶
Open a 1-Wire bus on one GPIO.
function espos_onewire_search¶
Find every DS18B20 on the bus.
esp_err_t espos_onewire_search (
espos_onewire_bus_handle_t bus,
uint64_t * addrs,
size_t max,
size_t * out_n
)
Fills addrs with up to max ROM ids and writes how many were found to *out_n. Log these once and put them in the configuration: an address is what a sensor IS, and it is printed as 16 hex digits.
The documentation for this class was generated from the following file espos_sensors/include/espos_onewire.h