Skip to content

Commit 2991bca

Browse files
committed
feat(ds18b20): upgrade the example to use ds18b20 version 0.2
1 parent a157181 commit 2991bca

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
dependencies:
2-
ds18b20: "^0.1.0"
2+
ds18b20: "^0.2.0"

examples/peripherals/rmt/onewire/main/onewire_example_main.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ void app_main(void)
4545
search_result = onewire_device_iter_get_next(iter, &next_onewire_device);
4646
if (search_result == ESP_OK) { // found a new device, let's check if we can upgrade it to a DS18B20
4747
ds18b20_config_t ds_cfg = {};
48-
if (ds18b20_new_device(&next_onewire_device, &ds_cfg, &ds18b20s[ds18b20_device_num]) == ESP_OK) {
49-
ESP_LOGI(TAG, "Found a DS18B20[%d], address: %016llX", ds18b20_device_num, next_onewire_device.address);
48+
onewire_device_address_t address;
49+
// wrap the generic 1-wire device into a DS18B20 sensor device
50+
if (ds18b20_new_device_from_enumeration(&next_onewire_device, &ds_cfg, &ds18b20s[ds18b20_device_num]) == ESP_OK) {
51+
ds18b20_get_device_address(ds18b20s[ds18b20_device_num], &address);
52+
ESP_LOGI(TAG, "Found a DS18B20[%d], address: %016llX", ds18b20_device_num, address);
5053
ds18b20_device_num++;
5154
if (ds18b20_device_num >= EXAMPLE_ONEWIRE_MAX_DS18B20) {
5255
ESP_LOGI(TAG, "Max DS18B20 number reached, stop searching...");
@@ -70,9 +73,10 @@ void app_main(void)
7073
float temperature;
7174
while (1) {
7275
vTaskDelay(pdMS_TO_TICKS(200));
73-
76+
// trigger temperature conversion for all DS18B20s on the bus
77+
ESP_ERROR_CHECK(ds18b20_trigger_temperature_conversion_for_all(bus));
78+
// read temperature from each DS18B20
7479
for (int i = 0; i < ds18b20_device_num; i ++) {
75-
ESP_ERROR_CHECK(ds18b20_trigger_temperature_conversion(ds18b20s[i]));
7680
ESP_ERROR_CHECK(ds18b20_get_temperature(ds18b20s[i], &temperature));
7781
ESP_LOGI(TAG, "temperature read from DS18B20[%d]: %.2fC", i, temperature);
7882
}

0 commit comments

Comments
 (0)