ESP8266/Temp: Difference between revisions
Jump to navigation
Jump to search
(#990000 go go what teh temp?) |
m (#990000 yankee doodle hack to F from float) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
Temperature Sensing with Dallas DS18B20 | Temperature Sensing with Dallas DS18B20 | ||
<pre> | |||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |||
// Pass the GPIO pin number sensor(s) is connected to | |||
OneWire oneWire(13); | |||
// Pass our oneWire reference to Dallas Temperature. | |||
DallasTemperature sensors(&oneWire); | |||
// Put this in setup() | |||
sensors.begin(); | |||
// Put this where you want to read temp | |||
sensors.requestTemperatures(); | |||
sensors.getTempCByIndex(0); | |||
</pre> | |||
Hack for Fahrenheit and float conversion | |||
<pre> | |||
sensors.requestTemperatures(); | |||
float tempFloat = sensors.getTempCByIndex(0) * 1.8 + 32; // convert to F | |||
int tempReading = int(tempFloat); | |||
int tempReadingTenth = int((tempFloat - tempReading) * 10); // Hack around %f | |||
// For use with sprintf() | |||
// sprintf(buff, 100, "Temperature: %d.%d", tempReadig, tempReadingTenth); | |||
</pre> | |||
== Dallas Library == | == Dallas Library == | ||
Latest revision as of 20:30, 23 November 2015
Temperature Sensing with Dallas DS18B20
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) // Pass the GPIO pin number sensor(s) is connected to OneWire oneWire(13); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // Put this in setup() sensors.begin(); // Put this where you want to read temp sensors.requestTemperatures(); sensors.getTempCByIndex(0);
Hack for Fahrenheit and float conversion
sensors.requestTemperatures(); float tempFloat = sensors.getTempCByIndex(0) * 1.8 + 32; // convert to F int tempReading = int(tempFloat); int tempReadingTenth = int((tempFloat - tempReading) * 10); // Hack around %f // For use with sprintf() // sprintf(buff, 100, "Temperature: %d.%d", tempReadig, tempReadingTenth);
Dallas Library[edit | edit source]
http://www.milesburton.com/?title=Dallas_Temperature_Control_Library
Library Download:
References[edit | edit source]
- Sensor Data Sheet
- Arduino Reference Project
- ESP8266 Reference Project