Browse Source

Merge pull request #18 from DavidAntliff/parasitic-power

Add support for parasitic power
main
David Antliff 6 years ago
committed by GitHub
parent
commit
3da9783768
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      .gitmodules
  2. 2
      CMakeLists.txt
  3. 25
      README.md
  4. 2
      components/esp32-ds18b20
  5. 2
      components/esp32-owb
  6. 38
      main/Kconfig.projbuild
  7. 21
      main/app_main.c
  8. 4
      sdkconfig.defaults

5
.gitmodules

@ -1,7 +1,6 @@
[submodule "components/esp32-owb"] [submodule "components/esp32-owb"]
path = components/esp32-owb path = components/esp32-owb
url = https://github.com/DavidAntliff/esp32-owb url = ../esp32-owb
[submodule "components/esp32-ds18b20"] [submodule "components/esp32-ds18b20"]
path = components/esp32-ds18b20 path = components/esp32-ds18b20
url = https://github.com/DavidAntliff/esp32-ds18b20 url = ../esp32-ds18b20

2
CMakeLists.txt

@ -3,7 +3,7 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake) include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp32-ds18b20-example) project(esp32-ds18b20-example LANGUAGES C)
if (NOT IDF_VERSION_MAJOR) if (NOT IDF_VERSION_MAJOR)
set(IDF_VERSION_MAJOR 3) set(IDF_VERSION_MAJOR 3)

25
README.md

@ -6,11 +6,13 @@
## Introduction ## Introduction
This is an example application for the Maxim Integrated DS18B20 Programmable Resolution 1-Wire Digital Thermometer device. This is an example application for the Maxim Integrated DS18B20 Programmable Resolution 1-Wire Digital Thermometer
device.
It supports a single or multiple devices on the same 1-Wire bus. It supports a single or multiple devices on the same 1-Wire bus.
It is written and tested for v3.3 of the [ESP-IDF](https://github.com/espressif/esp-idf) environment, using the xtensa-esp32-elf toolchain (gcc version 5.2.0, crosstool-ng-1.22.0-80-g6c4433a). It is written and tested for v3.3 and v4.1-beta1 of the [ESP-IDF](https://github.com/espressif/esp-idf) environment,
using the xtensa-esp32-elf toolchain (gcc version 5.2.0, crosstool-ng-1.22.0-80-g6c4433a).
Ensure that submodules are cloned: Ensure that submodules are cloned:
@ -23,7 +25,8 @@ Build the application with:
$ idf.py build $ idf.py build
$ idf.py -p (PORT) flash monitor $ 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. The program should detect your connected devices and periodically obtain temperature readings from them, displaying them
on the console.
## Dependencies ## Dependencies
@ -34,17 +37,27 @@ This application makes use of the following components (included as submodules):
## Hardware ## Hardware
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. 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. `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 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](https://www.github.com/DavidAntliff/esp32-ds18b20-example#parasitic-power-mode)
for further information about parasitic power mode, including strong pull-up configuration.
## Features ## Features
This example provides: This example provides:
* External power supply mode. * External power supply detection.
* Parasitic power supply detection.
* Static (stack-based) or dynamic (malloc-based) memory model examples. * Static (stack-based) or dynamic (malloc-based) memory model examples.
* No global variables. * No global variables.
* Device search. * Device search.

2
components/esp32-ds18b20

@ -1 +1 @@
Subproject commit d76b70c0a795adbbd1b9d1b3e2789b455cfd945d Subproject commit e763961d445263cdfc93d0fe516f917ba95a43e1

2
components/esp32-owb

@ -1 +1 @@
Subproject commit af25dd31dbb1e80364b99fad29815badfab0ceda Subproject commit 316296a398e44976a5abdd7d70f8c21ad2cec09d

38
main/Kconfig.projbuild

@ -2,13 +2,45 @@ menu "esp32-ds18b20-example Configuration"
config ONE_WIRE_GPIO config ONE_WIRE_GPIO
int "OneWire GPIO number" int "OneWire GPIO number"
range 0 34 range 0 33
default 5 default 4
help help
GPIO number (IOxx) to access One Wire Bus. GPIO number (IOxx) to access One Wire Bus.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used. Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used.
GPIOs 35-39 are input-only so cannot be used to drive the One Wire Bus. GPIOs 34-39 are input-only so cannot be used to drive the One Wire Bus.
config ENABLE_STRONG_PULLUP_GPIO
bool "Enable strong pull-up controlled by GPIO (MOSFET)"
default n
help
An external circuit can be used to provide a strong pull-up to the One Wire Bus.
This is useful when the bus has parasitic-powered devices and extra current is
required to power them, such as during temperature ADC conversions.
An example of such a circuit for the ESP32 is a P-channel MOSFET (such as the BS250)
connected Source-to-Drain between a current-limiting resistor (e.g. 270ohm for 12mA
max at 3.3V), itself connected to VCC, and the One Wire Bus data line. The Gate is
connected to the GPIO specified here.
config STRONG_PULLUP_GPIO
int "Strong pull-up GPIO number"
range 0 33
default 5
help
GPIO number (IOxx) to control the strong pull-up on the One Wire Bus, perhaps
via a P-channel MOSFET between VCC and the One Wire Bus data line.
This GPIO will be set as an output and driven high during temperature conversion.
This would enable the MOSFET providing current to the devices.
At all other times it will be driven low, switching off the MOSFET and allowing
the One Wire Bus to operate normally.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used.
GPIOs 34-39 are input-only so cannot be used to drive the One Wire Bus.
depends on ENABLE_STRONG_PULLUP_GPIO
endmenu endmenu

21
main/app_main.c

@ -22,8 +22,6 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <inttypes.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_system.h" #include "esp_system.h"
@ -38,7 +36,7 @@
#define DS18B20_RESOLUTION (DS18B20_RESOLUTION_12_BIT) #define DS18B20_RESOLUTION (DS18B20_RESOLUTION_12_BIT)
#define SAMPLE_PERIOD (1000) // milliseconds #define SAMPLE_PERIOD (1000) // milliseconds
void app_main() _Noreturn void app_main()
{ {
// Override global log level // Override global log level
esp_log_level_set("*", ESP_LOG_INFO); esp_log_level_set("*", ESP_LOG_INFO);
@ -150,6 +148,23 @@ void app_main()
// vTaskDelay(1000 / portTICK_PERIOD_MS); // vTaskDelay(1000 / portTICK_PERIOD_MS);
// } // }
// Check for parasitic-powered devices
bool parasitic_power = false;
ds18b20_check_for_parasite_power(owb, &parasitic_power);
if (parasitic_power) {
printf("Parasitic-powered devices detected");
}
// In parasitic-power mode, devices cannot indicate when conversions are complete,
// so waiting for a temperature conversion must be done by waiting a prescribed duration
owb_use_parasitic_power(owb, parasitic_power);
#ifdef CONFIG_ENABLE_STRONG_PULLUP_GPIO
// An external pull-up circuit is used to supply extra current to OneWireBus devices
// during temperature conversions.
owb_use_strong_pullup_gpio(owb, CONFIG_STRONG_PULLUP_GPIO);
#endif
// Read temperatures more efficiently by starting conversions on all devices at the same time // Read temperatures more efficiently by starting conversions on all devices at the same time
int errors_count[MAX_DEVICES] = {0}; int errors_count[MAX_DEVICES] = {0};
int sample_count = 0; int sample_count = 0;

4
sdkconfig.defaults

@ -0,0 +1,4 @@
#
# Log output
#
CONFIG_LOG_DEFAULT_LEVEL=4
Loading…
Cancel
Save