37 #include "freertos/FreeRTOS.h"
38 #include "freertos/task.h"
39 #include "esp_system.h"
46 #define GPIO_DS18B20_0 (CONFIG_TEMP_OWB_GPIO)
47 #define MAX_DEVICES (CONFIG_TEMP_MAX_DEVS)
48 #define DS18B20_RESOLUTION (DS18B20_RESOLUTION_12_BIT)
54 static const char *
TAG = CONFIG_TEMP_WRAPPER_TAG;
63 ESP_LOGI(
TAG,
"setting up temp sensor");
68 ESP_LOGD(
TAG,
"find devices:");
98 ESP_LOGD(
TAG,
"single device %s present", rom_code_s);
102 ESP_LOGE(
TAG,
"an error occurred reading ROM code: %d", status);
111 .fields.serial_number = {0xee, 0xb2, 0xa5, 0x2c, 0x16, 0x02},
112 .fields.crc = {0x15},
116 bool is_present =
false;
121 ESP_LOGD(
TAG,
"device %s is %s", rom_code_s, is_present ?
"present" :
"not present");
125 ESP_LOGE(
TAG,
"an error occurred searching for known device: %d", search_status);
138 ESP_LOGI(
TAG,
"single device optimisations enabled");
150 bool parasitic_power =
false;
154 ESP_LOGI(
TAG,
"parasitic-powered devices detected");
161 #ifdef CONFIG_ENABLE_STRONG_PULLUP_GPIO
167 ESP_LOGI(
TAG,
"finished sensor init");
176 ESP_LOGI(
TAG,
"temp deinit start");
185 ESP_LOGI(
TAG,
"temp deinit end");
188 vTaskDelay(1000 / portTICK_PERIOD_MS);
197 ESP_LOGD(
TAG,
"temp read");
200 int sample_count = 0;
203 TickType_t last_wake_time = xTaskGetTickCount();
221 ESP_LOGI(
TAG,
"temperature readings (degrees C): sample %d", ++sample_count);
229 ESP_LOGI(
TAG,
" %d: %.1f %d errors", i, readings[i], errors_count[i]);
232 vTaskDelayUntil(&last_wake_time, CONFIG_TEMP_SAMPLE_PERIOD / portTICK_PERIOD_MS);
236 ESP_LOGE(
TAG,
"no DS18B20 devices detected!");
250 TickType_t last_wake_time = xTaskGetTickCount();
255 for (
int i = 0; i < size; ++i)
262 ESP_LOGE(
TAG,
"no DS18B20 devices detected or invalid size provided");
264 vTaskDelayUntil(&last_wake_time, CONFIG_TEMP_SAMPLE_PERIOD / portTICK_PERIOD_MS);
void ds18b20_init_solo(DS18B20_Info *ds18b20_info, const OneWireBus *bus)
Initialise a device info instance as a solo device on the bus.
bool ds18b20_set_resolution(DS18B20_Info *ds18b20_info, DS18B20_RESOLUTION resolution)
Set temperature measurement resolution.
void ds18b20_init(DS18B20_Info *ds18b20_info, const OneWireBus *bus, OneWireBus_ROMCode rom_code)
Initialise a device info instance with the specified GPIO.
void ds18b20_free(DS18B20_Info **ds18b20_info)
Delete an existing device info instance.
float ds18b20_wait_for_conversion(const DS18B20_Info *ds18b20_info)
Wait for the maximum conversion time according to the current resolution of the device....
DS18B20_ERROR ds18b20_read_temp(const DS18B20_Info *ds18b20_info, float *value)
Read last temperature measurement from device.
DS18B20_ERROR ds18b20_check_for_parasite_power(const OneWireBus *bus, bool *present)
Check OneWire bus for presence of parasitic-powered devices.
void ds18b20_convert_all(const OneWireBus *bus)
Start temperature conversion on all connected devices.
void ds18b20_use_crc(DS18B20_Info *ds18b20_info, bool use_crc)
Enable or disable use of CRC checks on device communications.
DS18B20_Info * ds18b20_malloc(void)
Construct a new device info instance. New instance should be initialised before calling other functio...
Interface definitions for the Maxim Integrated DS18B20 Programmable Resolution 1-Wire Digital Thermom...
DS18B20_RESOLUTION
Symbols for the supported temperature resolution of the device.
DS18B20_ERROR
Success and error codes.
OneWireBus * owb
onewire bus pointer
void ds18b20_wrapped_read(void)
print the temps runs conversion on all the owb devices, waits for the conversion and then prints out ...
#define MAX_DEVICES
maximum number of devices to search for
void ds18b20_wrapped_deinit(void)
deinit the sensor cleans up and frees all of the devices and the onewire bus
void ds18b20_wrapped_capture(float *results, int size)
capture temps to results this function runs conversion on all the owb devices, waits for conversion t...
int ds18b20_wrapped_init(void)
init the sensor intitialises the onewire bus and finds and intialises ds18b20 sensors along the pin
DS18B20_Info * devices[MAX_DEVICES]
list of devices
#define GPIO_DS18B20_0
the gpio pin to search for sensors on
int num_devices
current number of devices found
owb_rmt_driver_info rmt_driver_info
the rmt driver info for communicating over the owb
definitions for wrapper component to help setup and interface with temp sensor
Interface definitions for the 1-Wire bus component.
owb_status owb_read_rom(const OneWireBus *bus, OneWireBus_ROMCode *rom_code)
Read ROM code from device - only works when there is a single device on the bus.
owb_status owb_use_parasitic_power(OneWireBus *bus, bool use_parasitic_power)
Enable or disable use of parasitic power on the One Wire Bus. This affects how devices signal on the ...
char * owb_string_from_rom_code(OneWireBus_ROMCode rom_code, char *buffer, size_t len)
Create a string representation of a ROM code, most significant byte (CRC8) first.
owb_status
Represents the result of OWB API functions.
@ OWB_STATUS_OK
Operation succeeded.
owb_status owb_use_crc(OneWireBus *bus, bool use_crc)
Enable or disable use of CRC checks on device communications.
owb_status owb_uninitialize(OneWireBus *bus)
call to release resources after completing use of the OneWireBus
owb_status owb_search_next(const OneWireBus *bus, OneWireBus_SearchState *state, bool *found_device)
Locates the next device on the 1-Wire bus, if present, starting from the provided state....
#define OWB_ROM_CODE_STRING_LENGTH
Typical length of OneWire bus ROM ID as ASCII hex string, including null terminator.
owb_status owb_use_strong_pullup_gpio(OneWireBus *bus, gpio_num_t gpio)
Enable or disable use of extra GPIO to activate strong pull-up circuit. This only has effect if paras...
owb_status owb_search_first(const OneWireBus *bus, OneWireBus_SearchState *state, bool *found_device)
Locates the first device on the 1-Wire bus, if present.
owb_status owb_verify_rom(const OneWireBus *bus, OneWireBus_ROMCode rom_code, bool *is_present)
Verify the device specified by ROM code is present.
OneWireBus * owb_rmt_initialize(owb_rmt_driver_info *info, gpio_num_t gpio_num, rmt_channel_t tx_channel, rmt_channel_t rx_channel)
Initialise the RMT driver.
Structure containing information related to a single DS18B20 device connected via a 1-Wire bus.
uint8_t family[1]
family identifier (1 byte, LSB - read/write first)
Represents the state of a device search on the 1-Wire bus.
OneWireBus_ROMCode rom_code
Device ROM code.
Structure containing 1-Wire bus information relevant to a single instance.
Represents a 1-Wire ROM Code. This is a sequence of eight bytes, where the first byte is the family n...
struct OneWireBus_ROMCode::fields fields
Provides access via field names.