DavidAntliff / esp32-ds18b20-example

ESP32-compatible example for Maxim Integrated DS18B20 Programmable Resolution 1-Wire Digital Thermometer.
MIT License
109 stars 34 forks source link

Step by step? #1

Closed DanteNahuel closed 6 years ago

DanteNahuel commented 6 years ago

Hi there. Incredible library. Is there any documentation with a step by step or youtube video using this library? Noob asking.

DavidAntliff commented 6 years ago

Thanks. There isn't really a step-by-step unfortunately (and no video) however app_main.c does contain all the steps you need, but I concede that it's not obvious. I can give you some pointers if you tell me how many sensors you plan to use (i.e. one vs more than one).

DanteNahuel commented 6 years ago

Thank you very much for the answer. I'm trying to understand app_main.c but, since it has all examples at the same time i'm a bit confused with it. i'm planing to use 4 sensors at the same time.

DavidAntliff commented 6 years ago

Ok, quickly (I can answer specific questions if you're not sure about any of these steps):

  1. first you need to set up the One Wire Bus (owb). See lines 59-61 (owb_rmt_initialize) and then decide if you want to enable CRC mode (I recommend it, then you can see if you get any bus errors).
  2. next you need to search the OWB for devices. This is done by first calling owb_search_first to find the first device, and then calling owb_search_next until found is false. For each device, you can extract the ROM code (ID) as a string with owb_string_from_rom_code and store it. Remember how many devices you saw.
  3. now you need to create a DS18B20_Info instance for each device. Loop through the number of devices, and for each one call ds18b20_malloc and then ds18b20_init. You can also turn on CRC for the device itself (ds18b20_use_crc), and set the resolution (ds18b20_set_resolution).
  4. Now you can start periodically polling the devices for readings. With multiple devices, you can tell them to all start measuring ("conversion") simultaneously (rather than one at a time) with ds18b20_convert_all. Then you have to wait a bit for the conversion to complete (ds18b20_wait_for_conversion)
  5. Once the conversion is complete, you can then loop through all your devices and read the measurements with ds18b20_read_temp.
  6. optional: if you want to clean up (not really necessary for an infinite loop), make sure you call ds18b20_free for each DS18B20_Info instance that you malloc'd, and call owb_free.

Also look here: https://davidantliff.github.io/esp32-ds18b20/index.html

At the risk of being more confusing, you can see an app where I used this library here: https://github.com/DavidAntliff/esp32-poolmon/blob/master/main/sensor_temp.c

See how you go with that, and if you're still stuck let me know and I'll help if I can.

DavidAntliff commented 6 years ago

See also: https://davidantliff.github.io/esp32-ds18b20/ds18b20_8h.html And: https://davidantliff.github.io/esp32-owb/owb_8h.html

DanteNahuel commented 6 years ago

Thank you a lot! I'll try to do as you explained! If you don't mind, can we leave this open until it works?

DavidAntliff commented 6 years ago

@DanteNahuel did you have any success? Can I close this issue?

DanteNahuel commented 6 years ago

@DavidAntliff Sorry, I had a couple of personal issues and I forgot to close this. Thank you for your help.