Giter VIP home page Giter VIP logo

esp32-ds18b20's Introduction

esp32-ds18b20

Introduction

This is a ESP32-compatible C component for the Maxim Integrated DS18B20 Programmable Resolution 1-Wire Digital Thermometer device.

It supports multiple devices on the same 1-Wire bus.

It is tested with v4.4.4 and v5.0.1 of the ESP-IDF environment.

Dependencies

Requires esp32-owb.

Example

See esp32-ds18b20-example for an example that supports single and multiple devices on a single bus.

Features

In cooperation with the underlying esp32-owb component, this component includes:

  • External power supply mode.
  • Parasitic power mode (VDD and GND connected) - see notes below.
  • Static (stack-based) or dynamic (malloc-based) memory model.
  • No globals - support any number of DS18B20 devices on any number of 1-Wire buses simultaneously.
  • 1-Wire device detection and validation, including search for multiple devices on a single bus.
  • Addressing optimisation for a single (solo) device on a bus.
  • CRC checks on temperature data.
  • Programmable temperature measurement resolution (9, 10, 11 or 12-bit resolution).
  • Temperature conversion and retrieval.
  • Separation of conversion and temperature retrieval to allow for simultaneous conversion across multiple devices.

Parasitic Power Mode

Consult the datasheet for more detailed information about Parasitic Power mode.

Parasitic power operation can be detected by ds18b20_check_for_parasite_power() followed by a call to owb_use_parasitic_power(), or simply set explicitly by a call to the latter.

This library has been tested on the ESP32 with two parasitic-power configurations, with two DS18B20 devices at 3.3V:

  1. Disconnect power to each device's VDD pin, and connect that pin to GND for each device. Power is supplied to each device through the OWB data line.
  2. Connect the OWB data line to VCC via a P-channel MOSFET (e.g. BS250) and current-limiting resistor (e.g. 270 Ohm). Ensure your code calls owb_use_strong_pullup_gpio() with the GPIO connected to the MOSFET Gate. The GPIO will go high during temperature conversion, turning on the MOSFET and providing power from VCC to each device through the OWB data line.

If you set up configuration 1 and do not see CRC errors, but you get incorrect temperature readings around 80 - 85 degrees C, then it is likely that your DS18B20 devices are running out of power during the temperature conversion. In this case, consider reducing the value of the pull-up resistor. For example, I have had success obtaining correct conversions from two parasitic DS18B20 devices by replacing the 4k7 Ohm pull-up resistor with a 1 kOhm resistor.

Alternatively, consider using configuration 2.

Note that use of parasitic power mode disables the ability for devices on the bus to signal that an operation has completed. This means that DS18B20 devices in parasitic power mode are not able to communicate when they have completed a temperature conversion. In this mode, a delay for a pre-calculated duration occurs, and then the conversion result is read from the device(s). If your ESP32 is not running on the correct clock rate, this duration may be too short!

Documentation

Automatically generated API documentation (doxygen) is available here.

Source Code

The source is available from GitHub.

License

The code in this project is licensed under the MIT license - see LICENSE for details.

Links

Acknowledgements

Parts of this code are based on references provided to the public domain by Maxim Integrated.

"1-Wire" is a registered trademark of Maxim Integrated.

Roadmap

The following features are anticipated but not yet implemented:

  • Concurrency support (multiple tasks accessing devices on the same bus).
  • Alarm support.
  • EEPROM support.
  • Parasitic power support.

esp32-ds18b20's People

Contributors

abraha2d avatar chmorgan avatar dantliff-sqc avatar davidantliff avatar lukecyca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

esp32-ds18b20's Issues

Trouble initializing and communicating after other code changes

Hi.

First off, great library. I had no trouble getting my external ds18b20 module working.
I'm using the ds18b20 in external supply mode so I'm providing a dedicated 3.3v supply to the device. My data line has a 4.7k pullup per the datasheet recommendation.

Before some recent code changes to totally unrelated code I was seeing only very rare crc errors. After some recent code changes to other tasks the device isn't detected at power up even after three retries.

