Update: 2020-05-31

Download Sketch

Der Sketch um die Adressen der Ds18b20 auszulesen.

Ds18b20_Scanner.ino

// ****************************************************************
// Sketch Esp8266 DS18b20 Adressen auslesen
// created: Jens Fleischer, 2018-08-23
// last mod: Jens Fleischer, 2018-08-24
// 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.
*******************************************************************/
// Zuerst den Pin einstellen an dem eure Thermometer angeschlossen sind
// Die Auflösung kann geändert werden.
/**************************************************************************************/

#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;     // Pin einstellen
const uint8_t PRECISION = 12;        // Auflösung einstellen 9, 10, 11, 12 --> 0.5°C, 0.25°C, 0.125°C, 0.0625°C --> 93.75 ms, 187.5 ms, 375 ms, 750 ms

OneWire oneWire(ONE_WIRE_PIN);
DallasTemperature DS18B20(&oneWire);
DeviceAddress tempDeviceAddress;     // Variable, um eine gefundene Geräteadresse zu speichern

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

  Serial.printf("%d Thermometer am ONE_WIRE_PIN gefunden.\n\n", DS18B20.getDeviceCount());

  for (uint8_t i = 0; i < DS18B20.getDeviceCount(); i++) {
    DS18B20.getAddress(tempDeviceAddress, i);
    DS18B20.setResolution(tempDeviceAddress, PRECISION);
    Serial.printf("Gerät %d {", i);
    for (uint8_t i = 0; i < 7; i++) {
      Serial.printf("0x%02x, ", tempDeviceAddress[i]);
    }
    Serial.printf("0x%02x}\n", tempDeviceAddress[7]);
  }
  DS18B20.requestTemperatures();
  Serial.printf("\nDie Auflösung ist auf %d eingestellt.\n", DS18B20.getResolution(tempDeviceAddress));
}

void loop() {
  static uint32_t letzteMillis = 0;
  uint32_t aktuelleMillis = millis();
  if (aktuelleMillis - letzteMillis >= 2e3) {
    letzteMillis = aktuelleMillis;
    Serial.println();
    for (uint8_t i = 0; i < DS18B20.getDeviceCount(); i++) {
      DS18B20.getAddress(tempDeviceAddress, i);
      Serial.printf("%.2f°C am Gerät %d\t", DS18B20.getTempC(tempDeviceAddress), i);
    }
    DS18B20.requestTemperatures();
  }
}
Kommentar eintragen

*