Update: 2020-05-30

Download Sketch

Der Sketch um den Ds18b20 über die Adressen anzusprechen.

Ds18b20_Array.ino

// ****************************************************************
// Sketch Esp8266 DS18b20 Adressen Array
// created: Jens Fleischer, 2018-08-25
// last mod: Jens Fleischer, 2020-05-30
// For more information visit: https://fipsok.de
// ****************************************************************
// Hardware: Esp8266, DS18B20, 4k7 Ohm Widerstand
// D6 = GPIO12  Anschluss DS18B20
// 4k7 Ohm Widerstand von VCC auf GPIO12
// Getestet auf: Nodemcu, Wemos D1 Mini Pro
/******************************************************************
  Copyright (c) 2018 Jens Fleischer. All rights reserved.

  This file is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  This file is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
*******************************************************************/
// Pin einstellen an dem die Ds18b20 Sensoren angeschlossen sind.
// Alle Adressen deiner Sensoren in das Array "DeviceAddress sensor[]" eintragen.
// Der Sketch prüft ob die Anzahl der Adressen mit der Anzahl der Sensoren übereinstimmt.
/**************************************************************************************/

#include <DallasTemperature.h>       // Version 3.8.0  https://github.com/milesburton/Arduino-Temperature-Control-Library
#include <OneWire.h>                 // Version 2.3.4  https://github.com/PaulStoffregen/OneWire

const uint8_t ONE_WIRE_PIN = D6;     // Sensor Pin einstellen
// trage alle Adressen deiner Ds18b20 Sensoren, die am Pin angeschlossen sind ein.
DeviceAddress tempDevice[] = { {0x28, 0xff, 0x33, 0x10, 0x81, 0x16, 0x04, 0x54} , {0x28, 0xff, 0x07, 0x6f, 0x30, 0x17, 0x04, 0x2e} , {0x28, 0xFF, 0x03, 0x18, 0x81, 0x16, 0x04, 0xCC}};

OneWire oneWire(ONE_WIRE_PIN);
DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(115200);
  delay(100);
  Serial.printf("\nSketchname: %s\nBuild: %s\n", (__FILE__), (__TIMESTAMP__));
  sensors.begin();
  sensors.setWaitForConversion(false);
  sensors.requestTemperatures();
}

void loop() {
  static uint32_t letzteMillis = 0;
  auto aktuelleMillis = millis();
  if (aktuelleMillis - letzteMillis >= 2e3) {
    letzteMillis = aktuelleMillis;
    const byte COUNT = sizeof(tempDevice) / 8 ;
    if (COUNT == sensors.getDS18Count()) {
      Serial.println();
      for (int i = 0; i < COUNT; i++ ) {
        Serial.printf("%d. %.2f°C\t", i + 1, static_cast<float>(sensors.getTemp(tempDevice[i]) / 128));
      }
    }
    else {
      Serial.println("Die Anzahl der Sensoren ist ungleich der Anzahl der Adressen.");
    }
    sensors.requestTemperatures();
  }
}

Kommentar eintragen

*