This library for the ESP32 aims to be both high performance and easy to use. It implements the same API as my example for the RPi Pico (RP2040).
Internally it is based on the ESP's RMT peripheral. Whilst originally designed as an IR tranceiver it provides a good general purpose hardware bitstream encoder/decoder. Using the RMT is far more efficient and accurate than bit-bashing a GPIO.
NOTE: the library uses the new RMT driver which requires ESP-IDF Release v5.0 or above.
The quickest way to understand a library is to see it in action. So this repository shows a simple example to take readings from several DS18B20 temperature sensors.
By default the example uses GPIO_4 for the 1-Wire bus but this can be changed easily (see main.c
). To function reliably the 1-Wire bus needs an external pull-up resistor (typically about 4k) from this pin to the +3.3v supply.
The example is in the main
folder and the library itself is in the components
folder.
The project can be built using idy.py or VSCode; instructions are beyond the scope of this README but are well explained in the ESP Getting Started documentation.
.
├── CMakeLists.txt
├── README.md this file
├── components
│ └── esp32-onewire the 1-wire library
│ ├── CMakeLists.txt
│ ├── include
│ │ ├── onewire.h <<< include this header file to use the library
│ │ ├── onewire_symbols.h
│ │ └── onewire_timings.h
│ ├── ow_init.c
│ ├── ow_read.c
│ ├── ow_reset.c
│ ├── ow_romsearch.c
│ └── ow_send.c
├── main
│ ├── CMakeLists.txt
│ ├── include
│ │ ├── ds18b20.h function command codes for the DS18B20
│ │ └── ow_rom.h generic 1-Wire ROM command codes
│ └── main.c example program to read DS18B20 sensors
1-Wire(R) is a trademark of Maxim Integrated Products, Inc.