Differenze tra le versioni di "Arduino, ESP and 1wire thermometers"

Da raspibo.
Jump to navigation Jump to search
 
(8 versioni intermedie di uno stesso utente non sono mostrate)
Riga 8: Riga 8:
 
Using an [https://www.adafruit.com/product/954 Adafruit like] cable:
 
Using an [https://www.adafruit.com/product/954 Adafruit like] cable:
  
Black -> GROUND
+
* Black -> GROUND
While -> TXD on ESP
+
* While -> TXD on ESP
Green -> RXD 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.
 
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.
Riga 16: Riga 16:
 
The connection to the DS18B10 is simple:
 
The connection to the DS18B10 is simple:
  
[[File: TO-92_Front_with_Pin_Numbers.png]]
+
[[File: TO-92_Front_with_Pin_Numbers.png|200px]]
  
GND -> GND
+
* 1 is GND -> GND
 +
* 2 is DATA -> GP02 on ESP
 +
* 3 is 3v3 -> +3V3
 +
 
 +
The circuit also needs a 4.7K resistor between DATA e 3v3.
 +
 
 +
=== Software ===
 +
 
 +
Here is the source code.
 +
<source lang=C>
 +
#include <DallasTemperature.h>
 +
 
 +
#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);
 +
}
 +
</source>
 +
 
 +
=== Testing ===
 +
 
 +
Load the program on you ESP. Remember that GP00 must be connected to ground at power-up to set the ESP in "flashing mode".
 +
 
 +
Open a terminal (e.g. using screen)
 +
<pre>
 +
screen /dev/ttyUSB0 115200
 +
</pre>
 +
 
 +
... and you'll get the temperature (one reading per second).
 +
 
 +
Unplug GP00 otherwise at the next power cycle your ESP will be in "flashing mode" again.
 +
If GP00 is unconnected, the program is restarted at power up.
 +
 
 +
This is the output (one line per second):
 +
<pre>
 +
Temperature: 31.94
 +
Temperature: 31.94
 +
Temperature: 32.00
 +
Temperature: 32.00
 +
Temperature: 32.00
 +
Temperature: 32.00
 +
Temperature: 32.00
 +
Temperature: 32.06
 +
Temperature: 32.25
 +
Temperature: 32.44
 +
Temperature: 32.56
 +
Temperature: 32.69
 +
Temperature: 32.63
 +
Temperature: 32.50
 +
Temperature: 32.44
 +
</pre>
 +
 
 +
(I touched the thermometer, so the temperature raised).

Versione attuale delle 11:08, 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:

TO-92 Front with Pin Numbers.png

  • 1 is GND -> GND
  • 2 is DATA -> GP02 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>

#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 GP00 must be connected to ground at power-up to set the ESP in "flashing mode".

Open a terminal (e.g. using screen)

screen /dev/ttyUSB0 115200

... and you'll get the temperature (one reading per second).

Unplug GP00 otherwise at the next power cycle your ESP will be in "flashing mode" again. If GP00 is unconnected, the program is restarted at power up.

This is the output (one line per second):

Temperature: 31.94
Temperature: 31.94
Temperature: 32.00
Temperature: 32.00
Temperature: 32.00
Temperature: 32.00
Temperature: 32.00
Temperature: 32.06
Temperature: 32.25
Temperature: 32.44
Temperature: 32.56
Temperature: 32.69
Temperature: 32.63
Temperature: 32.50
Temperature: 32.44

(I touched the thermometer, so the temperature raised).