Skip to content

Commit 66a6155

Browse files
authored
Merge pull request #314 from trombik/ds18x20_multi
ds18x20: introduce Kconfig.projbuild
2 parents eec6905 + daf22a8 commit 66a6155

File tree

6 files changed

+101
-13
lines changed

6 files changed

+101
-13
lines changed

examples/ds18x20_multi/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Example for `ds18x20` driver
2+
3+
## Datasheet
4+
5+
* [DS18S20 High-Precision 1-Wire Digital Thermometer](https://datasheets.maximintegrated.com/en/ds/DS18S20.pdf)
6+
7+
## What it does
8+
9+
The example configures one or `CONFIG_EXAMPLE_DS18X20_MAX_SENSORS` of
10+
`ds18x20` devices (the default is 8) with an internal pullup on
11+
`CONFIG_EXAMPLE_ONEWIRE_GPIO` (see below for defaults). Use `menuconfig` to
12+
change the default values under `Example configuration`.
13+
14+
It reads sensor values from the sensors and the address of each sensors, and
15+
show them in a loop.
16+
17+
The internal (~47k) pull-ups of the ESP do appear to work, at least for simple
18+
setups (one or two sensors connected with short leads), but do not technically
19+
meet the pull-up requirements from the ds18x20 datasheet and may not always be
20+
reliable. For a real application, a proper 4.7k external pull-up resistor is
21+
recommended instead!
22+
23+
## Wiring
24+
25+
Connect `DQ` pin to `CONFIG_EXAMPLE_ONEWIRE_GPIO`.
26+
27+
| Name | Description | Defaults |
28+
|------|-------------|----------|
29+
| `CONFIG_EXAMPLE_ONEWIRE_GPIO` | GPIO Number of 1-Wire bus, or `DQ` | "4" for `esp8266`, "18" for `esp32c3`, "19" for `esp32`, `esp32s2`, and `esp32s3` |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
menu "Example configuration"
2+
config EXAMPLE_ONEWIRE_GPIO
3+
int "GPIO Number of 1-Wire bus, or DQ"
4+
default 4 if IDF_TARGET_ESP8266
5+
default 18 if IDF_TARGET_ESP32C3
6+
default 17 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
7+
help
8+
GPIO Number of 1-Wire bus, or DQ. You might need an external
9+
pullup resistor on the bus. See README.md for details.
10+
11+
config EXAMPLE_DS18X20_MAX_SENSORS
12+
int "Number of ds18x20 sensors on the 1-Wire bus"
13+
default 8
14+
help
15+
Max number of ds18x20 sensors on th 1-Wire bus. If number of
16+
sensors on the bus more than this value found on the bus, the rest
17+
of sensors will be ignored.
18+
endmenu

examples/ds18x20_multi/main/main.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
#include <esp_log.h>
66
#include <esp_err.h>
77

8-
#if defined(CONFIG_IDF_TARGET_ESP8266)
9-
static const gpio_num_t SENSOR_GPIO = 4;
10-
#else
11-
static const gpio_num_t SENSOR_GPIO = 17;
12-
#endif
13-
static const uint32_t LOOP_DELAY_MS = 500;
14-
static const int MAX_SENSORS = 8;
8+
static const gpio_num_t SENSOR_GPIO = CONFIG_EXAMPLE_ONEWIRE_GPIO;
9+
static const int MAX_SENSORS = CONFIG_EXAMPLE_DS18X20_MAX_SENSORS;
1510
static const int RESCAN_INTERVAL = 8;
11+
static const uint32_t LOOP_DELAY_MS = 500;
1612

1713
static const char *TAG = "ds18x20_test";
1814

examples/ds18x20_single/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Example for `ds18x20` driver
2+
3+
## Datasheet
4+
5+
* [DS18S20 High-Precision 1-Wire Digital Thermometer](https://datasheets.maximintegrated.com/en/ds/DS18S20.pdf)
6+
7+
## What it does
8+
9+
The example configures a single `ds18x20` device with an internal pullup on
10+
`CONFIG_EXAMPLE_ONEWIRE_GPIO` (see below for defaults). You need to set
11+
`CONFIG_EXAMPLE_DS18X20_ADDR` to your own sensors' address. Use `menuconfig`
12+
to change the default values under `Example configuration`.
13+
14+
Use [`ds18x20_multi`](../ds18x20_multi) example to find out the sensor
15+
address.
16+
17+
It reads sensor values from the sensor and show them in a loop.
18+
19+
The internal (~47k) pull-ups of the ESP do appear to work, at least for simple
20+
setups (one or two sensors connected with short leads), but do not technically
21+
meet the pull-up requirements from the ds18x20 datasheet and may not always be
22+
reliable. For a real application, a proper 4.7k external pull-up resistor is
23+
recommended instead!
24+
25+
## Wiring
26+
27+
Connect `DQ` pin to `CONFIG_EXAMPLE_ONEWIRE_GPIO`.
28+
29+
| Name | Description | Defaults |
30+
|------|-------------|----------|
31+
| `CONFIG_EXAMPLE_ONEWIRE_GPIO` | GPIO Number of 1-Wire bus, or `DQ` | "4" for `esp8266`, "18" for `esp32c3`, "19" for `esp32`, `esp32s2`, and `esp32s3` |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
menu "Example configuration"
2+
config EXAMPLE_ONEWIRE_GPIO
3+
int "GPIO Number of 1-Wire bus, or DQ"
4+
default 4 if IDF_TARGET_ESP8266
5+
default 18 if IDF_TARGET_ESP32C3
6+
default 17 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
7+
help
8+
GPIO Number of 1-Wire bus, or DQ. You might need an external
9+
pullup resistor on the bus. See README.md for details.
10+
11+
config EXAMPLE_DS18X20_ADDR
12+
hex "Address of the sensor"
13+
default "27041685c771ff28"
14+
help
15+
The address of the sensor. Change this to the address of your own
16+
sensor. You can find out the address of your sensor by running
17+
ds18x20_multi example.
18+
endmenu

examples/ds18x20_single/main/main.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
#include <esp_log.h>
66
#include <esp_err.h>
77

8-
#if defined(CONFIG_IDF_TARGET_ESP8266)
9-
static const gpio_num_t SENSOR_GPIO = 4;
10-
#else
11-
static const gpio_num_t SENSOR_GPIO = 17;
12-
#endif
8+
static const gpio_num_t SENSOR_GPIO = CONFIG_EXAMPLE_ONEWIRE_GPIO;
139

1410
// Use address of your own sensor here!
1511
// You can find out the address of your sensor by running ds18x20_multi example
16-
static const ds18x20_addr_t SENSOR_ADDR = 0x27041685c771ff28;
12+
static const ds18x20_addr_t SENSOR_ADDR = CONFIG_EXAMPLE_DS18X20_ADDR;
1713

1814
static const char *TAG = "ds18x20_test";
1915

0 commit comments

Comments
 (0)