As the change was outside of the temperature reading task that I'm using to call the ds18b20 read function I suspect a timing change is causing the issue here but I'm not seeing anything particularly suspicious in my traces. Any thoughts where to look? I'm wondering if there is other timing sensitive code in your library that may need to be protected from interruption from outside tasks, or maybe if its related to a lack of full gpio pin configuration? I'm not doing any gpio configuration in my code and it looks like the esp32-owb only does direction and level configuration and doesn't touch the optional pullup/pulldowns that are on most gpio pins.

RMT does not set output level high during conversion

Hi!

I'm using one parasistic power sensor, without strong pull up, with a pull-up resistor of 4.7k to 3.3.

In GPIO mode it works fine and I see during the conversion a voltage of about 3.2V.

In RMT mode the voltage does down to 2V, so it means only the pull-up resistor is giving current, and not the I/O GPIO.

I didn't debug yet, I guess you might know why RMT is not staying High during conversion.

Also I'm using IDF 5.1-rc1 and I get this warning:

esp-idf/components/driver/deprecated/driver/rmt.h:18:2: warning: #warning "The legacy RMT driver is deprecated, please use driver/rmt_tx.h and/or driver/rmt_rx.h" [-Wcpp]

MAX31850 adaptation

Could we include an adaptation to read MAX31850 devices too?
I believe the only difference is that data is 14-bits resolutions. But in the code there are so many checks to ensure its 9-12.
What would be proper places to change in order to adapt?
Thank you

The library does not work correctly, no valid temperature readings.

So, with same wiring, with external power (no parasitic mode) the same sensor works on Arduino but does not work on ESP32 with your library.
On Arduino i'm using DallasTemperature library and it works solid, reliably every time. With esp32 board - no way, i cant get a reading.

The problem is i have no idea what goes wrong. The wiring is correct because onewire detects the sensor and initializes it, but reading the temperature doesnt work. The sensor always returns 85 degrees celcius (which is the 'default' value returned by dallas in case of setup problems).
My code for initialization and reading of sensors:
https://github.com/lafar6502/esp_playground/blob/master/main/temp_sensors.c

Another thing - your example doesn't work either. It doesn't even detect the sensor.
No idea why, basically my code is almost exactly the same as in your example, but i suspect some differences in build/compilation/linking? Tried modifying your example in various ways but no success, sensor is not found at all. Sorry i cant put more information in because there's no more information available to me - i have no idea how to diagnose the problem and i cant find any issue with my side of things - wiring is verified, checked with Arduino, code is basically borrowed from your example. And example is not working out of the box. My board is esp32-wrover

Temperature reading is too high

Hello, I have issue with all of my DS12B20 sensors: they all are about 5 degrees too high: I get 28-30 as my room temperature. I am sure that all wiring is done correct, I have tested it with sensors from 2 different sources. TO-92 is soldered directly to male header on PCB carefully at low temperature using tweezers as a heatsink to prevent it from overheating.
Using sensor in solo mode.

Debug information:
ds18b20: temp_LSB 0xbf, temp_MSB 0x01, temp 27.937500

Thank you for your help

I find mixed return types DS18B20_ERROR and bool error-prone

Hi @DavidAntliff, I have a suggestion:

I find error-prone using two different return types, bool and DS18B20_ERROR, specially since their values mean the opposite of each other. Furthermore, the compiler doesn't even throw a warning if you check one against each other.

As an example, these 2 functions are normally used together but their return types are inconsistent:

bool ds18b20_convert(const DS18B20_Info * ds18b20_info);
DS18B20_ERROR ds18b20_read_temp(const DS18B20_Info * ds18b20_info, float * value);

I believe all ds18b20 functions should use the DS18B20_ERROR return codes for code legibility (which I admit I am obsessed with). However, the change would potentially break existing code checking for true or false, since DS18B20_OK == false. If anything, I would change the value of DS18B20_OK to be 1 so it also equals true. That way the only code that would break is if it checks the return code just relying on it being != 0 or != false in case of error.

If this is something you are willing to consider, I don't mind making the changes and doing a PR. What do you think?

Functionality-wise it works great. Thank you for sharing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.