Differenze tra le versioni di "Arduino, ESP and 1wire thermometers"
m |
m (→Software) |
||
Riga 52: | Riga 52: | ||
} | } | ||
</source> | </source> | ||
+ | |||
+ | === Testing === | ||
+ | |||
+ | Load the program on you ESP. Remember that to set the ESP in "flashing mode" GPIO must be connected to ground at power-up. |
Versione delle 09:46, 27 giu 2016
This is a simple sketch to read the current temperature from a DS18B10/DS18B20 1 wire thermometer.
I have successfully tested this program on an ESP-12 (ESP8266) using the Arduino IDE.
hardware wiring
This project uses a "console cable" (but any USB to TTL converter is okay). Using an Adafruit like cable:
Black -> GROUND While -> TXD on ESP Green -> RXD on ESP
DO NOT CONNECT THE RED PIN TO YOUR ESP! The red pin is +5V while ESP need +3V3 so either you have a step-down circuit to convert 5V to 3.3V or you'll need another power source of the right voltage for yout ESP.
The connection to the DS18B10 is simple:
1 is GND -> GND 2 is DATA -> GPIO02 on ESP 3 is 3v3 -> +3V3
The circuit also needs a 4.7K resistor between DATA e 3v3.
Software
Here is the source code.
#include <DallasTemperature.h>
const int led=13;
#define ONE_WIRE_BUS 2 // DS18B20 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
void setup(void){
Serial.begin(115200);
pinMode(led, OUTPUT);
digitalWrite(led, 0);
}
void loop(void){
float temp;
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.println(temp);
delay(1000);
}
Testing
Load the program on you ESP. Remember that to set the ESP in "flashing mode" GPIO must be connected to ground at power-up.