Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions components/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ components/esp_lvgl_port/test_apps/simd:
- if: IDF_TARGET in ["esp32", "esp32s3"]
reason: Supports only xtensa targets

components/ds18b20:
components/ds18b20/examples/ds18b20_read:
depends_filepatterns:
- "components/ds18b20/**"
disable:
- if: SOC_RMT_SUPPORTED != 1
reason: Onewire component depends on RMT peripheral
- if: CONFIG_NAME == "rmt" and SOC_RMT_SUPPORTED != 1
reason: RMT backend variant requires SOC RMT support
- if: CONFIG_NAME == "uart" and SOC_UART_SUPPORTED != 1
reason: UART backend variant requires SOC UART support
Comment thread
cursor[bot] marked this conversation as resolved.

components/sensors/icm42670:
depends_filepatterns:
Expand Down
9 changes: 9 additions & 0 deletions components/ds18b20/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.3.1

- Bump dependency `onewire_bus` to `^1.1.0` to align with new backend capabilities (including UART backend support).
- Update `ds18b20_read` example to support backend selection in menuconfig (RMT/UART).

## 0.3.0

- Add detection for uninitialized power-on state (85.0C) and return `ESP_ERR_INVALID_STATE` when this value is read.

## 0.2.0

- Support trigger temperature conversion for all DS18B20 sensors on the same bus with a single function call (`ds18b20_trigger_temperature_conversion_for_all`).
Expand Down
15 changes: 12 additions & 3 deletions components/ds18b20/examples/ds18b20_read/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ This example shows how to use the 1-Wire temperature sensor DS18B20.

### Hardware Required

* An ESP development board with RMT peripheral (e.g ESP32, ESP32-C3, ESP32-S3, etc)
* An DS18B20 sensor connected to GPIO 18. To use a different pin, modify `EXAMPLE_ONEWIRE_BUS_GPIO` in [source file](main/ds18b20_example_main.c)
* An ESP development board that supports the selected 1-Wire backend (`RMT` or `UART`)
* A DS18B20 sensor connected to the configured 1-Wire GPIO (default: GPIO0)
* An USB cable for power supply and programming

### Configuration

Run `idf.py menuconfig`, then open:

* `Example Configuration` -> `1-Wire backend` to choose `RMT` or `UART`
* `Example Configuration` -> `1-Wire bus GPIO number` to select bus pin
* `Example Configuration` -> `Enable internal pull-up resistor on bus GPIO` as needed
* `Example Configuration` -> `UART port number (for UART backend)` when UART backend is selected

### Example Output

