1.    #include <OneWire.h>
2.    #include <DallasTemperature.h>
3.     
4.    // Anschluss Datenleitung am ESP8266
5.    #define ONE_WIRE_BUS D2
6.     
7.    // ONE-Wire Verbindung
8.    OneWire oneWire(ONE_WIRE_BUS);
9.     
10.    DallasTemperature sensors(&oneWire);
11.     
12.    DeviceAddress Thermometer;
13.     
14.    int deviceCount = 0;
15.     
16.    void setup(void)
17.    {
18.      // Start serieller Monitor
19.      Serial.begin(115200);
20.     
21.      sensors.begin();
22.     
23.      Serial.println("Locating devices...");
24.      Serial.print("Found ");
25.      deviceCount = sensors.getDeviceCount();
26.      Serial.print(deviceCount, DEC);
27.      Serial.println(" devices.");
28.      Serial.println("");
29.     
30.      Serial.println("Printing addresses...");
31.      for (int i = 0;  i < deviceCount;  i++)
32.      {
33.        Serial.print("Sensor ");
34.        Serial.print(i+1);
35.        Serial.print(" : ");
36.        sensors.getAddress(Thermometer, i);
37.        printAddress(Thermometer);
38.      }
39.    }
40.     
41.    void loop(void)
42.    { }
43.     
44.    // Sensoradressen im Seriellen Monitor abbilden
45.    void printAddress(DeviceAddress deviceAddress)
46.    {
47.      for (uint8_t i = 0; i < 8; i++)
48.      {
49.        Serial.print("0x");
50.        if (deviceAddress[i] < 0x10) Serial.print("0");
51.        Serial.print(deviceAddress[i], HEX);
52.        if (i < 7) Serial.print(", ");
53.      }
54.      Serial.println("");
55.    }


Back to Top