Created
May 26, 2018 07:31
-
-
Save jtuttas/30acb39913855e553450ab52eb903e22 to your computer and use it in GitHub Desktop.
Read Temperature of DS18b20 with ESP32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Arduino.h" | |
#include <DallasTemperature.h> | |
// Data wire is plugged into pin 21 on the ESP32 | |
#define ONE_WIRE_BUS 21 | |
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |
OneWire oneWire(ONE_WIRE_BUS); | |
// Pass our oneWire reference to Dallas Temperature. | |
DallasTemperature DS18B20(&oneWire); | |
char temperatureCString[6]; | |
float tempC = 0.0; | |
void setup() | |
{ | |
Serial.begin(115200); | |
delay(500); | |
// initialize LED digital pin as an output. | |
Serial.write("\r\nStarte OneWireBus"); | |
dtostrf(tempC, 2, 2, temperatureCString); | |
DS18B20.begin(); | |
int n = 0; | |
do | |
{ | |
DS18B20.requestTemperatures(); | |
tempC = DS18B20.getTempCByIndex(0); | |
delay(500); | |
Serial.print("."); | |
n++; | |
} while (tempC == -127 && n < 20); | |
dtostrf(tempC, 2, 2, temperatureCString); | |
Serial.println("\r\nTemperatur ist " + String(temperatureCString)); | |
} | |
void loop() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment