This is an example application for the Maxim Integrated DS18B20 Programmable Resolution 1-Wire Digital Thermometer device.
It is intended for the ESP32 (idf.py
target esp32
), however with some minor modifications it may work on the other ESP32 devices.
It supports a single or multiple devices on the same 1-Wire bus.
It is tested for v4.4.4 and v5.0.1 of the ESP-IDF environment.
Code for earlier versions of the IDF (v3.3 and v4.1-beta1) may be found on branch ESP-IDF_v3.3_4.1-beta1. This legacy code is no longer supported but you're welcome to use it if you're restricted to older versions of the IDF.
Ensure that submodules are cloned:
$ git clone --recursive https://github.com/DavidAntliff/esp32-ds18b20-example.git
Build the application with:
$ cd esp32-ds18b20-example
$ idf.py menuconfig # set your serial configuration and the 1-Wire GPIO - see below
$ idf.py build
$ idf.py -p (PORT) flash monitor
The program should detect your connected devices and periodically obtain temperature readings from them, displaying them on the console.
This application makes use of the following components (included as submodules):
To run this example, connect one or more DS18B20 devices to a single GPIO on the ESP32. Use the recommended pull-up resistor of 4.7 KOhms, connected to the 3.3V supply.
idf.py menuconfig
can be used to set the 1-Wire GPIO.
If you have several devices and see occasional CRC errors, consider using a 2.2 kOhm pull-up resistor instead. Also consider adding decoupling capacitors between the sensor supply voltage and ground, as close to each sensor as possible.
If you wish to enable a second GPIO to control an external strong pull-up circuit for parasitic power mode, ensure
CONFIG_ENABLE_STRONG_PULLUP=y
and CONFIG_STRONG_PULLUP_GPIO
is set appropriately.
See documentation for esp32-ds18b20 for further information about parasitic power mode, including strong pull-up configuration.
This example provides:
The source is available from GitHub.
The code in this project is licensed under the MIT license - see LICENSE for details.
"1-Wire" is a registered trademark of Maxim Integrated.