```text
...
I (297) main_task: Calling app_main()
I (297) example: 1-Wire bus installed on GPIO18
I (297) example: 1-Wire bus installed on GPIO0 by RMT backend
I (297) example: Device iterator created, start searching...
I (407) example: Found a DS18B20[0], address: 070822502019FC28
I (517) example: Found a DS18B20[1], address: FC0921C076034628
Expand Down
45 changes: 45 additions & 0 deletions components/ds18b20/examples/ds18b20_read/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
menu "Example Configuration"

config EXAMPLE_ONEWIRE_BUS_GPIO
int "1-Wire bus GPIO number"
range 0 48
default 0
help
GPIO used by the 1-Wire bus.

config EXAMPLE_ONEWIRE_MAX_DS18B20
int "Maximum number of DS18B20 devices to enumerate"
range 1 32
default 2
help
Stop searching after this many DS18B20 devices are found.

config EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP
bool "Enable internal pull-up resistor on bus GPIO"
default y
help
Enable this when there is no external pull-up resistor on the
1-Wire data line.

choice EXAMPLE_ONEWIRE_BACKEND
prompt "1-Wire backend"
default EXAMPLE_ONEWIRE_BACKEND_RMT
help
Select which backend is used by onewire_bus.

config EXAMPLE_ONEWIRE_BACKEND_RMT
bool "RMT backend"

config EXAMPLE_ONEWIRE_BACKEND_UART
bool "UART backend"
endchoice

config EXAMPLE_ONEWIRE_UART_PORT_NUM
int "UART port number (for UART backend)"
range 0 2
default 1
depends on EXAMPLE_ONEWIRE_BACKEND_UART
help
UART port index passed to onewire_new_bus_uart().

endmenu
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
/*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/

#include <stdio.h>
#include "esp_log.h"
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "onewire_bus.h"
#include "ds18b20.h"

#define EXAMPLE_ONEWIRE_BUS_GPIO 18
#define EXAMPLE_ONEWIRE_MAX_DS18B20 2
#if CONFIG_EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP
#define EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP 1
#else
#define EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP 0
#endif

#if CONFIG_EXAMPLE_ONEWIRE_BACKEND_UART
#define EXAMPLE_ONEWIRE_UART_PORT_NUM CONFIG_EXAMPLE_ONEWIRE_UART_PORT_NUM
#endif

#define EXAMPLE_ONEWIRE_BUS_GPIO CONFIG_EXAMPLE_ONEWIRE_BUS_GPIO
#define EXAMPLE_ONEWIRE_MAX_DS18B20 CONFIG_EXAMPLE_ONEWIRE_MAX_DS18B20

static const char *TAG = "example";

Expand All @@ -23,14 +34,25 @@ void app_main(void)
onewire_bus_config_t bus_config = {
.bus_gpio_num = EXAMPLE_ONEWIRE_BUS_GPIO,
.flags = {
.en_pull_up = true, // enable the internal pull-up resistor in case the external device didn't have one
.en_pull_up = EXAMPLE_ONEWIRE_ENABLE_INTERNAL_PULLUP,
}
};
#if CONFIG_EXAMPLE_ONEWIRE_BACKEND_RMT
onewire_bus_rmt_config_t rmt_config = {
.max_rx_bytes = 10, // 1byte ROM command + 8byte ROM number + 1byte device command
};
ESP_ERROR_CHECK(onewire_new_bus_rmt(&bus_config, &rmt_config, &bus));
ESP_LOGI(TAG, "1-Wire bus installed on GPIO%d", EXAMPLE_ONEWIRE_BUS_GPIO);
ESP_LOGI(TAG, "1-Wire bus installed on GPIO%d by RMT backend", EXAMPLE_ONEWIRE_BUS_GPIO);
#elif CONFIG_EXAMPLE_ONEWIRE_BACKEND_UART
onewire_bus_uart_config_t uart_config = {
.uart_port_num = EXAMPLE_ONEWIRE_UART_PORT_NUM,
};
ESP_ERROR_CHECK(onewire_new_bus_uart(&bus_config, &uart_config, &bus));
ESP_LOGI(TAG, "1-Wire bus installed on GPIO%d by UART backend (UART%d)",
EXAMPLE_ONEWIRE_BUS_GPIO, EXAMPLE_ONEWIRE_UART_PORT_NUM);
#else
#error "No 1-Wire backend selected in menuconfig"
#endif

int ds18b20_device_num = 0;
ds18b20_device_handle_t ds18b20s[EXAMPLE_ONEWIRE_MAX_DS18B20];
Expand Down
1 change: 1 addition & 0 deletions components/ds18b20/examples/ds18b20_read/sdkconfig.bsp.rmt
Comment thread
suda-morris marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_EXAMPLE_ONEWIRE_BACKEND_RMT=y
2 changes: 2 additions & 0 deletions components/ds18b20/examples/ds18b20_read/sdkconfig.bsp.uart
Comment thread
suda-morris marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_EXAMPLE_ONEWIRE_BACKEND_UART=y
CONFIG_EXAMPLE_ONEWIRE_UART_PORT_NUM=1
4 changes: 2 additions & 2 deletions components/ds18b20/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: "0.3.0"
version: "0.3.1"
description: DS18B20 device driver
url: https://github.com/espressif/esp-bsp/tree/master/components/ds18b20
dependencies:
onewire_bus: "^1.0.0"
onewire_bus: "^1.1.0"
Loading