ESP8266 wont run TMP36 on Cayenne -Newbie Question-


#1

Hi there,

I have had some issues getting a Wemos D1 run a simple TMP36 sensor on Cayenne. Actually, I had a lot of issues just getting the Wemos board to talk to Cayenne but thats another issue(I seems to have many:). Long story short, after looking at other posting I am connected but cannot get a real value. Cayenne shows my living room at -17.78C and its not that chilly, honest.

Here is the sketch i am using on latest Arduino IDE. any suggestions would be helpful. Sensor works fine otherwise.

Thanks,

Dave

define CAYENNE_DEBUG         // Uncomment to show debug messages
define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
include "CayenneTemperature.h" 
include "CayenneDefines.h"
include "BlynkSimpleEsp8266.h" // no idea why this has to be here, will not compile if not included
include "CayenneWiFiClient.h"


char token[] = "edited out for post";
char ssid[] = "edited out for post";
char password[] = "edited out for post";

define VIRTUAL_PIN V1

const int tmpPin = 0; 
const float voltage = 3.3; 

TMP36 tmpSensor(tmpPin, voltage);

void setup()
{
  
  Serial.begin(9600);
  Cayenne.begin(token, ssid, password);
}

void loop()
{
  Cayenne.run();
}


// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(VIRTUAL_PIN)
{

 // This command writes the temperature in Celsius to the Virtual Pin.
 Cayenne.celsiusWrite(VIRTUAL_PIN, tmpSensor.getCelsius());

Serial.print(tmpSensor.getCelsius(),1); // Pasted from http://community.mydevices.com/t/help-temperature-reading-lm35/1360/6

Serial.println(" degrees C   "); //added at suggestion of user (adam)
float temp = (3.3 * analogRead(A0) * 100.0) / 1023; //added at suggestion of user (adam)
  // To send the temperature in Fahrenheit or Kelvin use the corresponding code below.
  //Cayenne.fahrenheitWrite(VIRTUAL_PIN, tmpSensor.getFahrenheit());
  //Cayenne.kelvinWrite(VIRTUAL_PIN, tmpSensor.getKelvin());
}

#2

What are you seeing in the serial output?

Also, try this

CAYENNE_OUT(VIRTUAL_PIN)
{

 // This command writes the temperature in Celsius to the Virtual Pin.
 //Cayenne.celsiusWrite(VIRTUAL_PIN, tmpSensor.getCelsius());

Serial.print(tmpSensor.getCelsius(),1); // Pasted from http://community.mydevices.com/t/help-temperature-reading-lm35/1360/6

Serial.println(" degrees C   "); //added at suggestion of user (adam)
float temp = (3.3 * analogRead(A0) * 100.0) / 1023; //added at suggestion of user (adam)
Cayenne.virtualWrite(VIRTUAL_PIN, temp);
  // To send the temperature in Fahrenheit or Kelvin use the corresponding code below.
  //Cayenne.fahrenheitWrite(VIRTUAL_PIN, tmpSensor.getFahrenheit());
  //Cayenne.kelvinWrite(VIRTUAL_PIN, tmpSensor.getKelvin());
}

#3

Hi Adam,

Thanks for your response. At the serial I see this:

-Dave


#4

Do you have the virtual pin set up on the dashboard? From that output it looks like it’s not trying to read it.


#5

I created another widget just to make sure it was using virtual pin V0. Sketch looks Like this so I dont have both V1 and V0 in the sketch anymore.

define CAYENNE_DEBUG // Uncomment to show debug messages
define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
//include "CayenneTemperature.h"
include "CayenneDefines.h"
include “BlynkSimpleEsp8266.h” // no idea why this has to be here, will not compile if not included
include “CayenneWiFiClient.h”

char token[] = “”;
char ssid[] = “”;
char password[] = “”;

define VIRTUAL_PIN V0

//const int tmpPin = 0;
//const float voltage = 3.3;
int temp = 0;

//TMP36 tmpSensor(tmpPin, voltage);

void setup()
{

Serial.begin(9600);
Cayenne.begin(token, ssid, password);
}

void loop()
{
Cayenne.run();
}

// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(V0)
{

float temp = (3.3 * analogRead(A0) * 100.0) / 1023;
Serial.print(" degrees C ");
Serial.print(temp);
Cayenne.virtualWrite(V0, temp);
}


#6

Do you see any lines in your serial output that end with " degrees C "?


#7

no i dont.


#8

No matter what edits I make, the serial messages look similar if not the same to the screen capture I provided.


#9

Can you post a screen shot of your virtual pin settings?


#10

I think i have to set up a new widget to do this.


#11

You can click the settings wheel in the top right of the widget


#12

Added a new temp widget and something good happened

And more importantly I now see this (with serial port showing meaningful data albiet an bit warmer than actual):


#13

Cool, that does indeed look at lot better. So is 76.13 not accurate?


#14

no this is a chilly room, about 18C if I am lucky.

For giggles I took a better look at the other widget shown here:

Notice that no Icon is selected even though I had to choose one to set up the widget to start with.
When I toggle the Choose Icon I get this:


#15

To correct the temp I will measure the actual voltage I am getting and change the 3.3V I have in the sketch to the correct value. I am guessing thats whats going on here.


#16

Adam;

Thank you for your incredible patience and help. I was pretty much swimming in circles without your help. Thanks again and I really appreciate that!!!

Dave