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());
}
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());
}
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”
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.