UncleRus / esp-idf-lib

Component library for ESP32-xx and ESP8266
https://esp-idf-lib.readthedocs.io/en/latest/
1.41k stars 437 forks source link

DS18X20_ANY causes incorrect temperature in single sensor example code. #434

Closed AndyChessum closed 1 year ago

AndyChessum commented 2 years ago

The issue

Hi,

I tried both the multi and single example code in PlatformIO with a single DS18B20 sensor. The multi example worked fine, but the single example reported a temperature of 204 degrees. When I replaced DS18X20_ANY with the actual address of the sensor, the correct temperature was reported.

I have tried different sensors (always one at a time) and am using an external 4.7K resistor, as suggested.

Which SDK are you using?

esp-idf

Which version of SDK are you using?

master

Which build target have you used?

Component causing the issue

DS18x20

Anything in the logs that might be useful for us?

2mI (297) cpu_start: Starting scheduler on PRO CPU.␛[0m
␛[0;32mI (0) cpu_start: Starting scheduler on APP CPU.␛[0m
␛[0;32mI (1808) ds18x20_test: Sensor : 204.44°C␛[0m
Temperature 204.437500␛[0;32mI (3558) ds18x20_test: Sensor : 204.44°C␛[0m
Temperature 204.437500␛[0;32mI (5308) ds18x20_test: Sensor : 204.44°C␛[0m
Temperature 204.437500␛[0;32mI (7058) ds18x20_test: Sensor : 204.44°C␛[0m
Temperature 204.437500␛[0;32mI (8808) ds18x20_test: Sensor : 204.44°C␛[0m

Additional information or context

erbose mode can be enabled via -v, --verbose option CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/nodemcu-32s.html PLATFORM: Espressif 32 (5.0.0) > NodeMCU-32S HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa) PACKAGES:

Confirmation

UncleRus commented 1 year ago

I apologize for the delay in reply.

This happens because the function that calculates the measured temperature (esp_err_t ds18x20_read_temperature(gpio_num_t pin, ds18x20_addr_t addr, float *temperature)) cannot understand which family the sensor belongs to (because of DS18X20_ANY instead of address). In this case please use an explicit read/measure function, i.e. change the example, instead of:

res = ds18x20_measure_and_read(SENSOR_GPIO, SENSOR_ADDR, &temperature);

use

res = ds18b20_measure_and_read(SENSOR_GPIO, SENSOR_ADDR, &temperature);

I made changes to the driver and now in this case (impossibility to determine the sensor family) it will give an error.