Another esp-01 question, mainly around the use of GPIO-0 for the DS18B20 one wire data line.
I have the following code:
#include <OneWire.h>
#include <DallasTemperature.h>
// esp8266 GPIO Table
// http://www.seeedstudio.com/recipe/img/recipe/2015-05/55582b9962fb5.JPG
#define ONE_WIRE_BUS 0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
Serial.println("");
Serial.println("Setup..");
// Start up the library
sensors.begin();
}
// the loop function runs over and over again forever
void loop() {
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(sensors.getTempCByIndex(0));
delay(2000);
}
Noting that the http link in the code comments mentions GPIO-0 is IO index of 3, I also tried the following but still I only get -127.00 on the data line:
#define ONE_WIRE_BUS 3
I have the VCC and GND lines on the temp sensor to ground.
So next for the data line I have the following in the breadboard:
I have a 4.7k resistor from the 3.3v breadboard rail to "a" on the breadboard.
I have the DS18B20 plugged into "b" on same line next to the 4.7k resistor.
I have the ESP-01 GPIO-0 into "c" next to the DS18B20 which is plugged into "b".
The red wire is VCC for the temperature sensor.
The black wire is GND for the temperature sensor.
The yellow wire is the data line for the temperature sensor.
The yellow wire going downwards is the ESP-01 GPIO 0 line.
If I'm reading the data sheet right, I need to have VCC and GND to ground then have a pull-up resistor between 3.3v and the data line. So pretty much this:
i had the same problem with the temp reading -127, i had the sensor in the wrong way around. I found out the hard way....... touched it, it was red hot.