I’ve been searching this community high and low for nearly two weeks trying to find a working sketch to get the ESP 01 to display a temperature value from the ds18d20. From some of the posts it seems that many of you have managed, yet I can’t find a definitive explanation anywhere. I feel I’ve aged about six years just trying to get this to work! Could someone please either:
a) point me to the definitive sketch or
b) tell me how it’s done?
PS I have the DHT11 working fine on virtual pins - I’m just not skilled enough (old fart with no programming skills) to translate the code over to the ds18d20.
My significant other wants her six years back, so all help would be greatly appreciated.
Thanks, Adam. So far I have a working sketch for the DHT11 wired to an ESP8266 01, but I clearly need something different for the ds18d20.
All I’m looking for is a sketch that will allow me to use an ESP 01 to monitor temperature through Cayenne using a ds18d20. The closest I’ve found so far is this:
Hi
As i can see you refer to my post
In my project I am using analog pin for
Mq sensor, I use digital pin for ds18b20 and on node mcu it works fine on digital pin
Think it should work on digital pin of esp001
Thanks, Marcin. I’ve been playing with it all morning, and although my Cayenne recognizes the ds18d20, I’m not getting a reading. I’m not a programmer, so can’t figure out where I’m going wrong.
I’m okay with the wiring. I’ve done it many times before with the ds18d20 and the RasPi and/or ESP using Blynk. I have my resistor in place between +5 and signal.
Right now I’m trying to get it to work using the “Sparkfun Thing” (an ESP development board like the NodeMCU). Once I get it working, I’ll move over to the ESP-01.
I’m almost sure the problem’s in my sketch. My Cayenne is identifying the board, but no values seem to be coming through on serial. Could it be that my Cayenne widget is not asking my board for data?
I’ve tried it with and without pinMode and still don’t get any values.
Here’s my sketch: (for some reason anything with <> is not showing up in the preview, but I assure you I have OneWire.h, DallasTemperature.h and ESP8266WiFi.h, etc. included)
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"
#include <ESP8266WiFi.h>
// If you're not using the Ethernet W5100 shield, change this to match your connection type. See Communications examples.
//#include <CayenneEthernet.h>
// Virtual Pin of the DS18B20 widget.
#define VIRTUAL_PIN V1
// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
const int tmpPin = 2;
OneWire oneWire(tmpPin);
DallasTemperature sensors(&oneWire);
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "myToken";
// Your network name and password.
char ssid[] = "myWifi";
char password[] = "myPassword";
void setup()
{
//pinMode(tmpPin, INPUT);
Serial.begin(9600);
Cayenne.begin(token, ssid, password);
sensors.begin();
}
void loop()
{
Cayenne.run();
}
// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(VIRTUAL_PIN)
{
// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
Cayenne.celsiusWrite(VIRTUAL_PIN, sensors.getTempCByIndex(0));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}
The ESP works on 3.3v logic so you may have fried your pin if you used 5v.
You can also try printing the value in your out function to see if you’re getting anything there:
CAYENNE_OUT(VIRTUAL_PIN)
{
// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
Cayenne.celsiusWrite(VIRTUAL_PIN, sensors.getTempCByIndex(0));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
print sensors.getTempCByIndex(0);
}
I’ve been beating myself up with this as well. I can’t seem to ever get any reading at all from Cayenne.celsiusWrite() or Cayenne.fahrenheitWrite() in to the dashboard. It just comes back with a dash (-) even if i’m passing a float (i.e. Cayenne.celsiusWrite(V1, 22.4) Cayenne.virtualWrite() does produce the correct value from the temp sensor, or a float value.
Is there an issue with celsiusWrite() and fahrenheitWrite() with the esp8266 library?
So it does work with Cayenne.virtualWrite() but not Cayenne.celsiusWrite() or Cayenne.fahrenheitWrite()? If so that’s interesting…I usually always use virtualWrite so I wouldn’t have picked up on that.
That is exactly the behavior i’m experiencing, neither of the functions, Cayenne.celsiusWrite() or Cayenne.fahrenheitWrite(), are not passing values to the dashboard. I’m still unsure if it’s my code, or an issue with the ESP8266 library. I have been doing lots of digging through the community, and have yet to find the solution. Could you try either one of those methods and let me know how it works for you?
I finally got this working with the kind help of usmcwarmachine whose sketch can be found at this link. Note that the working sketch does not use either Cayenne.celsiusWrite or Cayenne.fahrenheitWrite.
Just as a follow up: I did tinker around with cleaning up the code I used, and did also try both the .celsius and .fahrenheit with no luck. Went back to a cleaned up version of the basic onewire and dallas code. Both the sensors.getTempFByIndex and sensors.getTempCByIndex work much better for me in my setup.