Coder Social home page Coder Social logo

ds18b20's Introduction

I recommend using this library instead of my own: https://github.com/DavidAntliff/esp32-ds18b20, it does everything this library does, plus more!


Not so simple library for multiple DS18B20 on ESP32

Resources

DS18B20 datasheet

https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf

1-Wire communication through software

https://www.maximintegrated.com/en/app-notes/index.mvp/id/126

1-Wire search algorithm

https://www.maximintegrated.com/en/app-notes/index.mvp/id/187

CPP implementation

https://github.com/PaulStoffregen/OneWire https://github.com/milesburton/Arduino-Temperature-Control-Library

Setup

From the root directory of your ESP-IDF project

git clone [email protected]:brettanomyces/ds18b20.git
echo "COMPONENT_ADD_INCLUDEDIRS := ../components/ds18b20" > main/components.mk

Usage

// main/main.c
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "ds18b20.h"

uint8_t pin = 27;
uint8_t addr1[] = {0x28, 0xff, 0xa5, 0xa0, 0x68, 0x14, 0x04, 0x36 };
uint8_t addr2[] = {0x28, 0xff, 0xb7, 0xa0, 0x68, 0x14, 0x04, 0xc9 };

void mainTask(void * pvParameters){
  ow_init(pin);

  uint8_t count, result, i;

  while (1) {
    // display addr of all connected devices
    count = 0;
    result = ow_first();
    while (result)
    {
      printf("addr%d: ", ++count);

      // print addr bytes in hex
      for (i = 0; i < 8; i++) {
        printf("0x%02x ", ROM_NO[i]);
      }
      printf("\n");

      result = ow_next();
    }

    // get temp by addr
    printf("temp1: %0.3f\n", ds_get_temp(addr1));
    printf("temp2: %0.3f\n", ds_get_temp(addr2));

    vTaskDelay(1000 / portTICK_PERIOD_MS);
  }
}

void app_main()
{
  xTaskCreatePinnedToCore(&mainTask, "mainTask", 2048, NULL, 5, NULL, 0);
}

ds18b20's People

Contributors

feelfreelinux avatar brettanomyces avatar

Stargazers

Kamil Karkoszka avatar  avatar Jimmy Pedersen avatar Pedro Larroy avatar Åke Hedman avatar Alexander Sparkowsky avatar

Watchers

Åke Hedman avatar

Forkers

ronitti

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.